| 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 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 snapshot("done") | 1090 snapshot("done") |
| 1091 return results | 1091 return results |
| 1092 | 1092 |
| 1093 | 1093 |
| 1094 def CheckPatchFormatted(input_api, output_api): | 1094 def CheckPatchFormatted(input_api, output_api): |
| 1095 import git_cl | 1095 import git_cl |
| 1096 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1096 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] |
| 1097 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1097 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
| 1098 if code == 2: | 1098 if code == 2: |
| 1099 return [output_api.PresubmitPromptWarning( | 1099 return [output_api.PresubmitPromptWarning( |
| 1100 'The %s directory requires clang-formatting. ' | 1100 'The %s directory requires source formatting. ' |
| 1101 'Please run git cl format %s' % | 1101 'Please run git cl format %s' % |
| 1102 (input_api.basename(input_api.PresubmitLocalPath()), | 1102 (input_api.basename(input_api.PresubmitLocalPath()), |
| 1103 input_api.basename(input_api.PresubmitLocalPath())))] | 1103 input_api.basename(input_api.PresubmitLocalPath())))] |
| 1104 # As this is just a warning, ignore all other errors if the user | 1104 # As this is just a warning, ignore all other errors if the user |
| 1105 # happens to have a broken clang-format, doesn't use git, etc etc. | 1105 # happens to have a broken clang-format, doesn't use git, etc etc. |
| 1106 return [] | 1106 return [] |
| 1107 | 1107 |
| 1108 | 1108 |
| 1109 def CheckGNFormatted(input_api, output_api): | 1109 def CheckGNFormatted(input_api, output_api): |
| 1110 import gn | 1110 import gn |
| 1111 affected_files = input_api.AffectedFiles( | 1111 affected_files = input_api.AffectedFiles( |
| 1112 include_deletes=False, | 1112 include_deletes=False, |
| 1113 file_filter=lambda x: x.LocalPath().endswith('.gn') or | 1113 file_filter=lambda x: x.LocalPath().endswith('.gn') or |
| 1114 x.LocalPath().endswith('.gni')) | 1114 x.LocalPath().endswith('.gni')) |
| 1115 warnings = [] | 1115 warnings = [] |
| 1116 for f in affected_files: | 1116 for f in affected_files: |
| 1117 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1117 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
| 1118 rc = gn.main(cmd) | 1118 rc = gn.main(cmd) |
| 1119 if rc == 2: | 1119 if rc == 2: |
| 1120 warnings.append(output_api.PresubmitPromptWarning( | 1120 warnings.append(output_api.PresubmitPromptWarning( |
| 1121 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1121 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
| 1122 f.AbsoluteLocalPath(), f.LocalPath()))) | 1122 f.AbsoluteLocalPath(), f.LocalPath()))) |
| 1123 # It's just a warning, so ignore other types of failures assuming they'll be | 1123 # It's just a warning, so ignore other types of failures assuming they'll be |
| 1124 # caught elsewhere. | 1124 # caught elsewhere. |
| 1125 return warnings | 1125 return warnings |
| OLD | NEW |