From a3dd7775d2dbf7e4368712626e11c15be7a23efd Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Thu, 22 Mar 2018 03:09:32 -0700 Subject: 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", "") 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 --- tools/cpp/windows_cc_configure.bzl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tools') 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"]) -- cgit v1.2.3