Skip to content

Commit

Permalink
Set non-empty values for msvc_env_* when VC not installed
Browse files Browse the repository at this point in the history
Fixes #7661

RELNOTES: None
PiperOrigin-RevId: 237246257
  • Loading branch information
meteorcloudy authored and copybara-github committed Mar 7, 2019
1 parent c25c054 commit 56366ee
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
75 changes: 75 additions & 0 deletions src/test/py/bazel/bazel_windows_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 4 additions & 4 deletions tools/cpp/windows_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 56366ee

Please sign in to comment.