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 | |
| 17 | def CheckGenerated(input_api, output_api): |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 18 | """Checks all scripts that produce generated output. |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 19 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 20 | Checks that all of the scripts that produce generated output in this |
| 21 | 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] | 22 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 23 | Args: |
| 24 | input_api: InputApi, provides information about the change. |
| 25 | output_api: OutputApi, provides the mechanism for returning a response. |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 26 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 27 | Returns: |
| 28 | list of PresubmitError, or empty list if no errors. |
| 29 | """ |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 30 | results = [] |
| 31 | |
David Burger | 88c2daa | 2020-06-04 14:58:27 -0600 | [diff] [blame] | 32 | # Starting with generate.sh. |
| 33 | results.extend(presubmits.CheckGenerated(input_api, output_api)) |
| 34 | |
| 35 | err_msg = ("gen_config produced a diff for {}, please amend your changes " |
| 36 | "and try again.") |
| 37 | |
| 38 | # Followed by fake program and project config. |
| 39 | for config_file in ["./test/program/fake/config.star", |
| 40 | "./test/project/fake/fake/config.star"]: |
| 41 | results.extend(presubmits.CheckGenConfig( |
| 42 | input_api, output_api, |
| 43 | config_file=config_file, |
| 44 | gen_config_cmd="./bin/gen_config", |
| 45 | failure_message=err_msg.format(config_file))) |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 46 | |
David Burger | 2607af0 | 2020-07-01 10:51:45 -0600 | [diff] [blame] | 47 | # The generate.sh in this repo can create files. Make sure repo is clean. |
| 48 | results.extend(presubmits.CheckUntracked(input_api, output_api)) |
| 49 | |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 50 | return results |
| 51 | |
| 52 | |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 53 | def CommonChecks(input_api, output_api): |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 54 | results = [] |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 55 | results.extend(CheckGenerated(input_api, output_api)) |
Allen Li | 2294cfa | 2020-10-27 15:34:34 -0700 | [diff] [blame] | 56 | for script in ['./run_py_unittests.sh', |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 57 | './run_go_unittests.sh', './check_starlark.sh']: |
| 58 | results.extend(presubmits.CheckScript(input_api, output_api, script)) |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 59 | return results |
| 60 | |
| 61 | |
| 62 | def CheckChangeOnUpload(input_api, output_api): |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 63 | return CommonChecks(input_api, output_api) |
Prathmesh Prabhu | 4220754 | 2020-04-20 23:13:23 -0700 | [diff] [blame] | 64 | |
| 65 | |
| 66 | def CheckChangeOnCommit(input_api, output_api): |
David Burger | f2b424b | 2020-06-12 10:49:28 -0600 | [diff] [blame] | 67 | return CommonChecks(input_api, output_api) |