diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 39c491f7c..f8a0a4eaa 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -528,11 +528,7 @@ def GetUnitTests(input_api, output_api, unit_tests, env=None): results = [] for unit_test in unit_tests: - cmd = [] - if input_api.platform == 'win32' and unit_test.endswith('.py'): - # Windows needs some help. - cmd = [input_api.python_executable] - cmd.append(unit_test) + cmd = [unit_test] if input_api.verbose: cmd.append('--verbose') kwargs = {'cwd': input_api.PresubmitLocalPath()} diff --git a/presubmit_support.py b/presubmit_support.py index 8493d273c..5b89a335d 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -438,8 +438,13 @@ class InputApi(object): self.unittest = unittest self.urllib2 = urllib2 - # To easily fork python. - self.python_executable = sys.executable + self.is_windows = sys.platform == 'win32' + + # Set python_executable to 'python'. This is interpreted in CallCommand to + # convert to vpython in order to allow scripts in other repos (e.g. src.git) + # to automatically pick up that repo's .vpython file, instead of inheriting + # the one in depot_tools. + self.python_executable = 'python' self.environ = os.environ # InputApi.platform is the platform you're currently running on. @@ -468,7 +473,6 @@ class InputApi(object): fopen=file, os_path=self.os_path) self.owners_finder = owners_finder.OwnersFinder self.verbose = verbose - self.is_windows = sys.platform == 'win32' self.Command = CommandData # Replace and as headers that need to be included @@ -1533,12 +1537,24 @@ def CallCommand(cmd_data): multiprocessing module. multiprocessing needs a top level function with a single argument. + + This function converts invocation of .py files and invocations of "python" to + vpython invocations. """ + vpython = 'vpython.bat' if sys.platform == 'win32' else 'vpython' + + cmd = cmd_data.cmd + if cmd[0] == 'python': + cmd = list(cmd) + cmd[0] = vpython + elif cmd[0].endswith('.py'): + cmd = [vpython] + cmd + cmd_data.kwargs['stdout'] = subprocess.PIPE cmd_data.kwargs['stderr'] = subprocess.STDOUT try: start = time.time() - (out, _), code = subprocess.communicate(cmd_data.cmd, **cmd_data.kwargs) + (out, _), code = subprocess.communicate(cmd, **cmd_data.kwargs) duration = time.time() - start except OSError as e: duration = time.time() - start diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index d9ac3e8fd..e94b5c7d9 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2786,7 +2786,9 @@ class CannedChecksUnittest(PresubmitTestsBase): CommHelper(input_api, ['allo', '--verbose'], cwd=self.fake_root_dir) cmd = ['bar.py', '--verbose'] if input_api.platform == 'win32': - cmd.insert(0, input_api.python_executable) + cmd.insert(0, 'vpython.bat') + else: + cmd.insert(0, 'vpython') CommHelper(input_api, cmd, cwd=self.fake_root_dir, ret=(('', None), 1)) self.mox.ReplayAll()