Lann Martin | 46361ee | 2019-03-14 15:30:47 -0600 | [diff] [blame] | 1 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
David Burger | c0effc2 | 2020-03-04 08:27:07 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Lann Martin | 46361ee | 2019-03-14 15:30:47 -0600 | [diff] [blame] | 4 | |
recipe-roller | 4202bc6 | 2020-09-17 17:38:22 -0700 | [diff] [blame^] | 5 | import git_cl |
| 6 | |
Lann Martin | 46361ee | 2019-03-14 15:30:47 -0600 | [diff] [blame] | 7 | |
| 8 | def CommonChecks(input_api, output_api): |
| 9 | results = [] |
| 10 | |
| 11 | # recipes.py test run |
| 12 | results += input_api.RunTests([ |
| 13 | input_api.Command( |
| 14 | name='recipes test', |
| 15 | cmd=[input_api.python_executable, 'recipes.py', 'test', 'run'], |
| 16 | kwargs={}, |
| 17 | message=output_api.PresubmitError, |
| 18 | ) |
| 19 | ]) |
| 20 | |
recipe-roller | 4202bc6 | 2020-09-17 17:38:22 -0700 | [diff] [blame^] | 21 | # Python formatting issues are errors, but we need to ignore recipes.py, which |
| 22 | # we do not control. |
| 23 | bad_format = False |
| 24 | cmd = [ |
| 25 | '-C', |
| 26 | input_api.change.RepositoryRoot(), 'cl', 'format', '--dry-run', |
| 27 | '--presubmit', '--python', '--no-clang-format', '--diff' |
| 28 | ] |
| 29 | code, out = git_cl.RunGitWithCode(cmd, suppress_stderr=True) |
| 30 | for line in out.splitlines(): |
| 31 | if line.startswith('--- ') or line.startswith('+++ '): |
| 32 | if not ' recipes.py\t' in line: |
| 33 | bad_format = True |
| 34 | break |
| 35 | |
| 36 | if bad_format: |
| 37 | results += input_api.canned_checks.CheckPatchFormatted( |
| 38 | input_api, output_api, check_python=True, check_clang_format=False, |
| 39 | result_factory=output_api.PresubmitError) |
Andrew Lamb | 9b2d086 | 2019-04-03 16:38:52 -0600 | [diff] [blame] | 40 | |
Lann Martin | 46361ee | 2019-03-14 15:30:47 -0600 | [diff] [blame] | 41 | return results |
| 42 | |
| 43 | |
| 44 | CheckChangeOnUpload = CommonChecks |
| 45 | CheckChangeOnCommit = CommonChecks |