From 55b239185738fda7ff3816b3484db446f92121c3 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 15 Apr 2013 12:21:05 +0000 Subject: [PATCH] Fix so that you can run presubmit.py in Windows. presubmit.py tried to execute cpplint.py directly, but in Windows it's the shell that connects that to the python binary so the execution (subprocess.Popen) needs to be told how to find python. An alternative would be to call subprocess.Popen with shell=True but this is less dangerous. Review URL: https://chromiumcodereview.appspot.com/13849008 Patch from Daniel Bratell . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14263 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- tools/presubmit.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/presubmit.py b/tools/presubmit.py index efa8724e765d..616505f3cd75 100755 --- a/tools/presubmit.py +++ b/tools/presubmit.py @@ -228,6 +228,15 @@ def IgnoreFile(self, name): def GetPathsToSearch(self): return ['src', 'preparser', 'include', 'samples', join('test', 'cctest')] + def GetCpplintScript(self, prio_path): + for path in [prio_path] + os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + cpplint = os.path.join(path, "cpplint.py") + if os.path.isfile(cpplint): + return cpplint + + return None + def ProcessFiles(self, files, path): good_files_cache = FileContentsCache('.cpplint-cache') good_files_cache.Load() @@ -237,10 +246,14 @@ def ProcessFiles(self, files, path): return True filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) - command = ['cpplint.py', '--filter', filt] - local_cpplint = join(path, "tools", "cpplint.py") - if exists(local_cpplint): - command = ['python', local_cpplint, '--filter', filt] + command = [sys.executable, 'cpplint.py', '--filter', filt] + cpplint = self.GetCpplintScript(join(path, "tools")) + if cpplint is None: + print('Could not find cpplint.py. Make sure ' + 'depot_tools is installed and in the path.') + sys.exit(1) + + command = [sys.executable, cpplint, '--filter', filt] commands = join([command + [file] for file in files]) count = multiprocessing.cpu_count()