| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2012 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 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 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 import multiprocessing |
| 46 from subprocess import PIPE | 46 from subprocess import PIPE |
| 47 | 47 |
| 48 # Disabled LINT rules and reason. | 48 # Special LINT rules diverging from default and reason. |
| 49 # build/header_guard: Our guards have the form "V8_FOO_H_", not "SRC_FOO_H_". |
| 49 # build/include_what_you_use: Started giving false positives for variables | 50 # build/include_what_you_use: Started giving false positives for variables |
| 50 # named "string" and "map" assuming that you needed to include STL headers. | 51 # named "string" and "map" assuming that you needed to include STL headers. |
| 52 # TODO(bmeurer): Fix and re-enable readability/check |
| 53 # TODO(mstarzinger): Fix and re-enable build/include |
| 54 # TODO(mstarzinger): Fix and re-enable readability/namespace |
| 51 | 55 |
| 52 ENABLED_LINT_RULES = """ | 56 LINT_RULES = """ |
| 53 build/class | 57 -build/c++11 |
| 54 build/deprecated | 58 -build/header_guard |
| 55 build/endif_comment | 59 -build/include |
| 56 build/forward_decl | 60 +build/include_alpha |
| 57 build/include_alpha | 61 -build/include_what_you_use |
| 58 build/include_order | 62 -build/namespaces |
| 59 build/printf_format | 63 -readability/check |
| 60 build/storage_class | 64 -readability/inheritance |
| 61 legal/copyright | 65 -readability/namespace |
| 62 readability/boost | 66 -readability/nolint |
| 63 readability/braces | 67 +readability/streams |
| 64 readability/casting | 68 -runtime/indentation_namespace |
| 65 readability/constructors | 69 -runtime/references |
| 66 readability/fn_size | 70 -runtime/threadsafe_fn |
| 67 readability/function | 71 -whitespace/semicolon |
| 68 readability/multiline_comment | 72 -whitespace/empty_loop_body |
| 69 readability/multiline_string | |
| 70 readability/streams | |
| 71 readability/todo | |
| 72 readability/utf8 | |
| 73 runtime/arrays | |
| 74 runtime/casting | |
| 75 runtime/deprecated_fn | |
| 76 runtime/explicit | |
| 77 runtime/int | |
| 78 runtime/memset | |
| 79 runtime/mutex | |
| 80 runtime/nonconf | |
| 81 runtime/printf | |
| 82 runtime/printf_format | |
| 83 runtime/rtti | |
| 84 runtime/sizeof | |
| 85 runtime/string | |
| 86 runtime/virtual | |
| 87 runtime/vlog | |
| 88 whitespace/blank_line | |
| 89 whitespace/braces | |
| 90 whitespace/comma | |
| 91 whitespace/comments | |
| 92 whitespace/ending_newline | |
| 93 whitespace/indent | |
| 94 whitespace/labels | |
| 95 whitespace/line_length | |
| 96 whitespace/newline | |
| 97 whitespace/operators | |
| 98 whitespace/parens | |
| 99 whitespace/tab | |
| 100 whitespace/todo | |
| 101 """.split() | 73 """.split() |
| 102 | 74 |
| 103 # TODO(bmeurer): Fix and re-enable readability/check | |
| 104 | |
| 105 LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]|^Done processing') | 75 LINT_OUTPUT_PATTERN = re.compile(r'^.+[:(]\d+[:)]|^Done processing') |
| 106 FLAGS_LINE = re.compile("//\s*Flags:.*--([A-z0-9-])+_[A-z0-9].*\n") | 76 FLAGS_LINE = re.compile("//\s*Flags:.*--([A-z0-9-])+_[A-z0-9].*\n") |
| 107 | 77 |
| 108 def CppLintWorker(command): | 78 def CppLintWorker(command): |
| 109 try: | 79 try: |
| 110 process = subprocess.Popen(command, stderr=subprocess.PIPE) | 80 process = subprocess.Popen(command, stderr=subprocess.PIPE) |
| 111 process.wait() | 81 process.wait() |
| 112 out_lines = "" | 82 out_lines = "" |
| 113 error_count = -1 | 83 error_count = -1 |
| 114 while True: | 84 while True: |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return None | 219 return None |
| 250 | 220 |
| 251 def ProcessFiles(self, files, path): | 221 def ProcessFiles(self, files, path): |
| 252 good_files_cache = FileContentsCache('.cpplint-cache') | 222 good_files_cache = FileContentsCache('.cpplint-cache') |
| 253 good_files_cache.Load() | 223 good_files_cache.Load() |
| 254 files = good_files_cache.FilterUnchangedFiles(files) | 224 files = good_files_cache.FilterUnchangedFiles(files) |
| 255 if len(files) == 0: | 225 if len(files) == 0: |
| 256 print 'No changes in files detected. Skipping cpplint check.' | 226 print 'No changes in files detected. Skipping cpplint check.' |
| 257 return True | 227 return True |
| 258 | 228 |
| 259 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) | 229 filters = ",".join([n for n in LINT_RULES]) |
| 260 command = [sys.executable, 'cpplint.py', '--filter', filt] | 230 command = [sys.executable, 'cpplint.py', '--filter', filters] |
| 261 cpplint = self.GetCpplintScript(join(path, "tools")) | 231 cpplint = self.GetCpplintScript(join(path, "tools")) |
| 262 if cpplint is None: | 232 if cpplint is None: |
| 263 print('Could not find cpplint.py. Make sure ' | 233 print('Could not find cpplint.py. Make sure ' |
| 264 'depot_tools is installed and in the path.') | 234 'depot_tools is installed and in the path.') |
| 265 sys.exit(1) | 235 sys.exit(1) |
| 266 | 236 |
| 267 command = [sys.executable, cpplint, '--filter', filt] | 237 command = [sys.executable, cpplint, '--filter', filters] |
| 268 | 238 |
| 269 commands = join([command + [file] for file in files]) | 239 commands = join([command + [file] for file in files]) |
| 270 count = multiprocessing.cpu_count() | 240 count = multiprocessing.cpu_count() |
| 271 pool = multiprocessing.Pool(count) | 241 pool = multiprocessing.Pool(count) |
| 272 try: | 242 try: |
| 273 results = pool.map_async(CppLintWorker, commands).get(999999) | 243 results = pool.map_async(CppLintWorker, commands).get(999999) |
| 274 except KeyboardInterrupt: | 244 except KeyboardInterrupt: |
| 275 print "\nCaught KeyboardInterrupt, terminating workers." | 245 print "\nCaught KeyboardInterrupt, terminating workers." |
| 276 sys.exit(1) | 246 sys.exit(1) |
| 277 | 247 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 success = SourceProcessor().Run(workspace) and success | 461 success = SourceProcessor().Run(workspace) and success |
| 492 success = CheckExternalReferenceRegistration(workspace) and success | 462 success = CheckExternalReferenceRegistration(workspace) and success |
| 493 if success: | 463 if success: |
| 494 return 0 | 464 return 0 |
| 495 else: | 465 else: |
| 496 return 1 | 466 return 1 |
| 497 | 467 |
| 498 | 468 |
| 499 if __name__ == '__main__': | 469 if __name__ == '__main__': |
| 500 sys.exit(Main()) | 470 sys.exit(Main()) |
| OLD | NEW |