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 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 snapshot("done") | 1108 snapshot("done") |
1109 return results | 1109 return results |
1110 | 1110 |
1111 | 1111 |
1112 def CheckPatchFormatted(input_api, output_api): | 1112 def CheckPatchFormatted(input_api, output_api): |
1113 import git_cl | 1113 import git_cl |
1114 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] | 1114 cmd = ['cl', 'format', '--dry-run', input_api.PresubmitLocalPath()] |
1115 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) | 1115 code, _ = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
1116 if code == 2: | 1116 if code == 2: |
1117 return [output_api.PresubmitPromptWarning( | 1117 return [output_api.PresubmitPromptWarning( |
1118 'The %s directory requires clang-formatting. ' | 1118 'The %s directory requires source formatting. ' |
1119 'Please run git cl format %s' % | 1119 'Please run git cl format %s' % |
1120 (input_api.basename(input_api.PresubmitLocalPath()), | 1120 (input_api.basename(input_api.PresubmitLocalPath()), |
1121 input_api.basename(input_api.PresubmitLocalPath())))] | 1121 input_api.basename(input_api.PresubmitLocalPath())))] |
1122 # As this is just a warning, ignore all other errors if the user | 1122 # As this is just a warning, ignore all other errors if the user |
1123 # happens to have a broken clang-format, doesn't use git, etc etc. | 1123 # happens to have a broken clang-format, doesn't use git, etc etc. |
1124 return [] | 1124 return [] |
1125 | 1125 |
1126 | 1126 |
1127 def CheckGNFormatted(input_api, output_api): | 1127 def CheckGNFormatted(input_api, output_api): |
1128 import gn | 1128 import gn |
1129 affected_files = input_api.AffectedFiles( | 1129 affected_files = input_api.AffectedFiles( |
1130 include_deletes=False, | 1130 include_deletes=False, |
1131 file_filter=lambda x: x.LocalPath().endswith('.gn') or | 1131 file_filter=lambda x: x.LocalPath().endswith('.gn') or |
1132 x.LocalPath().endswith('.gni')) | 1132 x.LocalPath().endswith('.gni')) |
1133 warnings = [] | 1133 warnings = [] |
1134 for f in affected_files: | 1134 for f in affected_files: |
1135 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1135 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1136 rc = gn.main(cmd) | 1136 rc = gn.main(cmd) |
1137 if rc == 2: | 1137 if rc == 2: |
1138 warnings.append(output_api.PresubmitPromptWarning( | 1138 warnings.append(output_api.PresubmitPromptWarning( |
1139 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1139 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1140 f.AbsoluteLocalPath(), f.LocalPath()))) | 1140 f.AbsoluteLocalPath(), f.LocalPath()))) |
1141 # It's just a warning, so ignore other types of failures assuming they'll be | 1141 # It's just a warning, so ignore other types of failures assuming they'll be |
1142 # caught elsewhere. | 1142 # caught elsewhere. |
1143 return warnings | 1143 return warnings |
OLD | NEW |