diff options
author | 2017-06-13 13:23:15 +0200 | |
---|---|---|
committer | 2017-06-13 17:13:24 +0200 | |
commit | 9c54e2a764f0ddd2d3787aade1c530c5f43bd26c (patch) | |
tree | c51928fefac492d1c97b2994dad18e6c7a7e5165 /src/test/py | |
parent | 1d62c67a2d6d6eccf415ad5647d860d08f4c5966 (diff) |
Windows, Bazel client: pass Unix root as JVM flag
The Bazel client will pass the
--host_jvm_args=-Dbazel.windows_unix_root=<path>
flag to the server (computed from $BAZEL_SH), and
the server will no longer shell out to cygpath to
compute this value.
Fixes https://github.com/bazelbuild/bazel/issues/2983
Change-Id: Iacc2e2eb70eacafdf7bbcad68d375ba9eadc6ee1
PiperOrigin-RevId: 158830675
Diffstat (limited to 'src/test/py')
-rw-r--r-- | src/test/py/bazel/BUILD | 23 | ||||
-rw-r--r-- | src/test/py/bazel/bazel_windows_test.py | 50 | ||||
-rw-r--r-- | src/test/py/bazel/empty_test.py | 27 | ||||
-rw-r--r-- | src/test/py/bazel/test_base.py | 18 |
4 files changed, 113 insertions, 5 deletions
diff --git a/src/test/py/bazel/BUILD b/src/test/py/bazel/BUILD index 428e97d629..32a5adda1e 100644 --- a/src/test/py/bazel/BUILD +++ b/src/test/py/bazel/BUILD @@ -32,3 +32,26 @@ py_test( srcs = ["bazel_clean_test.py"], deps = [":test_base"], ) + +py_test( + name = "bazel_windows_test", + size = "medium", + srcs = select({ + "//src:windows": ["bazel_windows_test.py"], + "//src:windows_msvc": ["bazel_windows_test.py"], + "//src:windows_msys": ["bazel_windows_test.py"], + "//conditions:default": ["empty_test.py"], + }), + main = select({ + "//src:windows": "bazel_windows_test.py", + "//src:windows_msvc": "bazel_windows_test.py", + "//src:windows_msys": "bazel_windows_test.py", + "//conditions:default": "empty_test.py", + }), + deps = select({ + "//src:windows": [":test_base"], + "//src:windows_msvc": [":test_base"], + "//src:windows_msys": [":test_base"], + "//conditions:default": [], + }), +) diff --git a/src/test/py/bazel/bazel_windows_test.py b/src/test/py/bazel/bazel_windows_test.py new file mode 100644 index 0000000000..27bc37366c --- /dev/null +++ b/src/test/py/bazel/bazel_windows_test.py @@ -0,0 +1,50 @@ +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from src.test.py.bazel import test_base + + +class BazelWindowsTest(test_base.TestBase): + + def testWindowsUnixRoot(self): + self.ScratchFile('WORKSPACE') + self.ScratchFile('foo/BUILD', ['cc_binary(name="x", srcs=["x.cc"])']) + self.ScratchFile('foo/x.cc', [ + '#include <stdio.h>', 'int main(int, char**) {' + ' printf("hello\\n");', ' return 0;', '}' + ]) + + exit_code, _, stderr = self.RunBazel( + ['--batch', 'build', '//foo:x', '--cpu=x64_windows_msys'], + env_remove={'BAZEL_SH'}) + self.assertEqual(exit_code, 2) + self.assertIn('\'BAZEL_SH\' environment variable is not set', + '\n'.join(stderr)) + + exit_code, _, stderr = self.RunBazel([ + '--batch', '--host_jvm_args=-Dbazel.windows_unix_root=', 'build', + '//foo:x', '--cpu=x64_windows_msys' + ]) + self.assertEqual(exit_code, 37) + self.assertIn('"bazel.windows_unix_root" JVM flag is not set', + '\n'.join(stderr)) + + exit_code, _, _ = self.RunBazel( + ['--batch', 'build', '//foo:x', '--cpu=x64_windows_msys']) + self.assertEqual(exit_code, 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/src/test/py/bazel/empty_test.py b/src/test/py/bazel/empty_test.py new file mode 100644 index 0000000000..fe6a40a8ea --- /dev/null +++ b/src/test/py/bazel/empty_test.py @@ -0,0 +1,27 @@ +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Empty test for platforms that don't need to run a particular test. + +import unittest + + +class EmptyTest(unittest.TestCase): + + def testNothing(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index 2a2b2e574e..7d0bba7385 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -117,7 +117,9 @@ class TestBase(unittest.TestCase): if not path: return abspath = self.Path(path) - if os.path.exists(abspath) and not os.path.isdir(abspath): + if os.path.exists(abspath): + if os.path.isdir(abspath): + return raise IOError('"%s" (%s) exists and is not a directory' % (path, abspath)) os.makedirs(abspath) @@ -145,11 +147,13 @@ class TestBase(unittest.TestCase): f.write(l) f.write('\n') - def RunBazel(self, args): + def RunBazel(self, args, env_remove=None): """Runs "bazel <args>", waits for it to exit. Args: args: [string]; flags to pass to bazel (e.g. ['--batch', 'build', '//x']) + env_remove: set(string); optional; environment variables to NOT pass to + Bazel Returns: (int, [string], [string]) tuple: exit code, stdout lines, stderr lines """ @@ -163,7 +167,7 @@ class TestBase(unittest.TestCase): stdout=stdout, stderr=stderr, cwd=self._tests_root, - env=self._BazelEnvMap()) + env=self._BazelEnvMap(env_remove)) exit_code = proc.wait() with open(self._stdout, 'r') as f: @@ -172,7 +176,7 @@ class TestBase(unittest.TestCase): stderr = [l.strip() for l in f.readlines()] return exit_code, stdout, stderr - def _BazelEnvMap(self): + def _BazelEnvMap(self, env_remove=None): """Returns the environment variable map to run Bazel.""" if TestBase.IsWindows(): result = [] @@ -190,12 +194,13 @@ class TestBase(unittest.TestCase): names.pop() os.path.walk('c:\\program files\\java\\', _Visit, result) + env = { 'SYSTEMROOT': TestBase.GetEnv('SYSTEMROOT'), # TODO(laszlocsomor): Let Bazel pass BAZEL_SH and JAVA_HOME to tests # and use those here instead of hardcoding paths. 'JAVA_HOME': 'c:\\program files\\java\\' + sorted(result)[-1], - 'BAZEL_SH': 'c:\\tools\\msys64\\usr\\bin\\bash.exe' + 'BAZEL_SH': 'c:\\tools\\msys64\\usr\\bin\\bash.exe', } else: env = {'HOME': os.path.join(self._temp, 'home')} @@ -206,6 +211,9 @@ class TestBase(unittest.TestCase): # that by checking for TEST_TMPDIR. env['TEST_TMPDIR'] = TestBase.GetEnv('TEST_TMPDIR') env['TMP'] = self._temp + if env_remove: + for e in env_remove: + del env[e] return env @staticmethod |