blob: 0b770ae51331d40e41ee4d22c4e9fb2db40f9734 [file] [log] [blame]
Mike Frysingerb1237032022-09-12 14:44:40 -04001# Copyright 2020 The ChromiumOS Authors
Prathmesh Prabhu42207542020-04-20 23:13:23 -07002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# For details on the depot tools provided presubmit API see:
6# http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7
David Burger88c2daa2020-06-04 14:58:27 -06008import sys
9
10sys.path.insert(1, 'presubmit')
11import presubmits
Prathmesh Prabhu42207542020-04-20 23:13:23 -070012
Sean McAllisterc8c43062021-09-10 10:47:22 -060013
Prathmesh Prabhu42207542020-04-20 23:13:23 -070014def CheckGenerated(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060015 """Checks all scripts that produce generated output.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070016
David Burger88c2daa2020-06-04 14:58:27 -060017 Checks that all of the scripts that produce generated output in this
18 repository have been ran and that the generated output is up to date.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070019
David Burger88c2daa2020-06-04 14:58:27 -060020 Args:
21 input_api: InputApi, provides information about the change.
22 output_api: OutputApi, provides the mechanism for returning a response.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070023
David Burger88c2daa2020-06-04 14:58:27 -060024 Returns:
25 list of PresubmitError, or empty list if no errors.
26 """
Sean McAllisterc8c43062021-09-10 10:47:22 -060027 results = []
Prathmesh Prabhu42207542020-04-20 23:13:23 -070028
Sean McAllisterc8c43062021-09-10 10:47:22 -060029 # Starting with generate.sh.
30 results.extend(presubmits.CheckGenerated(input_api, output_api))
David Burger88c2daa2020-06-04 14:58:27 -060031
Sean McAllisterc8c43062021-09-10 10:47:22 -060032 err_msg = ("gen_config produced a diff for {}, please amend your changes "
33 "and try again.")
David Burger88c2daa2020-06-04 14:58:27 -060034
Sean McAllisterc8c43062021-09-10 10:47:22 -060035 # Followed by fake program and project config.
36 for config_file in [
37 "./test/program/fake/config.star", "./test/project/fake/fake/config.star"
38 ]:
39 results.extend(
40 presubmits.CheckGenConfig(
41 input_api,
42 output_api,
43 config_file=config_file,
44 gen_config_cmd="./bin/gen_config",
45 failure_message=err_msg.format(config_file)))
Prathmesh Prabhu42207542020-04-20 23:13:23 -070046
Sean McAllisterc8c43062021-09-10 10:47:22 -060047 # The generate.sh in this repo can create files. Make sure repo is clean.
48 results.extend(presubmits.CheckUntracked(input_api, output_api))
David Burger2607af02020-07-01 10:51:45 -060049
Sean McAllisterc8c43062021-09-10 10:47:22 -060050 return results
Prathmesh Prabhu42207542020-04-20 23:13:23 -070051
52
David Burgerf2b424b2020-06-12 10:49:28 -060053def CommonChecks(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060054 file_filter = lambda x: x.LocalPath() == 'infra/config/recipes.cfg'
55 results = input_api.canned_checks.CheckJsonParses(
56 input_api, output_api, file_filter=file_filter)
57 results.extend(CheckGenerated(input_api, output_api))
58 for script in [
59 './run_py_unittests.sh',
60 './run_go_unittests.sh',
61 './check_starlark.sh',
62 'vpython3 -vpython-spec .vpython presubmit/check_dut_attributes.py',
63 ]:
64 results.extend(presubmits.CheckScript(input_api, output_api, script))
65 return results
Prathmesh Prabhu42207542020-04-20 23:13:23 -070066
67
68def CheckChangeOnUpload(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060069 return CommonChecks(input_api, output_api)
Prathmesh Prabhu42207542020-04-20 23:13:23 -070070
71
72def CheckChangeOnCommit(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060073 return CommonChecks(input_api, output_api)