From 56366ee3a73e2c92b2fa36a9840478202b9618ca Mon Sep 17 00:00:00 2001 From: pcloudy Date: Thu, 7 Mar 2019 07:48:17 -0800 Subject: [PATCH] Set non-empty values for msvc_env_* when VC not installed Fixes https://github.com/bazelbuild/bazel/issues/7661 RELNOTES: None PiperOrigin-RevId: 237246257 --- src/test/py/bazel/bazel_windows_test.py | 75 +++++++++++++++++++++++++ tools/cpp/windows_cc_configure.bzl | 8 +-- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py index e813d9f881d127..32bc97c380f530 100644 --- a/src/test/py/bazel/bazel_windows_test.py +++ b/src/test/py/bazel/bazel_windows_test.py @@ -134,6 +134,81 @@ def testWindowsEnvironmentVariablesSetting(self): self.assertNotIn('foo=bar2', result_in_lower_case) self.assertIn('foo=bar3', result_in_lower_case) + def testAnalyzeCcRuleWithoutVCInstalled(self): + self.ScratchFile('WORKSPACE') + self.ScratchFile('BUILD', [ + 'cc_binary(', + ' name = "bin",', + ' srcs = ["main.cc"],', + ')', + ]) + self.ScratchFile('main.cc', [ + 'void main() {', + ' printf("Hello world");', + '}', + ]) + exit_code, _, stderr = self.RunBazel( + [ + 'build', + '--nobuild', + '//...', + ], + # Set BAZEL_VC to a non-existing path, + # Bazel should still work when analyzing cc rules . + env_add={'BAZEL_VC': 'C:/not/exists/VC'}, + ) + self.AssertExitCode(exit_code, 0, stderr) + + def testBuildNonCcRuleWithoutVCInstalled(self): + self.ScratchFile('WORKSPACE') + self.ScratchFile('BUILD', [ + 'genrule(', + ' name="gen",', + ' outs = ["hello"],', + ' cmd = "touch $@",', + ')', + '', + 'java_binary(', + ' name = "bin_java",', + ' srcs = ["Main.java"],', + ' main_class = "Main",', + ')', + '', + 'py_binary(', + ' name = "bin_py",', + ' srcs = ["bin_py.py"],', + ')', + '', + 'sh_binary(', + ' name = "bin_sh",', + ' srcs = ["main.sh"],', + ')', + ]) + self.ScratchFile('Main.java', [ + 'public class Main {', + ' public static void main(String[] args) {', + ' System.out.println("hello java");', + ' }', + '}', + ]) + self.ScratchFile('bin_py.py', [ + 'print("Hello world")', + ]) + self.ScratchFile('main.sh', [ + 'echo "Hello world"', + ]) + exit_code, _, stderr = self.RunBazel( + [ + 'build', + '//...', + ], + # Set BAZEL_VC to a non-existing path, + # Bazel should still work when building rules that doesn't + # require cc toolchain. + env_add={'BAZEL_VC': 'C:/not/exists/VC'}, + ) + self.AssertExitCode(exit_code, 0, stderr) + if __name__ == '__main__': unittest.main() diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl index 952d9feeb590ca..372bffba0158ff 100644 --- a/tools/cpp/windows_cc_configure.bzl +++ b/tools/cpp/windows_cc_configure.bzl @@ -361,10 +361,10 @@ def configure_windows_toolchain(repository_ctx): paths["@bazel_tools//tools/cpp:cc_toolchain_config.bzl.tpl"], { "%{toolchain_identifier}": "msys_x64", - "%{msvc_env_tmp}": "", - "%{msvc_env_path}": "", - "%{msvc_env_include}": "", - "%{msvc_env_lib}": "", + "%{msvc_env_tmp}": "msvc_not_found", + "%{msvc_env_path}": "msvc_not_found", + "%{msvc_env_include}": "msvc_not_found", + "%{msvc_env_lib}": "msvc_not_found", "%{msvc_cl_path}": "vc_installation_error.bat", "%{msvc_ml_path}": "vc_installation_error.bat", "%{msvc_link_path}": "vc_installation_error.bat",