blob: 256dd272f0756876fc46017fa4342d60e7420445 [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
David Burger2607af02020-07-01 10:51:45 -060047 # 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 Prabhu42207542020-04-20 23:13:23 -070050 return results
51
52
David Burgerf2b424b2020-06-12 10:49:28 -060053def CommonChecks(input_api, output_api):
Prathmesh Prabhu42207542020-04-20 23:13:23 -070054 results = []
David Burgerf2b424b2020-06-12 10:49:28 -060055 results.extend(CheckGenerated(input_api, output_api))
56 for script in ['./check_examples.sh', './run_py_unittests.sh',
57 './run_go_unittests.sh', './check_starlark.sh']:
58 results.extend(presubmits.CheckScript(input_api, output_api, script))
Prathmesh Prabhu42207542020-04-20 23:13:23 -070059 return results
60
61
62def CheckChangeOnUpload(input_api, output_api):
David Burgerf2b424b2020-06-12 10:49:28 -060063 return CommonChecks(input_api, output_api)
Prathmesh Prabhu42207542020-04-20 23:13:23 -070064
65
66def CheckChangeOnCommit(input_api, output_api):
David Burgerf2b424b2020-06-12 10:49:28 -060067 return CommonChecks(input_api, output_api)