Chromium Code Reviews| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 runtime/references | 81 runtime/references |
| 82 runtime/rtti | 82 runtime/rtti |
| 83 runtime/sizeof | 83 runtime/sizeof |
| 84 runtime/string | 84 runtime/string |
| 85 runtime/virtual | 85 runtime/virtual |
| 86 runtime/vlog | 86 runtime/vlog |
| 87 whitespace/blank_line | 87 whitespace/blank_line |
| 88 whitespace/braces | 88 whitespace/braces |
| 89 whitespace/comma | 89 whitespace/comma |
| 90 whitespace/comments | 90 whitespace/comments |
| 91 whitespace/end_of_line | 91 whitespace/end_of_line |
|
Kevin Millikin (Chromium)
2011/09/01 10:07:12
It's simpler to just delete this line than IGNORE_
| |
| 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 IGNORE_TRAILING_WHITESPACE_EXTENSIONS = ['.c', '.cc', '.h'] | |
| 240 | |
| 239 def IsRelevant(self, name): | 241 def IsRelevant(self, name): |
| 240 for ext in SourceProcessor.RELEVANT_EXTENSIONS: | 242 for ext in SourceProcessor.RELEVANT_EXTENSIONS: |
| 241 if name.endswith(ext): | 243 if name.endswith(ext): |
| 242 return True | 244 return True |
| 243 return False | 245 return False |
| 244 | 246 |
| 245 def GetPathsToSearch(self): | 247 def GetPathsToSearch(self): |
| 246 return ['.'] | 248 return ['.'] |
| 247 | 249 |
| 248 def IgnoreDir(self, name): | 250 def IgnoreDir(self, name): |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 266 result = True | 268 result = True |
| 267 base = basename(name) | 269 base = basename(name) |
| 268 if not base in SourceProcessor.IGNORE_TABS: | 270 if not base in SourceProcessor.IGNORE_TABS: |
| 269 if '\t' in contents: | 271 if '\t' in contents: |
| 270 print "%s contains tabs" % name | 272 print "%s contains tabs" % name |
| 271 result = False | 273 result = False |
| 272 if not base in SourceProcessor.IGNORE_COPYRIGHTS: | 274 if not base in SourceProcessor.IGNORE_COPYRIGHTS: |
| 273 if not COPYRIGHT_HEADER_PATTERN.search(contents): | 275 if not COPYRIGHT_HEADER_PATTERN.search(contents): |
| 274 print "%s is missing a correct copyright header." % name | 276 print "%s is missing a correct copyright header." % name |
| 275 result = False | 277 result = False |
| 278 ext = base.split('.').pop() | |
| 279 if not ext in SourceProcessor.IGNORE_TRAILING_WHITESPACE_EXTENSIONS and \ | |
| 280 ' \n' in contents or contents.endswith(' '): | |
| 281 line = 0 | |
| 282 lines = [] | |
| 283 parts = contents.split(' \n') | |
| 284 if not contents.endswith(' '): | |
| 285 parts.pop() | |
| 286 for part in parts: | |
| 287 line += part.count('\n') + 1 | |
| 288 lines.append(str(line)) | |
| 289 linenumbers = ', '.join(lines) | |
| 290 if len(lines) > 1: | |
| 291 print "%s has trailing whitespaces in lines: %s" % (name, linenumbers) | |
| 292 else: | |
| 293 print "%s has trailing whitespaces in line %s" % (name, linenumbers) | |
| 294 result = False | |
| 276 return result | 295 return result |
| 277 | 296 |
| 278 def ProcessFiles(self, files, path): | 297 def ProcessFiles(self, files, path): |
| 279 success = True | 298 success = True |
| 280 for file in files: | 299 for file in files: |
| 281 try: | 300 try: |
| 282 handle = open(file) | 301 handle = open(file) |
| 283 contents = handle.read() | 302 contents = handle.read() |
| 284 success = self.ProcessContents(file, contents) and success | 303 success = self.ProcessContents(file, contents) and success |
| 285 finally: | 304 finally: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 303 success = CppLintProcessor().Run(workspace) and success | 322 success = CppLintProcessor().Run(workspace) and success |
| 304 success = SourceProcessor().Run(workspace) and success | 323 success = SourceProcessor().Run(workspace) and success |
| 305 if success: | 324 if success: |
| 306 return 0 | 325 return 0 |
| 307 else: | 326 else: |
| 308 return 1 | 327 return 1 |
| 309 | 328 |
| 310 | 329 |
| 311 if __name__ == '__main__': | 330 if __name__ == '__main__': |
| 312 sys.exit(Main()) | 331 sys.exit(Main()) |
| OLD | NEW |