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