| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 def Run(self, path): | 185 def Run(self, path): |
| 186 all_files = [] | 186 all_files = [] |
| 187 for file in self.GetPathsToSearch(): | 187 for file in self.GetPathsToSearch(): |
| 188 all_files += self.FindFilesIn(join(path, file)) | 188 all_files += self.FindFilesIn(join(path, file)) |
| 189 if not self.ProcessFiles(all_files, path): | 189 if not self.ProcessFiles(all_files, path): |
| 190 return False | 190 return False |
| 191 return True | 191 return True |
| 192 | 192 |
| 193 def IgnoreDir(self, name): | 193 def IgnoreDir(self, name): |
| 194 return name.startswith('.') or name == 'data' or name == 'sputniktests' | 194 return (name.startswith('.') or |
| 195 name in ('data', 'kraken', 'octane', 'sunspider')) |
| 195 | 196 |
| 196 def IgnoreFile(self, name): | 197 def IgnoreFile(self, name): |
| 197 return name.startswith('.') | 198 return name.startswith('.') |
| 198 | 199 |
| 199 def FindFilesIn(self, path): | 200 def FindFilesIn(self, path): |
| 200 result = [] | 201 result = [] |
| 201 for (root, dirs, files) in os.walk(path): | 202 for (root, dirs, files) in os.walk(path): |
| 202 for ignored in [x for x in dirs if self.IgnoreDir(x)]: | 203 for ignored in [x for x in dirs if self.IgnoreDir(x)]: |
| 203 dirs.remove(ignored) | 204 dirs.remove(ignored) |
| 204 for file in files: | 205 for file in files: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 def IsRelevant(self, name): | 306 def IsRelevant(self, name): |
| 306 for ext in SourceProcessor.RELEVANT_EXTENSIONS: | 307 for ext in SourceProcessor.RELEVANT_EXTENSIONS: |
| 307 if name.endswith(ext): | 308 if name.endswith(ext): |
| 308 return True | 309 return True |
| 309 return False | 310 return False |
| 310 | 311 |
| 311 def GetPathsToSearch(self): | 312 def GetPathsToSearch(self): |
| 312 return ['.'] | 313 return ['.'] |
| 313 | 314 |
| 314 def IgnoreDir(self, name): | 315 def IgnoreDir(self, name): |
| 315 return (super(SourceProcessor, self).IgnoreDir(name) | 316 return (super(SourceProcessor, self).IgnoreDir(name) or |
| 316 or (name == 'third_party') | 317 name in ('third_party', 'gyp', 'out', 'obj', 'DerivedSources')) |
| 317 or (name == 'gyp') | |
| 318 or (name == 'out') | |
| 319 or (name == 'obj') | |
| 320 or (name == 'DerivedSources')) | |
| 321 | 318 |
| 322 IGNORE_COPYRIGHTS = ['cpplint.py', | 319 IGNORE_COPYRIGHTS = ['cpplint.py', |
| 323 'daemon.py', | 320 'daemon.py', |
| 324 'earley-boyer.js', | 321 'earley-boyer.js', |
| 325 'raytrace.js', | 322 'raytrace.js', |
| 326 'crypto.js', | 323 'crypto.js', |
| 327 'libraries.cc', | 324 'libraries.cc', |
| 328 'libraries-empty.cc', | 325 'libraries-empty.cc', |
| 329 'jsmin.py', | 326 'jsmin.py', |
| 330 'regexp-pcre.js', | 327 'regexp-pcre.js', |
| (...skipping 27 matching lines...) Expand all Loading... |
| 358 parts.pop() | 355 parts.pop() |
| 359 for part in parts: | 356 for part in parts: |
| 360 line += part.count('\n') + 1 | 357 line += part.count('\n') + 1 |
| 361 lines.append(str(line)) | 358 lines.append(str(line)) |
| 362 linenumbers = ', '.join(lines) | 359 linenumbers = ', '.join(lines) |
| 363 if len(lines) > 1: | 360 if len(lines) > 1: |
| 364 print "%s has trailing whitespaces in lines %s." % (name, linenumbers) | 361 print "%s has trailing whitespaces in lines %s." % (name, linenumbers) |
| 365 else: | 362 else: |
| 366 print "%s has trailing whitespaces in line %s." % (name, linenumbers) | 363 print "%s has trailing whitespaces in line %s." % (name, linenumbers) |
| 367 result = False | 364 result = False |
| 365 if not contents.endswith('\n') or contents.endswith('\n\n'): |
| 366 print "%s does not end with a single new line." % name |
| 367 result = False |
| 368 # Check two empty lines between declarations. | 368 # Check two empty lines between declarations. |
| 369 if name.endswith(".cc"): | 369 if name.endswith(".cc"): |
| 370 line = 0 | 370 line = 0 |
| 371 lines = [] | 371 lines = [] |
| 372 parts = contents.split('\n') | 372 parts = contents.split('\n') |
| 373 while line < len(parts) - 2: | 373 while line < len(parts) - 2: |
| 374 if self.EndOfDeclaration(parts[line]): | 374 if self.EndOfDeclaration(parts[line]): |
| 375 if self.StartOfDeclaration(parts[line + 1]): | 375 if self.StartOfDeclaration(parts[line + 1]): |
| 376 lines.append(str(line + 1)) | 376 lines.append(str(line + 1)) |
| 377 line += 1 | 377 line += 1 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 "two empty lines between declarations check..." | 426 "two empty lines between declarations check..." |
| 427 success = SourceProcessor().Run(workspace) and success | 427 success = SourceProcessor().Run(workspace) and success |
| 428 if success: | 428 if success: |
| 429 return 0 | 429 return 0 |
| 430 else: | 430 else: |
| 431 return 1 | 431 return 1 |
| 432 | 432 |
| 433 | 433 |
| 434 if __name__ == '__main__': | 434 if __name__ == '__main__': |
| 435 sys.exit(Main()) | 435 sys.exit(Main()) |
| OLD | NEW |