blob: d6ec0aba60d51cea39d01935e9a50fcb964ebb89 [file] [log] [blame]
Andrew Lambeceaec02020-02-11 14:16:41 -07001#!/usr/bin/env python3
2# Copyright 2020 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Run a program's constraint checks on a project."""
6
7import argparse
8import os
9
Andrew Lambc75a6392020-02-14 13:08:14 -070010from checker import constraint_suite_discovery
Andrew Lambeceaec02020-02-11 14:16:41 -070011from checker import io_utils
12
Andrew Lambc75a6392020-02-14 13:08:14 -070013COMMON_CHECKS_PATH = os.path.join(
14 os.path.dirname(__file__), 'checker', 'common_checks')
15
Andrew Lambeceaec02020-02-11 14:16:41 -070016
17def argument_parser():
18 parser = argparse.ArgumentParser(description=__doc__)
19 parser.add_argument(
20 '--program',
21 required=True,
Andrew Lamb9328c402020-03-05 12:57:59 -070022 help=('Path to the program config binary proto e.g. '
23 '.../chromiumos/src/program/program1/generated/config.binaryproto. '
24 'Note that passing a path to the repo root is deprecated, and will '
25 'raise a warning.'),
Andrew Lambeceaec02020-02-11 14:16:41 -070026 metavar='PATH')
27 parser.add_argument(
28 '--project',
29 required=True,
Andrew Lamb9328c402020-03-05 12:57:59 -070030 help=('Path to the project config binary proto e.g. '
31 '.../chromiumos/src/project/project1/generated/config.binaryproto. '
32 'Note that passing a path to the repo root is deprecated, and will '
33 'raise a warning.'),
Andrew Lambeceaec02020-02-11 14:16:41 -070034 metavar='PATH')
35 return parser
36
37
38def main():
39 parser = argument_parser()
40 args = parser.parse_args()
41
Andrew Lamb9328c402020-03-05 12:57:59 -070042 project_config = io_utils.read_config(args.project)
43 program_config = io_utils.read_config(args.program)
Andrew Lambeceaec02020-02-11 14:16:41 -070044
Andrew Lambc75a6392020-02-14 13:08:14 -070045 constraint_suite_directories = [
46 COMMON_CHECKS_PATH,
47 os.path.join(args.program, 'checks'),
Andrew Lambc75a6392020-02-14 13:08:14 -070048 ]
49
50 constraint_suites = []
51 for directory in constraint_suite_directories:
52 constraint_suites.extend(
53 constraint_suite_discovery.discover_suites(directory))
54
55 for suite in constraint_suites:
56 suite.run_checks(
57 program_config=program_config, project_config=project_config, verbose=1)
Andrew Lambeceaec02020-02-11 14:16:41 -070058
59
60if __name__ == '__main__':
61 main()