aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2018-03-22 03:09:32 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-22 03:11:08 -0700
commita3dd7775d2dbf7e4368712626e11c15be7a23efd (patch)
treef597e77ed8a338ebefd2d80dc9ea36dc98e06997
parent7cca5d788da153acff59bba19617fc65e468201b (diff)
Windows: Expose setup_vc_env_vars function from windows_cc_configure.bzl
`setup_vc_env_vars` runs vcvarsall.bat to setup environment varibles for Visuall C++ build tools. It returns the values of PATH, LIB, INCLUDE and WINDOWSSDKDIR. Expose this function so that users can use load("@bazel_tools/tools/cpp:windows_cc_configure.bzl", "setup_vc_env_vars") to access this function. Fixed https://github.com/bazelbuild/bazel/issues/4542 RELNOTES[NEW]: Now you can access three functions in windows_cc_configure.bzl by: load("@bazel_tools/tools/cpp:windows_cc_configure.bzl", "<function_name>") 1. find_vc_path(repository_ctx): Detect the VC installation path on your machine, respect BAZEL_VC first, return None if VC not found. 2. setup_vc_env_vars(repository_ctx, vc_path): Get PATH, LIB, INCLUDE, WINDOWSSDKDIR env vars set by VCVARSALL.bat, return None if VCVARSALL.bat not found. 3. find_msvc_tool(repository_ctx, vc_path, tool): Find a certain VC build tool (eg. cl.exe, lib.exe, link.exe), return None if tool not found. Change-Id: Iec5770165aaa4766470bb3b4d818a2cf90678586 Closes #4892. Change-Id: Iec5770165aaa4766470bb3b4d818a2cf90678586 PiperOrigin-RevId: 190039950
-rw-r--r--tools/cpp/windows_cc_configure.bzl10
1 files changed, 6 insertions, 4 deletions
diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl
index 1a49b2ca14..f7f7df12c5 100644
--- a/tools/cpp/windows_cc_configure.bzl
+++ b/tools/cpp/windows_cc_configure.bzl
@@ -190,15 +190,17 @@ def _find_vcvarsall_bat_script(repository_ctx, vc_path):
return vcvarsall
-def _find_env_vars(repository_ctx, vc_path):
+def setup_vc_env_vars(repository_ctx, vc_path):
"""Get environment variables set by VCVARSALL.BAT. Doesn't %-escape the result!"""
vcvarsall = _find_vcvarsall_bat_script(repository_ctx, vc_path)
+ if not vcvarsall:
+ return None
repository_ctx.file("get_env.bat",
"@echo off\n" +
"call \"" + vcvarsall + "\" amd64 > NUL \n" +
- "echo PATH=%PATH%,INCLUDE=%INCLUDE%,LIB=%LIB% \n", True)
+ "echo PATH=%PATH%,INCLUDE=%INCLUDE%,LIB=%LIB%,WINDOWSSDKDIR=%WINDOWSSDKDIR% \n", True)
env = _add_system_root(repository_ctx,
- {"PATH": "", "INCLUDE": "", "LIB": ""})
+ {"PATH": "", "INCLUDE": "", "LIB": "", "WINDOWSSDKDIR": ""})
envs = execute(repository_ctx, ["./get_env.bat"], environment=env).split(",")
env_map = {}
for env in envs:
@@ -352,7 +354,7 @@ def configure_windows_toolchain(repository_ctx):
})
return
- env = _find_env_vars(repository_ctx, vc_path)
+ env = setup_vc_env_vars(repository_ctx, vc_path)
escaped_paths = escape_string(env["PATH"])
escaped_include_paths = escape_string(env["INCLUDE"])
escaped_lib_paths = escape_string(env["LIB"])