blob: 8b8a61da1dcee3e0c67cd3dee8b1fa238329d299 [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
17def CheckGenerated(input_api, output_api):
David Burger88c2daa2020-06-04 14:58:27 -060018 """Checks all scripts that produce generated output.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070019
David Burger88c2daa2020-06-04 14:58:27 -060020 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 Prabhu42207542020-04-20 23:13:23 -070022
David Burger88c2daa2020-06-04 14:58:27 -060023 Args:
24 input_api: InputApi, provides information about the change.
25 output_api: OutputApi, provides the mechanism for returning a response.
Prathmesh Prabhu42207542020-04-20 23:13:23 -070026
David Burger88c2daa2020-06-04 14:58:27 -060027 Returns:
28 list of PresubmitError, or empty list if no errors.
29 """
Prathmesh Prabhu42207542020-04-20 23:13:23 -070030 results = []
31
David Burger88c2daa2020-06-04 14:58:27 -060032 # 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 Prabhu42207542020-04-20 23:13:23 -070046
47 return results
48
49
David Burgerf2b424b2020-06-12 10:49:28 -060050def CommonChecks(input_api, output_api):
Prathmesh Prabhu42207542020-04-20 23:13:23 -070051 results = []
David Burgerf2b424b2020-06-12 10:49:28 -060052 results.extend(CheckGenerated(input_api, output_api))
53 for script in ['./check_examples.sh', './run_py_unittests.sh',
54 './run_go_unittests.sh', './check_starlark.sh']:
55 results.extend(presubmits.CheckScript(input_api, output_api, script))
Prathmesh Prabhu42207542020-04-20 23:13:23 -070056 return results
57
58
59def CheckChangeOnUpload(input_api, output_api):
David Burgerf2b424b2020-06-12 10:49:28 -060060 return CommonChecks(input_api, output_api)
Prathmesh Prabhu42207542020-04-20 23:13:23 -070061
62
63def CheckChangeOnCommit(input_api, output_api):
David Burgerf2b424b2020-06-12 10:49:28 -060064 return CommonChecks(input_api, output_api)