• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The ChromiumOS Authors
2# 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
8"""Hook to run unit tests on upload."""
9
10import sys
11
12
13sys.path.insert(1, "presubmit")
14# pylint: disable=wrong-import-position
15import presubmits
16
17
18# pylint: enable=wrong-import-position
19
20
21USE_PYTHON3 = True
22
23
24def CheckGenerated(input_api, output_api):
25    """Checks all scripts that produce generated output.
26
27    Checks that all of the scripts that produce generated output in this
28    repository have been ran and that the generated output is up to date.
29
30    Args:
31        input_api: InputApi, provides information about the change.
32        output_api: OutputApi, provides the mechanism for returning a response.
33
34    Returns:
35        list of PresubmitError, or empty list if no errors.
36    """
37    results = []
38
39    # Starting with generate.sh.
40    results.extend(presubmits.CheckGenerated(input_api, output_api))
41
42    # The generate.sh in this repo can create files. Make sure repo is clean.
43    results.extend(presubmits.CheckUntracked(input_api, output_api))
44
45    return results
46
47
48def CommonChecks(input_api, output_api):
49    """Code to check the generated code and .star files."""
50    file_filter = lambda x: x.LocalPath() == "infra/config/recipes.cfg"
51    results = input_api.canned_checks.CheckJsonParses(
52        input_api, output_api, file_filter=file_filter
53    )
54    results.extend(CheckGenerated(input_api, output_api))
55    for script in [
56        "./run_py_unittests.sh",
57        "./run_go_unittests.sh",
58        "presubmit/check_dut_attributes.py",
59    ]:
60        results.extend(presubmits.CheckScript(input_api, output_api, script))
61    return results
62
63
64def CheckChangeOnUpload(input_api, output_api):
65    """Upload hook.
66
67    Normally disabled on ChromeOS, but used in config to validate the generated code.
68
69    """
70    return CommonChecks(input_api, output_api)
71
72
73def CheckChangeOnCommit(input_api, output_api):
74    """Commit hook."""
75    return CommonChecks(input_api, output_api)
76