blob: 27f2b653235553234a25c66e501c61a900483317 [file] [log] [blame]
Prathmesh Prabhu42207542020-04-20 23:13:23 -07001# 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 Burger88c2daa2020-06-04 14:58:27 -060012import sys
13
14sys.path.insert(1, 'presubmit')
15import presubmits
Prathmesh Prabhu42207542020-04-20 23:13:23 -070016
Sean McAllisterc8c43062021-09-10 10:47:22 -060017
Prathmesh Prabhu42207542020-04-20 23:13:23 -070018def CheckGenerated(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060019 """Checks all scripts that produce generated output.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070020
David Burger88c2daa2020-06-04 14:58:27 -060021 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 Prabhu42207542020-04-20 23:13:23 -070023
David Burger88c2daa2020-06-04 14:58:27 -060024 Args:
25 input_api: InputApi, provides information about the change.
26 output_api: OutputApi, provides the mechanism for returning a response.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070027
David Burger88c2daa2020-06-04 14:58:27 -060028 Returns:
29 list of PresubmitError, or empty list if no errors.
30 """
Sean McAllisterc8c43062021-09-10 10:47:22 -060031 results = []
Prathmesh Prabhu42207542020-04-20 23:13:23 -070032
Sean McAllisterc8c43062021-09-10 10:47:22 -060033 # Starting with generate.sh.
34 results.extend(presubmits.CheckGenerated(input_api, output_api))
David Burger88c2daa2020-06-04 14:58:27 -060035
Sean McAllisterc8c43062021-09-10 10:47:22 -060036 err_msg = ("gen_config produced a diff for {}, please amend your changes "
37 "and try again.")
David Burger88c2daa2020-06-04 14:58:27 -060038
Sean McAllisterc8c43062021-09-10 10:47:22 -060039 # 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 Prabhu42207542020-04-20 23:13:23 -070050
Sean McAllisterc8c43062021-09-10 10:47:22 -060051 # The generate.sh in this repo can create files. Make sure repo is clean.
52 results.extend(presubmits.CheckUntracked(input_api, output_api))
David Burger2607af02020-07-01 10:51:45 -060053
Sean McAllisterc8c43062021-09-10 10:47:22 -060054 return results
Prathmesh Prabhu42207542020-04-20 23:13:23 -070055
56
David Burgerf2b424b2020-06-12 10:49:28 -060057def CommonChecks(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060058 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 Prabhu42207542020-04-20 23:13:23 -070070
71
72def CheckChangeOnUpload(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060073 return CommonChecks(input_api, output_api)
Prathmesh Prabhu42207542020-04-20 23:13:23 -070074
75
76def CheckChangeOnCommit(input_api, output_api):
Sean McAllisterc8c43062021-09-10 10:47:22 -060077 return CommonChecks(input_api, output_api)