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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 recipes_py = os.path.join('infra', 'bots', 'recipes.py') | 179 recipes_py = os.path.join('infra', 'bots', 'recipes.py') |
180 cmd = ['python', recipes_py, 'simulation_test'] | 180 cmd = ['python', recipes_py, 'simulation_test'] |
181 try: | 181 try: |
182 subprocess.check_output(cmd) | 182 subprocess.check_output(cmd) |
183 except subprocess.CalledProcessError as e: | 183 except subprocess.CalledProcessError as e: |
184 results.append(output_api.PresubmitError( | 184 results.append(output_api.PresubmitError( |
185 '`%s` failed:\n%s' % (' '.join(cmd), e.output))) | 185 '`%s` failed:\n%s' % (' '.join(cmd), e.output))) |
186 return results | 186 return results |
187 | 187 |
| 188 def _CheckGNFormatted(input_api, output_api): |
| 189 """Make sure any .gn files we're changing have been formatted.""" |
| 190 results = [] |
| 191 for f in input_api.AffectedFiles(): |
| 192 if not f.LocalPath().endswith('.gn'): |
| 193 continue |
| 194 |
| 195 cmd = ['gn', 'format', '--dry-run', f.LocalPath()] |
| 196 try: |
| 197 subprocess.check_output(cmd) |
| 198 except subprocess.CalledProcessError: |
| 199 fix = cmd[:] |
| 200 fix[2] = '--in-place' |
| 201 results.append(output_api.PresubmitError( |
| 202 '`%s` failed, try\n\t%s' % (' '.join(cmd), ' '.join(fix)))) |
| 203 return results |
| 204 |
188 | 205 |
189 def _CommonChecks(input_api, output_api): | 206 def _CommonChecks(input_api, output_api): |
190 """Presubmit checks common to upload and commit.""" | 207 """Presubmit checks common to upload and commit.""" |
191 results = [] | 208 results = [] |
192 sources = lambda x: (x.LocalPath().endswith('.h') or | 209 sources = lambda x: (x.LocalPath().endswith('.h') or |
193 x.LocalPath().endswith('.gypi') or | 210 x.LocalPath().endswith('.gypi') or |
194 x.LocalPath().endswith('.gyp') or | 211 x.LocalPath().endswith('.gyp') or |
195 x.LocalPath().endswith('.py') or | 212 x.LocalPath().endswith('.py') or |
196 x.LocalPath().endswith('.sh') or | 213 x.LocalPath().endswith('.sh') or |
197 x.LocalPath().endswith('.m') or | 214 x.LocalPath().endswith('.m') or |
(...skipping 17 matching lines...) Expand all Loading... |
215 """Presubmit checks for the change on upload. | 232 """Presubmit checks for the change on upload. |
216 | 233 |
217 The following are the presubmit checks: | 234 The following are the presubmit checks: |
218 * Check change has one and only one EOL. | 235 * Check change has one and only one EOL. |
219 """ | 236 """ |
220 results = [] | 237 results = [] |
221 results.extend(_CommonChecks(input_api, output_api)) | 238 results.extend(_CommonChecks(input_api, output_api)) |
222 # Run on upload, not commit, since the presubmit bot apparently doesn't have | 239 # Run on upload, not commit, since the presubmit bot apparently doesn't have |
223 # coverage installed. | 240 # coverage installed. |
224 results.extend(_RecipeSimulationTest(input_api, output_api)) | 241 results.extend(_RecipeSimulationTest(input_api, output_api)) |
| 242 results.extend(_CheckGNFormatted(input_api, output_api)) |
225 return results | 243 return results |
226 | 244 |
227 | 245 |
228 def _CheckTreeStatus(input_api, output_api, json_url): | 246 def _CheckTreeStatus(input_api, output_api, json_url): |
229 """Check whether to allow commit. | 247 """Check whether to allow commit. |
230 | 248 |
231 Args: | 249 Args: |
232 input_api: input related apis. | 250 input_api: input related apis. |
233 output_api: output related apis. | 251 output_api: output related apis. |
234 json_url: url to download json style status. | 252 json_url: url to download json style status. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 state and an error if it is in 'Closed' state. | 554 state and an error if it is in 'Closed' state. |
537 """ | 555 """ |
538 results = [] | 556 results = [] |
539 results.extend(_CommonChecks(input_api, output_api)) | 557 results.extend(_CommonChecks(input_api, output_api)) |
540 results.extend( | 558 results.extend( |
541 _CheckTreeStatus(input_api, output_api, json_url=( | 559 _CheckTreeStatus(input_api, output_api, json_url=( |
542 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 560 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
543 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 561 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
544 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 562 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
545 return results | 563 return results |
OLD | NEW |