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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 results = [] | 111 results = [] |
112 if failing_files: | 112 if failing_files: |
113 results.append( | 113 results.append( |
114 output_api.PresubmitError( | 114 output_api.PresubmitError( |
115 'The following files have #if or #ifdef before includes:\n%s\n\n' | 115 'The following files have #if or #ifdef before includes:\n%s\n\n' |
116 'See skbug.com/3362 for why this should be fixed.' % | 116 'See skbug.com/3362 for why this should be fixed.' % |
117 '\n'.join(failing_files))) | 117 '\n'.join(failing_files))) |
118 return results | 118 return results |
119 | 119 |
120 | 120 |
| 121 def _CopyrightChecks(input_api, output_api, source_file_filter=None): |
| 122 results = [] |
| 123 year_pattern = r'\d{4}' |
| 124 year_range_pattern = r'%s(-%s)?' % (year_pattern, year_pattern) |
| 125 years_pattern = r'%s(,%s)*,?' % (year_range_pattern, year_range_pattern) |
| 126 copyright_pattern = ( |
| 127 r'Copyright (\([cC]\) )?%s \w+' % years_pattern) |
| 128 |
| 129 for affected_file in input_api.AffectedSourceFiles(source_file_filter): |
| 130 if 'third_party' in affected_file.LocalPath(): |
| 131 continue |
| 132 contents = input_api.ReadFile(affected_file, 'rb') |
| 133 if not re.search(copyright_pattern, contents): |
| 134 results.append(output_api.PresubmitError( |
| 135 '%s is missing a correct copyright header.' % affected_file)) |
| 136 return results |
| 137 |
| 138 |
121 def _CommonChecks(input_api, output_api): | 139 def _CommonChecks(input_api, output_api): |
122 """Presubmit checks common to upload and commit.""" | 140 """Presubmit checks common to upload and commit.""" |
123 results = [] | 141 results = [] |
124 sources = lambda x: (x.LocalPath().endswith('.h') or | 142 sources = lambda x: (x.LocalPath().endswith('.h') or |
125 x.LocalPath().endswith('.gypi') or | 143 x.LocalPath().endswith('.gypi') or |
126 x.LocalPath().endswith('.gyp') or | 144 x.LocalPath().endswith('.gyp') or |
127 x.LocalPath().endswith('.py') or | 145 x.LocalPath().endswith('.py') or |
128 x.LocalPath().endswith('.sh') or | 146 x.LocalPath().endswith('.sh') or |
129 x.LocalPath().endswith('.cpp')) | 147 x.LocalPath().endswith('.cpp')) |
130 results.extend( | 148 results.extend( |
131 _CheckChangeHasEol( | 149 _CheckChangeHasEol( |
132 input_api, output_api, source_file_filter=sources)) | 150 input_api, output_api, source_file_filter=sources)) |
133 results.extend(_PythonChecks(input_api, output_api)) | 151 results.extend(_PythonChecks(input_api, output_api)) |
134 results.extend(_IfDefChecks(input_api, output_api)) | 152 results.extend(_IfDefChecks(input_api, output_api)) |
| 153 results.extend(_CopyrightChecks(input_api, output_api, |
| 154 source_file_filter=sources)) |
135 return results | 155 return results |
136 | 156 |
137 | 157 |
138 def CheckChangeOnUpload(input_api, output_api): | 158 def CheckChangeOnUpload(input_api, output_api): |
139 """Presubmit checks for the change on upload. | 159 """Presubmit checks for the change on upload. |
140 | 160 |
141 The following are the presubmit checks: | 161 The following are the presubmit checks: |
142 * Check change has one and only one EOL. | 162 * Check change has one and only one EOL. |
143 """ | 163 """ |
144 results = [] | 164 results = [] |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 state and an error if it is in 'Closed' state. | 400 state and an error if it is in 'Closed' state. |
381 """ | 401 """ |
382 results = [] | 402 results = [] |
383 results.extend(_CommonChecks(input_api, output_api)) | 403 results.extend(_CommonChecks(input_api, output_api)) |
384 results.extend( | 404 results.extend( |
385 _CheckTreeStatus(input_api, output_api, json_url=( | 405 _CheckTreeStatus(input_api, output_api, json_url=( |
386 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 406 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
387 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 407 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
388 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 408 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
389 return results | 409 return results |
OLD | NEW |