OLD | NEW |
---|---|
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 | 5 |
6 """Top-level presubmit script for Skia. | 6 """Top-level presubmit script for Skia. |
7 | 7 |
8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
9 for more details about the presubmit API built into gcl. | 9 for more details about the presubmit API built into gcl. |
10 """ | 10 """ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 for affected_file in input_api.AffectedSourceFiles(None): | 70 for affected_file in input_api.AffectedSourceFiles(None): |
71 affected_file_path = affected_file.LocalPath() | 71 affected_file_path = affected_file.LocalPath() |
72 if affected_file_path.endswith('.py'): | 72 if affected_file_path.endswith('.py'): |
73 affected_python_files.append(affected_file_path) | 73 affected_python_files.append(affected_file_path) |
74 return input_api.canned_checks.RunPylint( | 74 return input_api.canned_checks.RunPylint( |
75 input_api, output_api, | 75 input_api, output_api, |
76 disabled_warnings=pylint_disabled_warnings, | 76 disabled_warnings=pylint_disabled_warnings, |
77 white_list=affected_python_files) | 77 white_list=affected_python_files) |
78 | 78 |
79 | 79 |
80 def _IfDefChecks(input_api, output_api): | |
81 """Ensures if/ifdef are not before includes. See skbug/3362 for details.""" | |
82 copyright_start_pattern = re.compile('\/\*\w*\n') | |
83 copyright_middle_pattern = re.compile(' \*.*\n') | |
84 copyright_end_pattern = re.compile(' \*\/.*\n') | |
borenet
2015/03/12 12:47:48
Suggest using '^\/\*w*$' etc
rmistry
2015/03/12 13:13:59
Yes, I forgot to do this. Done.
| |
85 def is_in_copyright_block(line): | |
86 return (copyright_start_pattern.match(line) or | |
87 copyright_middle_pattern.match(line) or | |
88 copyright_end_pattern.match(line)) | |
89 | |
90 empty_line_pattern = re.compile('\w*\n\w*') | |
borenet
2015/03/12 12:47:48
Shouldn't this be '^$' ? Why match characters in
rmistry
2015/03/12 13:13:59
This is to treat lines that have only whitespaces
| |
91 def is_empty_line(line): | |
92 return empty_line_pattern.match(line) | |
93 | |
94 failing_files = [] | |
95 for affected_file in input_api.AffectedSourceFiles(None): | |
96 affected_file_path = affected_file.LocalPath() | |
97 if affected_file_path.endswith('.cpp') or affected_file_path.endswith('.h'): | |
98 f = open(affected_file_path) | |
99 for line in f.xreadlines(): | |
100 if is_in_copyright_block(line) or is_empty_line(line): | |
101 continue | |
102 # The below will be the first real line after the copyright block and | |
103 # newlines. | |
104 if line.startswith('#if 0 '): | |
105 pass | |
borenet
2015/03/12 12:47:48
Why not break here?
rmistry
2015/03/12 13:13:59
Either way works. I prefer having less places to e
| |
106 elif line.startswith('#if ') or line.startswith('#ifdef '): | |
107 failing_files.append(affected_file_path) | |
108 break | |
109 | |
110 results = [] | |
111 if failing_files: | |
112 results.append( | |
113 output_api.PresubmitError( | |
114 'The following files have #if or #ifdef before includes:\n%s\n\n' | |
115 'See skbug.com/3362 for why this should be fixed.' % | |
116 '\n'.join(failing_files))) | |
117 return results | |
118 | |
119 | |
80 def _CommonChecks(input_api, output_api): | 120 def _CommonChecks(input_api, output_api): |
81 """Presubmit checks common to upload and commit.""" | 121 """Presubmit checks common to upload and commit.""" |
82 results = [] | 122 results = [] |
83 sources = lambda x: (x.LocalPath().endswith('.h') or | 123 sources = lambda x: (x.LocalPath().endswith('.h') or |
84 x.LocalPath().endswith('.gypi') or | 124 x.LocalPath().endswith('.gypi') or |
85 x.LocalPath().endswith('.gyp') or | 125 x.LocalPath().endswith('.gyp') or |
86 x.LocalPath().endswith('.py') or | 126 x.LocalPath().endswith('.py') or |
87 x.LocalPath().endswith('.sh') or | 127 x.LocalPath().endswith('.sh') or |
88 x.LocalPath().endswith('.cpp')) | 128 x.LocalPath().endswith('.cpp')) |
89 results.extend( | 129 results.extend( |
90 _CheckChangeHasEol( | 130 _CheckChangeHasEol( |
91 input_api, output_api, source_file_filter=sources)) | 131 input_api, output_api, source_file_filter=sources)) |
92 results.extend(_PythonChecks(input_api, output_api)) | 132 results.extend(_PythonChecks(input_api, output_api)) |
133 results.extend(_IfDefChecks(input_api, output_api)) | |
93 return results | 134 return results |
94 | 135 |
95 | 136 |
96 def CheckChangeOnUpload(input_api, output_api): | 137 def CheckChangeOnUpload(input_api, output_api): |
97 """Presubmit checks for the change on upload. | 138 """Presubmit checks for the change on upload. |
98 | 139 |
99 The following are the presubmit checks: | 140 The following are the presubmit checks: |
100 * Check change has one and only one EOL. | 141 * Check change has one and only one EOL. |
101 """ | 142 """ |
102 results = [] | 143 results = [] |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 state and an error if it is in 'Closed' state. | 374 state and an error if it is in 'Closed' state. |
334 """ | 375 """ |
335 results = [] | 376 results = [] |
336 results.extend(_CommonChecks(input_api, output_api)) | 377 results.extend(_CommonChecks(input_api, output_api)) |
337 results.extend( | 378 results.extend( |
338 _CheckTreeStatus(input_api, output_api, json_url=( | 379 _CheckTreeStatus(input_api, output_api, json_url=( |
339 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 380 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
340 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 381 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
341 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 382 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
342 return results | 383 return results |
OLD | NEW |