Check that all files include a copyright notice and no trailing whitespaces.
| 518 | r'Copyright [\d-]*20[0-2][0-9] the V8 project authors. All rights reserved.') |
| 519 | |
| 520 | class SourceProcessor(SourceFileProcessor): |
| 521 | """ |
| 522 | Check that all files include a copyright notice and no trailing whitespaces. |
| 523 | """ |
| 524 | |
| 525 | RELEVANT_EXTENSIONS = ['.js', '.cc', '.h', '.py', '.c', '.status', '.tq', '.g4'] |
| 526 | |
| 527 | def __init__(self): |
| 528 | self.runtime_function_call_pattern = self.CreateRuntimeFunctionCallMatcher() |
| 529 | |
| 530 | def CreateRuntimeFunctionCallMatcher(self): |
| 531 | runtime_h_path = join(dirname(TOOLS_PATH), 'src/runtime/runtime.h') |
| 532 | pattern = re.compile(r'\s+F\(([^,]*),.*\)') |
| 533 | runtime_functions = [] |
| 534 | with open(runtime_h_path) as f: |
| 535 | for line in f.readlines(): |
| 536 | m = pattern.match(line) |
| 537 | if m: |
| 538 | runtime_functions.append(m.group(1)) |
| 539 | if len(runtime_functions) < 250: |
| 540 | print ("Runtime functions list is suspiciously short. " |
| 541 | "Consider updating the presubmit script.") |
| 542 | sys.exit(1) |
| 543 | str = '(\%\s+(' + '|'.join(runtime_functions) + '))[\s\(]' |
| 544 | return re.compile(str) |
| 545 | |
| 546 | # Overwriting the one in the parent class. |
| 547 | def FindFilesIn(self, path): |
| 548 | if exists(path+'/.git'): |
| 549 | output = subprocess.Popen('git ls-files --full-name', |
| 550 | stdout=PIPE, cwd=path, shell=True) |
| 551 | result = [] |
| 552 | for file in decode(output.stdout.read()).split(): |
| 553 | for dir_part in dirname(file).replace(os.sep, '/').split('/'): |
| 554 | if self.IgnoreDir(dir_part): |
| 555 | break |
| 556 | else: |
| 557 | if (self.IsRelevant(file) and exists(file) |
| 558 | and not self.IgnoreFile(file)): |
| 559 | result.append(join(path, file)) |
| 560 | if output.wait() == 0: |
| 561 | return result |
| 562 | return super(SourceProcessor, self).FindFilesIn(path) |
| 563 | |
| 564 | def IsRelevant(self, name): |
| 565 | for ext in SourceProcessor.RELEVANT_EXTENSIONS: |
| 566 | if name.endswith(ext): |
| 567 | return True |
| 568 | return False |
| 569 | |
| 570 | def GetPathsToSearch(self): |
| 571 | return ['.'] |
| 572 | |
| 573 | def IgnoreDir(self, name): |
| 574 | return (super(SourceProcessor, self).IgnoreDir(name) or |
| 575 | name in ('third_party', 'out', 'obj', 'DerivedSources')) |
| 576 | |
| 577 | IGNORE_COPYRIGHTS = ['box2d.js', |
no outgoing calls
no test coverage detected
searching dependent graphs…