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 2008 the V8 project authors. All rights reserved. |
|
Jakob Kummerow
2011/09/01 09:29:46
2011
| |
| 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 210 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 trailing whitespaces. |
|
Jakob Kummerow
2011/09/01 09:29:46
you mean "and *no* trailing whitespace", right?
| |
| 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 def IsRelevant(self, name): | 239 def IsRelevant(self, name): |
| 240 for ext in SourceProcessor.RELEVANT_EXTENSIONS: | 240 for ext in SourceProcessor.RELEVANT_EXTENSIONS: |
| 241 if name.endswith(ext): | 241 if name.endswith(ext): |
| 242 return True | 242 return True |
| 243 return False | 243 return False |
| 244 | 244 |
| 245 def GetPathsToSearch(self): | 245 def GetPathsToSearch(self): |
| 246 return ['.'] | 246 return ['.'] |
| 247 | 247 |
| 248 def IgnoreDir(self, name): | 248 def IgnoreDir(self, name): |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 266 result = True | 266 result = True |
| 267 base = basename(name) | 267 base = basename(name) |
| 268 if not base in SourceProcessor.IGNORE_TABS: | 268 if not base in SourceProcessor.IGNORE_TABS: |
| 269 if '\t' in contents: | 269 if '\t' in contents: |
| 270 print "%s contains tabs" % name | 270 print "%s contains tabs" % name |
| 271 result = False | 271 result = False |
| 272 if not base in SourceProcessor.IGNORE_COPYRIGHTS: | 272 if not base in SourceProcessor.IGNORE_COPYRIGHTS: |
| 273 if not COPYRIGHT_HEADER_PATTERN.search(contents): | 273 if not COPYRIGHT_HEADER_PATTERN.search(contents): |
| 274 print "%s is missing a correct copyright header." % name | 274 print "%s is missing a correct copyright header." % name |
| 275 result = False | 275 result = False |
| 276 if ' \n' in contents or contents.endswith(' '): | |
|
Jakob Kummerow
2011/09/01 09:29:46
The "contents.endswith(' ')" case isn't handled be
| |
| 277 line = 0 | |
| 278 lines = [] | |
| 279 for part in contents.split(' \n')[0:-1]: | |
| 280 line += part.count('\n') + 1; | |
| 281 lines.append(str(line)); | |
| 282 linenumbers = ', '.join(lines); | |
| 283 if len(lines) > 1: | |
| 284 print "%s has trailing whitespaces in lines: %s" % (name, linenumbers) | |
|
Kevin Millikin (Chromium)
2011/09/01 09:32:21
There is already a check for trailing whitespace f
| |
| 285 else: | |
| 286 print "%s has trailing whitespaces in line %s" % (name, linenumbers) | |
| 287 result = False | |
| 276 return result | 288 return result |
| 277 | 289 |
| 278 def ProcessFiles(self, files, path): | 290 def ProcessFiles(self, files, path): |
| 279 success = True | 291 success = True |
| 280 for file in files: | 292 for file in files: |
| 281 try: | 293 try: |
| 282 handle = open(file) | 294 handle = open(file) |
| 283 contents = handle.read() | 295 contents = handle.read() |
| 284 success = self.ProcessContents(file, contents) and success | 296 success = self.ProcessContents(file, contents) and success |
| 285 finally: | 297 finally: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 303 success = CppLintProcessor().Run(workspace) and success | 315 success = CppLintProcessor().Run(workspace) and success |
| 304 success = SourceProcessor().Run(workspace) and success | 316 success = SourceProcessor().Run(workspace) and success |
| 305 if success: | 317 if success: |
| 306 return 0 | 318 return 0 |
| 307 else: | 319 else: |
| 308 return 1 | 320 return 1 |
| 309 | 321 |
| 310 | 322 |
| 311 if __name__ == '__main__': | 323 if __name__ == '__main__': |
| 312 sys.exit(Main()) | 324 sys.exit(Main()) |
| OLD | NEW |