Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: tools/presubmit.py

Issue 9192010: Parallelize cpplint in presubmit and fix usage of DISALLOW_* macros. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2011 the V8 project authors. All rights reserved. 3 # Copyright 2012 the V8 project authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following 11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided 12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution. 13 # with the distribution.
(...skipping 21 matching lines...) Expand all
35 md5er = md5.new 35 md5er = md5.new
36 36
37 37
38 import optparse 38 import optparse
39 import os 39 import os
40 from os.path import abspath, join, dirname, basename, exists 40 from os.path import abspath, join, dirname, basename, exists
41 import pickle 41 import pickle
42 import re 42 import re
43 import sys 43 import sys
44 import subprocess 44 import subprocess
45 import multiprocessing
45 from subprocess import PIPE 46 from subprocess import PIPE
46 47
47 # Disabled LINT rules and reason. 48 # Disabled LINT rules and reason.
48 # build/include_what_you_use: Started giving false positives for variables 49 # build/include_what_you_use: Started giving false positives for variables
49 # named "string" and "map" assuming that you needed to include STL headers. 50 # named "string" and "map" assuming that you needed to include STL headers.
50 51
51 ENABLED_LINT_RULES = """ 52 ENABLED_LINT_RULES = """
52 build/class 53 build/class
53 build/deprecated 54 build/deprecated
54 build/endif_comment 55 build/endif_comment
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 whitespace/labels 95 whitespace/labels
95 whitespace/line_length 96 whitespace/line_length
96 whitespace/newline 97 whitespace/newline
97 whitespace/operators 98 whitespace/operators
98 whitespace/parens 99 whitespace/parens
99 whitespace/tab 100 whitespace/tab
100 whitespace/todo 101 whitespace/todo
101 """.split() 102 """.split()
102 103
103 104
105 LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]|^Done processing')
106
107
108 def CppLintWorker(command):
109 try:
110 process = subprocess.Popen(command, stderr=subprocess.PIPE)
111 process.wait()
112 out_lines = ""
113 error_count = -1
114 while True:
115 out_line = process.stderr.readline()
116 if out_line == '' and process.poll() != None:
117 break
118 m = LINT_OUTPUT_PATTERN.match(out_line)
119 if m:
120 out_lines += out_line
121 error_count += 1
122 sys.stderr.write(out_lines)
123 return error_count
124 except KeyboardInterrupt:
125 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
126 except:
127 print('Error running cpplint.py. Please make sure you have depot_tools' +
128 ' in your $PATH. Lint check skipped.')
129 child.kill()
Jakob Kummerow 2012/01/20 14:56:22 same here.
Yang 2012/01/20 16:18:31 Done.
130
131
104 class FileContentsCache(object): 132 class FileContentsCache(object):
105 133
106 def __init__(self, sums_file_name): 134 def __init__(self, sums_file_name):
107 self.sums = {} 135 self.sums = {}
108 self.sums_file_name = sums_file_name 136 self.sums_file_name = sums_file_name
109 137
110 def Load(self): 138 def Load(self):
111 try: 139 try:
112 sums_file = None 140 sums_file = None
113 try: 141 try:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 227
200 def ProcessFiles(self, files, path): 228 def ProcessFiles(self, files, path):
201 good_files_cache = FileContentsCache('.cpplint-cache') 229 good_files_cache = FileContentsCache('.cpplint-cache')
202 good_files_cache.Load() 230 good_files_cache.Load()
203 files = good_files_cache.FilterUnchangedFiles(files) 231 files = good_files_cache.FilterUnchangedFiles(files)
204 if len(files) == 0: 232 if len(files) == 0:
205 print 'No changes in files detected. Skipping cpplint check.' 233 print 'No changes in files detected. Skipping cpplint check.'
206 return True 234 return True
207 235
208 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) 236 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES])
209 command = ['cpplint.py', '--filter', filt] + join(files) 237 command = ['cpplint.py', '--filter', filt]
210 local_cpplint = join(path, "tools", "cpplint.py") 238 local_cpplint = join(path, "tools", "cpplint.py")
211 if exists(local_cpplint): 239 if exists(local_cpplint):
212 command = ['python', local_cpplint, '--filter', filt] + join(files) 240 command = ['python', local_cpplint, '--filter', filt]
213 241
242 commands = join([command + [file] for file in files])
243 count = multiprocessing.cpu_count()
244 pool = multiprocessing.Pool(count)
214 try: 245 try:
215 process = subprocess.Popen(command, stderr=subprocess.PIPE) 246 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.
216 except: 247 except KeyboardInterrupt:
217 print('Error running cpplint.py. Please make sure you have depot_tools' + 248 print "\nCaught KeyboardInterrupt, terminating workers."
218 ' in your $PATH. Lint check skipped.') 249 sys.exit(1)
219 return True
220 LINT_ERROR_PATTERN = re.compile(r'^(.+)[:(]\d+[:)]')
221 while True:
222 out_line = process.stderr.readline()
223 if out_line == '' and process.poll() != None:
224 break
225 sys.stderr.write(out_line)
226 m = LINT_ERROR_PATTERN.match(out_line)
227 if m:
228 good_files_cache.RemoveFile(m.group(1))
229 250
251 for i in range(len(files)):
252 if results[i] > 0:
253 good_files_cache.RemoveFile(files[i])
254
255 print "Total errors found: %d" % sum(results)
230 good_files_cache.Save() 256 good_files_cache.Save()
231 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.
232 257
233 258
234 COPYRIGHT_HEADER_PATTERN = re.compile( 259 COPYRIGHT_HEADER_PATTERN = re.compile(
235 r'Copyright [\d-]*20[0-1][0-9] the V8 project authors. All rights reserved.' ) 260 r'Copyright [\d-]*20[0-1][0-9] the V8 project authors. All rights reserved.' )
236 261
237 class SourceProcessor(SourceFileProcessor): 262 class SourceProcessor(SourceFileProcessor):
238 """ 263 """
239 Check that all files include a copyright notice and no trailing whitespaces. 264 Check that all files include a copyright notice and no trailing whitespaces.
240 """ 265 """
241 266
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 print "Running copyright header and trailing whitespaces check..." 373 print "Running copyright header and trailing whitespaces check..."
349 success = SourceProcessor().Run(workspace) and success 374 success = SourceProcessor().Run(workspace) and success
350 if success: 375 if success:
351 return 0 376 return 0
352 else: 377 else:
353 return 1 378 return 1
354 379
355 380
356 if __name__ == '__main__': 381 if __name__ == '__main__':
357 sys.exit(Main()) 382 sys.exit(Main())
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698