Fix so that you can run presubmit.py in Windows.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 15 Apr 2013 12:21:05 +0000 (12:21 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 15 Apr 2013 12:21:05 +0000 (12:21 +0000)
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 <bratell@opera.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14263 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

tools/presubmit.py

index efa8724..616505f 100755 (executable)
@@ -228,6 +228,15 @@ class CppLintProcessor(SourceFileProcessor):
   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 @@ class CppLintProcessor(SourceFileProcessor):
       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()