OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Top-level presubmit script for Chromium. | 6 """Top-level presubmit script for Chromium. |
7 | 7 |
8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
9 details on the presubmit API built into gcl. | 9 details on the presubmit API built into gcl. |
10 """ | 10 """ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 def LocalChecks(input_api, output_api, max_cols=80): | 57 def LocalChecks(input_api, output_api, max_cols=80): |
58 """Reports an error if for any source file in SOURCE_FILE_EXTENSIONS: | 58 """Reports an error if for any source file in SOURCE_FILE_EXTENSIONS: |
59 - uses CR (or CRLF) | 59 - uses CR (or CRLF) |
60 - contains a TAB | 60 - contains a TAB |
61 - has a line that ends with whitespace | 61 - has a line that ends with whitespace |
62 - contains a line >|max_cols| cols unless |max_cols| is 0. | 62 - contains a line >|max_cols| cols unless |max_cols| is 0. |
63 - File does not end in a newline, or ends in more than one. | 63 - File does not end in a newline, or ends in more than one. |
64 | 64 |
65 Note that the whole file is checked, not only the changes. | 65 Note that the whole file is checked, not only the changes. |
66 """ | 66 """ |
| 67 C_SOURCE_FILE_EXTENSIONS = ('.c', '.cc', '.cpp', '.h', '.inl') |
67 cr_files = [] | 68 cr_files = [] |
68 eof_files = [] | 69 eof_files = [] |
69 results = [] | 70 results = [] |
70 excluded_paths = [input_api.re.compile(x) for x in EXCLUDED_PATHS] | 71 excluded_paths = [input_api.re.compile(x) for x in EXCLUDED_PATHS] |
71 files = input_api.AffectedFiles() | 72 files = input_api.AffectedFiles() |
72 for f in files: | 73 for f in files: |
73 path = f.LocalPath() | 74 path = f.LocalPath() |
74 root, ext = input_api.os_path.splitext(path) | 75 root, ext = input_api.os_path.splitext(path) |
75 # Look for unsupported extensions. | 76 # Look for unsupported extensions. |
76 if not ext in SOURCE_FILE_EXTENSIONS: | 77 if not ext in SOURCE_FILE_EXTENSIONS: |
(...skipping 19 matching lines...) Expand all Loading... |
96 | 97 |
97 local_errors = [] | 98 local_errors = [] |
98 # Remove EOL character. | 99 # Remove EOL character. |
99 lines = contents.splitlines() | 100 lines = contents.splitlines() |
100 line_num = 1 | 101 line_num = 1 |
101 for line in lines: | 102 for line in lines: |
102 if line.endswith(' '): | 103 if line.endswith(' '): |
103 local_errors.append(output_api.PresubmitError( | 104 local_errors.append(output_api.PresubmitError( |
104 '%s, line %s ends with whitespaces.' % | 105 '%s, line %s ends with whitespaces.' % |
105 (path, line_num))) | 106 (path, line_num))) |
106 # Accept lines with http:// to exceed the max_cols rule. | 107 # Accept lines with http://, https:// and C #define/#pragma/#include to |
107 if max_cols and len(line) > max_cols and not 'http://' in line: | 108 # exceed the max_cols rule. |
| 109 if (max_cols and |
| 110 len(line) > max_cols and |
| 111 not 'http://' in line and |
| 112 not 'https://' in line and |
| 113 not (line[0] == '#' and ext in C_SOURCE_FILE_EXTENSIONS)): |
108 local_errors.append(output_api.PresubmitError( | 114 local_errors.append(output_api.PresubmitError( |
109 '%s, line %s has %s chars, please reduce to %d chars.' % | 115 '%s, line %s has %s chars, please reduce to %d chars.' % |
110 (path, line_num, len(line), max_cols))) | 116 (path, line_num, len(line), max_cols))) |
111 if '\t' in line: | 117 if '\t' in line: |
112 local_errors.append(output_api.PresubmitError( | 118 local_errors.append(output_api.PresubmitError( |
113 "%s, line %s contains a tab character." % | 119 "%s, line %s contains a tab character." % |
114 (path, line_num))) | 120 (path, line_num))) |
115 line_num += 1 | 121 line_num += 1 |
116 # Just show the first 5 errors. | 122 # Just show the first 5 errors. |
117 if len(local_errors) == 6: | 123 if len(local_errors) == 6: |
118 local_errors.pop() | 124 local_errors.pop() |
119 local_errors.append(output_api.PresubmitError("... and more.")) | 125 local_errors.append(output_api.PresubmitError("... and more.")) |
120 break | 126 break |
121 results.extend(local_errors) | 127 results.extend(local_errors) |
122 | 128 |
123 if cr_files: | 129 if cr_files: |
124 results.append(output_api.PresubmitError( | 130 results.append(output_api.PresubmitError( |
125 'Found CR (or CRLF) line ending in these files, please use only LF:', | 131 'Found CR (or CRLF) line ending in these files, please use only LF:', |
126 items=cr_files)) | 132 items=cr_files)) |
127 if eof_files: | 133 if eof_files: |
128 results.append(output_api.PresubmitError( | 134 results.append(output_api.PresubmitError( |
129 'These files should end in one (and only one) newline character:', | 135 'These files should end in one (and only one) newline character:', |
130 items=eof_files)) | 136 items=eof_files)) |
131 return results | 137 return results |
OLD | NEW |