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 | |
| 47 | return results |
| 48 | |
| 49 | |
| 50 | def CheckExamples(input_api, output_api): |
| 51 | results = [] |
| 52 | ret = input_api.subprocess.call( |
| 53 | ["./check_examples.sh"], |
| 54 | stdout=input_api.subprocess.PIPE, |
| 55 | stderr=input_api.subprocess.PIPE, |
| 56 | ) |
| 57 | if ret: |
| 58 | results.append( |
| 59 | output_api.PresubmitError( |
| 60 | "go test failed. Please run check_examples.sh for details." |
| 61 | ) |
| 62 | ) |
| 63 | return results |
| 64 | |
| 65 | |
| 66 | def CheckChangeOnUpload(input_api, output_api): |
| 67 | results = [] |
| 68 | results.extend(CheckGenerated(input_api, output_api)) |
| 69 | results.extend(CheckExamples(input_api, output_api)) |
| 70 | return results |
| 71 | |
| 72 | |
| 73 | def CheckChangeOnCommit(input_api, output_api): |
| 74 | results = [] |
| 75 | results.extend(CheckGenerated(input_api, output_api)) |
| 76 | results.extend(CheckExamples(input_api, output_api)) |
| 77 | return results |