Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 1 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 6 | # Use of this source code is governed by a BSD-style license that can be |
| 7 | # found in the LICENSE file. |
| 8 | |
| 9 | # For details on the depot tools provided presubmit API see: |
| 10 | # http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 11 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 12 | import sys |
| 13 | |
| 14 | sys.path.insert(1, 'presubmit') |
| 15 | import presubmits |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 16 | |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 17 | |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 18 | def CheckGenerated(input_api, output_api): |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 19 | """Checks all scripts that produce generated output. |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 20 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 21 | Checks that all of the scripts that produce generated output in this |
| 22 | repository have been ran and that the generated output is up to date. |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 23 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 24 | Args: |
| 25 | input_api: InputApi, provides information about the change. |
| 26 | output_api: OutputApi, provides the mechanism for returning a response. |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 27 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 28 | Returns: |
| 29 | list of PresubmitError, or empty list if no errors. |
| 30 | """ |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 31 | results = [] |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 32 | |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 33 | # Starting with generate.sh. |
| 34 | results.extend(presubmits.CheckGenerated(input_api, output_api)) |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 35 | |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 36 | err_msg = ("gen_config produced a diff for {}, please amend your changes " |
| 37 | "and try again.") |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 38 | |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 39 | # Followed by fake program and project config. |
| 40 | for config_file in [ |
| 41 | "./test/program/fake/config.star", "./test/project/fake/fake/config.star" |
| 42 | ]: |
| 43 | results.extend( |
| 44 | presubmits.CheckGenConfig( |
| 45 | input_api, |
| 46 | output_api, |
| 47 | config_file=config_file, |
| 48 | gen_config_cmd="./bin/gen_config", |
| 49 | failure_message=err_msg.format(config_file))) |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 50 | |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 51 | # The generate.sh in this repo can create files. Make sure repo is clean. |
| 52 | results.extend(presubmits.CheckUntracked(input_api, output_api)) |
David Burger | 2607af0 | 2020-07-01 10:51:45 -0600 | [diff] [blame] | 53 | |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 54 | return results |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 55 | |
| 56 | |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 57 | def CommonChecks(input_api, output_api): |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 58 | file_filter = lambda x: x.LocalPath() == 'infra/config/recipes.cfg' |
| 59 | results = input_api.canned_checks.CheckJsonParses( |
| 60 | input_api, output_api, file_filter=file_filter) |
| 61 | results.extend(CheckGenerated(input_api, output_api)) |
| 62 | for script in [ |
| 63 | './run_py_unittests.sh', |
| 64 | './run_go_unittests.sh', |
| 65 | './check_starlark.sh', |
| 66 | 'vpython3 -vpython-spec .vpython presubmit/check_dut_attributes.py', |
| 67 | ]: |
| 68 | results.extend(presubmits.CheckScript(input_api, output_api, script)) |
| 69 | return results |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 70 | |
| 71 | |
| 72 | def CheckChangeOnUpload(input_api, output_api): |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 73 | return CommonChecks(input_api, output_api) |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 74 | |
| 75 | |
| 76 | def CheckChangeOnCommit(input_api, output_api): |
Sean McAllister | c8c4306 | 2021-09-10 10:47:22 -0600 | [diff] [blame] | 77 | return CommonChecks(input_api, output_api) |