OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
6 | 6 |
7 import os as _os | 7 import os as _os |
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
9 | 9 |
10 # Justifications for each filter: | 10 # Justifications for each filter: |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 """ | 412 """ |
413 license_re = input_api.re.compile(license_re, input_api.re.MULTILINE) | 413 license_re = input_api.re.compile(license_re, input_api.re.MULTILINE) |
414 bad_files = [] | 414 bad_files = [] |
415 for f in input_api.AffectedSourceFiles(source_file_filter): | 415 for f in input_api.AffectedSourceFiles(source_file_filter): |
416 contents = input_api.ReadFile(f, 'rb') | 416 contents = input_api.ReadFile(f, 'rb') |
417 if accept_empty_files and not contents: | 417 if accept_empty_files and not contents: |
418 continue | 418 continue |
419 if not license_re.search(contents): | 419 if not license_re.search(contents): |
420 bad_files.append(f.LocalPath()) | 420 bad_files.append(f.LocalPath()) |
421 if bad_files: | 421 if bad_files: |
422 if input_api.is_committing: | 422 return [output_api.PresubmitPromptWarning( |
423 res_type = output_api.PresubmitPromptWarning | |
424 else: | |
425 res_type = output_api.PresubmitNotifyResult | |
426 return [res_type( | |
427 'License must match:\n%s\n' % license_re.pattern + | 423 'License must match:\n%s\n' % license_re.pattern + |
428 'Found a bad license header in these files:', items=bad_files)] | 424 'Found a bad license header in these files:', items=bad_files)] |
429 return [] | 425 return [] |
430 | 426 |
431 | 427 |
432 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None): | 428 def CheckChangeSvnEolStyle(input_api, output_api, source_file_filter=None): |
433 """Checks that the source files have svn:eol-style=LF.""" | 429 """Checks that the source files have svn:eol-style=LF.""" |
434 return CheckSvnProperty(input_api, output_api, | 430 return CheckSvnProperty(input_api, output_api, |
435 'svn:eol-style', 'LF', | 431 'svn:eol-style', 'LF', |
436 input_api.AffectedSourceFiles(source_file_filter)) | 432 input_api.AffectedSourceFiles(source_file_filter)) |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 for f in affected_files: | 1152 for f in affected_files: |
1157 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1153 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1158 rc = gn.main(cmd) | 1154 rc = gn.main(cmd) |
1159 if rc == 2: | 1155 if rc == 2: |
1160 warnings.append(output_api.PresubmitPromptWarning( | 1156 warnings.append(output_api.PresubmitPromptWarning( |
1161 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1157 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1162 f.AbsoluteLocalPath(), f.LocalPath()))) | 1158 f.AbsoluteLocalPath(), f.LocalPath()))) |
1163 # It's just a warning, so ignore other types of failures assuming they'll be | 1159 # It's just a warning, so ignore other types of failures assuming they'll be |
1164 # caught elsewhere. | 1160 # caught elsewhere. |
1165 return warnings | 1161 return warnings |
OLD | NEW |