blob: 38dc2ef7b85fb10b38ff9613935e52e9cda22bd0 [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
50def 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
66def 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
73def 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