Index: tools/presubmit.py |
diff --git a/tools/presubmit.py b/tools/presubmit.py |
index 7af6e3d0d80e3a85c7606af692c8b1c249e78922..8619a2536d9bc517a657b6f9a6315783c19ffe2b 100755 |
--- a/tools/presubmit.py |
+++ b/tools/presubmit.py |
@@ -1,6 +1,6 @@ |
#!/usr/bin/env python |
# |
-# Copyright 2011 the V8 project authors. All rights reserved. |
+# Copyright 2012 the V8 project authors. All rights reserved. |
# Redistribution and use in source and binary forms, with or without |
# modification, are permitted provided that the following conditions are |
# met: |
@@ -42,6 +42,7 @@ import pickle |
import re |
import sys |
import subprocess |
+import multiprocessing |
from subprocess import PIPE |
# Disabled LINT rules and reason. |
@@ -101,6 +102,33 @@ whitespace/todo |
""".split() |
+LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]|^Done processing') |
+ |
+ |
+def CppLintWorker(command): |
+ try: |
+ process = subprocess.Popen(command, stderr=subprocess.PIPE) |
+ process.wait() |
+ out_lines = "" |
+ error_count = -1 |
+ while True: |
+ out_line = process.stderr.readline() |
+ if out_line == '' and process.poll() != None: |
+ break |
+ m = LINT_OUTPUT_PATTERN.match(out_line) |
+ if m: |
+ out_lines += out_line |
+ error_count += 1 |
+ sys.stderr.write(out_lines) |
+ return error_count |
+ except KeyboardInterrupt: |
+ child.kill() |
Jakob Kummerow
2012/01/20 14:56:22
I think you meant s/child/process/
Yang
2012/01/20 16:18:31
This is actually interesting. Previously the scrip
|
+ except: |
+ print('Error running cpplint.py. Please make sure you have depot_tools' + |
+ ' in your $PATH. Lint check skipped.') |
+ child.kill() |
Jakob Kummerow
2012/01/20 14:56:22
same here.
Yang
2012/01/20 16:18:31
Done.
|
+ |
+ |
class FileContentsCache(object): |
def __init__(self, sums_file_name): |
@@ -206,29 +234,26 @@ class CppLintProcessor(SourceFileProcessor): |
return True |
filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) |
- command = ['cpplint.py', '--filter', filt] + join(files) |
+ command = ['cpplint.py', '--filter', filt] |
local_cpplint = join(path, "tools", "cpplint.py") |
if exists(local_cpplint): |
- command = ['python', local_cpplint, '--filter', filt] + join(files) |
+ command = ['python', local_cpplint, '--filter', filt] |
+ commands = join([command + [file] for file in files]) |
+ count = multiprocessing.cpu_count() |
+ pool = multiprocessing.Pool(count) |
try: |
- process = subprocess.Popen(command, stderr=subprocess.PIPE) |
- except: |
- print('Error running cpplint.py. Please make sure you have depot_tools' + |
- ' in your $PATH. Lint check skipped.') |
- return True |
- LINT_ERROR_PATTERN = re.compile(r'^(.+)[:(]\d+[:)]') |
- while True: |
- out_line = process.stderr.readline() |
- if out_line == '' and process.poll() != None: |
- break |
- sys.stderr.write(out_line) |
- m = LINT_ERROR_PATTERN.match(out_line) |
- if m: |
- good_files_cache.RemoveFile(m.group(1)) |
+ results = pool.map(CppLintWorker, commands) |
Jakob Kummerow
2012/01/20 14:56:22
I need the following patch to make this react prop
Yang
2012/01/20 16:18:31
Done.
|
+ except KeyboardInterrupt: |
+ print "\nCaught KeyboardInterrupt, terminating workers." |
+ sys.exit(1) |
+ |
+ for i in range(len(files)): |
+ if results[i] > 0: |
+ good_files_cache.RemoveFile(files[i]) |
+ print "Total errors found: %d" % sum(results) |
good_files_cache.Save() |
- return process.returncode == 0 |
Jakob Kummerow
2012/01/20 14:56:22
I think we still want a return value here. IIUC, i
Yang
2012/01/20 16:18:31
Done.
|
COPYRIGHT_HEADER_PATTERN = re.compile( |