| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2008 the V8 project authors. All rights reserved. | 3 # Copyright 2011 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 Loading... |
| 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 from subprocess import PIPE |
| 45 | 46 |
| 46 # Disabled LINT rules and reason. | 47 # Disabled LINT rules and reason. |
| 47 # build/include_what_you_use: Started giving false positives for variables | 48 # build/include_what_you_use: Started giving false positives for variables |
| 48 # named "string" and "map" assuming that you needed to include STL headers. | 49 # named "string" and "map" assuming that you needed to include STL headers. |
| 49 | 50 |
| 50 ENABLED_LINT_RULES = """ | 51 ENABLED_LINT_RULES = """ |
| 51 build/class | 52 build/class |
| 52 build/deprecated | 53 build/deprecated |
| 53 build/endif_comment | 54 build/endif_comment |
| 54 build/forward_decl | 55 build/forward_decl |
| (...skipping 26 matching lines...) Expand all Loading... |
| 81 runtime/references | 82 runtime/references |
| 82 runtime/rtti | 83 runtime/rtti |
| 83 runtime/sizeof | 84 runtime/sizeof |
| 84 runtime/string | 85 runtime/string |
| 85 runtime/virtual | 86 runtime/virtual |
| 86 runtime/vlog | 87 runtime/vlog |
| 87 whitespace/blank_line | 88 whitespace/blank_line |
| 88 whitespace/braces | 89 whitespace/braces |
| 89 whitespace/comma | 90 whitespace/comma |
| 90 whitespace/comments | 91 whitespace/comments |
| 91 whitespace/end_of_line | |
| 92 whitespace/ending_newline | 92 whitespace/ending_newline |
| 93 whitespace/indent | 93 whitespace/indent |
| 94 whitespace/labels | 94 whitespace/labels |
| 95 whitespace/line_length | 95 whitespace/line_length |
| 96 whitespace/newline | 96 whitespace/newline |
| 97 whitespace/operators | 97 whitespace/operators |
| 98 whitespace/parens | 98 whitespace/parens |
| 99 whitespace/tab | 99 whitespace/tab |
| 100 whitespace/todo | 100 whitespace/todo |
| 101 """.split() | 101 """.split() |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 good_files_cache.Save() | 225 good_files_cache.Save() |
| 226 return process.returncode == 0 | 226 return process.returncode == 0 |
| 227 | 227 |
| 228 | 228 |
| 229 COPYRIGHT_HEADER_PATTERN = re.compile( | 229 COPYRIGHT_HEADER_PATTERN = re.compile( |
| 230 r'Copyright [\d-]*20[0-1][0-9] the V8 project authors. All rights reserved.'
) | 230 r'Copyright [\d-]*20[0-1][0-9] the V8 project authors. All rights reserved.'
) |
| 231 | 231 |
| 232 class SourceProcessor(SourceFileProcessor): | 232 class SourceProcessor(SourceFileProcessor): |
| 233 """ | 233 """ |
| 234 Check that all files include a copyright notice. | 234 Check that all files include a copyright notice and no trailing whitespaces. |
| 235 """ | 235 """ |
| 236 | 236 |
| 237 RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', 'SConscript', | 237 RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', 'SConscript', |
| 238 'SConstruct', '.status'] | 238 'SConstruct', '.status', '.gyp', '.gypi'] |
| 239 |
| 240 # Overwriting the one in the parent class. |
| 241 def FindFilesIn(self, path): |
| 242 if os.path.exists(path+'/.git'): |
| 243 output = subprocess.Popen('git ls-files --full-name', |
| 244 stdout=PIPE, cwd=path, shell=True) |
| 245 result = [] |
| 246 for file in output.stdout.read().split(): |
| 247 for dir_part in os.path.dirname(file).split(os.sep): |
| 248 if self.IgnoreDir(dir_part): |
| 249 break |
| 250 else: |
| 251 if self.IsRelevant(file) and not self.IgnoreFile(file): |
| 252 result.append(join(path, file)) |
| 253 if output.wait() == 0: |
| 254 return result |
| 255 return super(SourceProcessor, self).FindFilesIn(path) |
| 256 |
| 239 def IsRelevant(self, name): | 257 def IsRelevant(self, name): |
| 240 for ext in SourceProcessor.RELEVANT_EXTENSIONS: | 258 for ext in SourceProcessor.RELEVANT_EXTENSIONS: |
| 241 if name.endswith(ext): | 259 if name.endswith(ext): |
| 242 return True | 260 return True |
| 243 return False | 261 return False |
| 244 | 262 |
| 245 def GetPathsToSearch(self): | 263 def GetPathsToSearch(self): |
| 246 return ['.'] | 264 return ['.'] |
| 247 | 265 |
| 248 def IgnoreDir(self, name): | 266 def IgnoreDir(self, name): |
| (...skipping 17 matching lines...) Expand all Loading... |
| 266 result = True | 284 result = True |
| 267 base = basename(name) | 285 base = basename(name) |
| 268 if not base in SourceProcessor.IGNORE_TABS: | 286 if not base in SourceProcessor.IGNORE_TABS: |
| 269 if '\t' in contents: | 287 if '\t' in contents: |
| 270 print "%s contains tabs" % name | 288 print "%s contains tabs" % name |
| 271 result = False | 289 result = False |
| 272 if not base in SourceProcessor.IGNORE_COPYRIGHTS: | 290 if not base in SourceProcessor.IGNORE_COPYRIGHTS: |
| 273 if not COPYRIGHT_HEADER_PATTERN.search(contents): | 291 if not COPYRIGHT_HEADER_PATTERN.search(contents): |
| 274 print "%s is missing a correct copyright header." % name | 292 print "%s is missing a correct copyright header." % name |
| 275 result = False | 293 result = False |
| 294 ext = base.split('.').pop() |
| 295 if ' \n' in contents or contents.endswith(' '): |
| 296 line = 0 |
| 297 lines = [] |
| 298 parts = contents.split(' \n') |
| 299 if not contents.endswith(' '): |
| 300 parts.pop() |
| 301 for part in parts: |
| 302 line += part.count('\n') + 1 |
| 303 lines.append(str(line)) |
| 304 linenumbers = ', '.join(lines) |
| 305 if len(lines) > 1: |
| 306 print "%s has trailing whitespaces in lines %s." % (name, linenumbers) |
| 307 else: |
| 308 print "%s has trailing whitespaces in line %s." % (name, linenumbers) |
| 309 result = False |
| 276 return result | 310 return result |
| 277 | 311 |
| 278 def ProcessFiles(self, files, path): | 312 def ProcessFiles(self, files, path): |
| 279 success = True | 313 success = True |
| 314 violations = 0 |
| 280 for file in files: | 315 for file in files: |
| 281 try: | 316 try: |
| 282 handle = open(file) | 317 handle = open(file) |
| 283 contents = handle.read() | 318 contents = handle.read() |
| 284 success = self.ProcessContents(file, contents) and success | 319 if not self.ProcessContents(file, contents): |
| 320 success = False |
| 321 violations += 1 |
| 285 finally: | 322 finally: |
| 286 handle.close() | 323 handle.close() |
| 324 print "Total violating files: %s" % violations |
| 287 return success | 325 return success |
| 288 | 326 |
| 289 | 327 |
| 290 def GetOptions(): | 328 def GetOptions(): |
| 291 result = optparse.OptionParser() | 329 result = optparse.OptionParser() |
| 292 result.add_option('--no-lint', help="Do not run cpplint", default=False, | 330 result.add_option('--no-lint', help="Do not run cpplint", default=False, |
| 293 action="store_true") | 331 action="store_true") |
| 294 return result | 332 return result |
| 295 | 333 |
| 296 | 334 |
| 297 def Main(): | 335 def Main(): |
| 298 workspace = abspath(join(dirname(sys.argv[0]), '..')) | 336 workspace = abspath(join(dirname(sys.argv[0]), '..')) |
| 299 parser = GetOptions() | 337 parser = GetOptions() |
| 300 (options, args) = parser.parse_args() | 338 (options, args) = parser.parse_args() |
| 301 success = True | 339 success = True |
| 340 print "Running C++ lint check..." |
| 302 if not options.no_lint: | 341 if not options.no_lint: |
| 303 success = CppLintProcessor().Run(workspace) and success | 342 success = CppLintProcessor().Run(workspace) and success |
| 343 print "Running copyright header and trailing whitespaces check..." |
| 304 success = SourceProcessor().Run(workspace) and success | 344 success = SourceProcessor().Run(workspace) and success |
| 305 if success: | 345 if success: |
| 306 return 0 | 346 return 0 |
| 307 else: | 347 else: |
| 308 return 1 | 348 return 1 |
| 309 | 349 |
| 310 | 350 |
| 311 if __name__ == '__main__': | 351 if __name__ == '__main__': |
| 312 sys.exit(Main()) | 352 sys.exit(Main()) |
| OLD | NEW |