| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 'nanobench_flags.py' in x.LocalPath()) | 163 'nanobench_flags.py' in x.LocalPath()) |
| 164 for f in input_api.AffectedSourceFiles(sources): | 164 for f in input_api.AffectedSourceFiles(sources): |
| 165 if 0 != subprocess.call(['python', f.LocalPath(), 'test']): | 165 if 0 != subprocess.call(['python', f.LocalPath(), 'test']): |
| 166 results.append(output_api.PresubmitError('`python %s test` failed' % f)) | 166 results.append(output_api.PresubmitError('`python %s test` failed' % f)) |
| 167 return results | 167 return results |
| 168 | 168 |
| 169 | 169 |
| 170 def _RecipeSimulationTest(input_api, output_api): | 170 def _RecipeSimulationTest(input_api, output_api): |
| 171 """Run the recipe simulation test.""" | 171 """Run the recipe simulation test.""" |
| 172 results = [] | 172 results = [] |
| 173 if not any(f.LocalPath().startswith('infra') | |
| 174 for f in input_api.AffectedFiles()): | |
| 175 return results | |
| 176 | |
| 177 recipes_py = os.path.join('infra', 'bots', 'recipes.py') | 173 recipes_py = os.path.join('infra', 'bots', 'recipes.py') |
| 178 cmd = ['python', recipes_py, 'simulation_test'] | 174 cmd = ['python', recipes_py, 'simulation_test'] |
| 179 try: | 175 try: |
| 176 input_api.logging.debug('Running: %s' % ' '.join(cmd)) |
| 180 subprocess.check_output(cmd) | 177 subprocess.check_output(cmd) |
| 181 except subprocess.CalledProcessError as e: | 178 except subprocess.CalledProcessError as e: |
| 182 results.append(output_api.PresubmitError( | 179 results.append(output_api.PresubmitError( |
| 183 '`%s` failed:\n%s' % (' '.join(cmd), e.output))) | 180 '`%s` failed:\n%s' % (' '.join(cmd), e.output))) |
| 184 return results | 181 return results |
| 185 | 182 |
| 186 | 183 |
| 187 def _GenTasksTest(input_api, output_api): | 184 def _GenTasksTest(input_api, output_api): |
| 188 """Run gen_tasks.go test.""" | 185 """Run gen_tasks.go test.""" |
| 189 results = [] | 186 results = [] |
| 190 if not any(f.LocalPath().startswith('infra') | 187 |
| 191 for f in input_api.AffectedFiles()): | 188 # Update the infra Go packages. |
| 189 cmd = ['go', 'get', '-u', 'go.skia.org/infra/...'] |
| 190 try: |
| 191 subprocess.check_call(cmd) |
| 192 except subprocess.CalledProcessError as e: |
| 193 results.append(output_api.PresubmitError( |
| 194 'Failed to run %s: %s' % (' '.join(cmd), e))) |
| 195 return results |
| 196 except os.OSError: |
| 197 results.append(output_api.PresubmitError( |
| 198 'Failed to run "%s"; is Go installed?' % ' '.join(cmd))) |
| 192 return results | 199 return results |
| 193 | 200 |
| 201 # Run gen_tasks.go --test. |
| 194 gen_tasks = os.path.join('infra', 'bots', 'gen_tasks.go') | 202 gen_tasks = os.path.join('infra', 'bots', 'gen_tasks.go') |
| 195 cmd = ['go', 'run', gen_tasks, '--test'] | 203 cmd = ['go', 'run', gen_tasks, '--test'] |
| 196 try: | 204 try: |
| 205 input_api.logging.debug('Running: %s' % ' '.join(cmd)) |
| 197 subprocess.check_output(cmd) | 206 subprocess.check_output(cmd) |
| 198 except subprocess.CalledProcessError as e: | 207 except subprocess.CalledProcessError as e: |
| 199 results.append(output_api.PresubmitError( | 208 results.append(output_api.PresubmitError( |
| 200 '`%s` failed:\n%s' % (' '.join(cmd), e.output))) | 209 '`%s` failed:\n%s' % (' '.join(cmd), e.output))) |
| 201 return results | 210 return results |
| 202 | 211 |
| 203 | 212 |
| 204 def _CheckGNFormatted(input_api, output_api): | 213 def _CheckGNFormatted(input_api, output_api): |
| 205 """Make sure any .gn files we're changing have been formatted.""" | 214 """Make sure any .gn files we're changing have been formatted.""" |
| 206 results = [] | 215 results = [] |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 253 |
| 245 | 254 |
| 246 def CheckChangeOnUpload(input_api, output_api): | 255 def CheckChangeOnUpload(input_api, output_api): |
| 247 """Presubmit checks for the change on upload. | 256 """Presubmit checks for the change on upload. |
| 248 | 257 |
| 249 The following are the presubmit checks: | 258 The following are the presubmit checks: |
| 250 * Check change has one and only one EOL. | 259 * Check change has one and only one EOL. |
| 251 """ | 260 """ |
| 252 results = [] | 261 results = [] |
| 253 results.extend(_CommonChecks(input_api, output_api)) | 262 results.extend(_CommonChecks(input_api, output_api)) |
| 254 # Run on upload, not commit, since the presubmit bot apparently doesn't have | 263 |
| 255 # coverage or Go installed. | 264 # On upload, only run these checks if something in the 'infra' dir changed. |
| 256 results.extend(_RecipeSimulationTest(input_api, output_api)) | 265 if any(f.LocalPath().startswith('infra') |
| 257 results.extend(_GenTasksTest(input_api, output_api)) | 266 for f in input_api.AffectedFiles()): |
| 267 results.extend(_RecipeSimulationTest(input_api, output_api)) |
| 268 results.extend(_GenTasksTest(input_api, output_api)) |
| 258 | 269 |
| 259 results.extend(_CheckGNFormatted(input_api, output_api)) | 270 results.extend(_CheckGNFormatted(input_api, output_api)) |
| 260 return results | 271 return results |
| 261 | 272 |
| 262 | 273 |
| 263 def _CheckTreeStatus(input_api, output_api, json_url): | 274 def _CheckTreeStatus(input_api, output_api, json_url): |
| 264 """Check whether to allow commit. | 275 """Check whether to allow commit. |
| 265 | 276 |
| 266 Args: | 277 Args: |
| 267 input_api: input related apis. | 278 input_api: input related apis. |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' | 652 http://skia-tree-status.appspot.com/. Shows a warning if it is in 'Caution' |
| 642 state and an error if it is in 'Closed' state. | 653 state and an error if it is in 'Closed' state. |
| 643 """ | 654 """ |
| 644 results = [] | 655 results = [] |
| 645 results.extend(_CommonChecks(input_api, output_api)) | 656 results.extend(_CommonChecks(input_api, output_api)) |
| 646 results.extend( | 657 results.extend( |
| 647 _CheckTreeStatus(input_api, output_api, json_url=( | 658 _CheckTreeStatus(input_api, output_api, json_url=( |
| 648 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 659 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
| 649 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 660 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
| 650 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 661 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
| 662 results.extend(_RecipeSimulationTest(input_api, output_api)) |
| 663 results.extend(_GenTasksTest(input_api, output_api)) |
| 651 return results | 664 return results |
| OLD | NEW |