blob: 8fe419fb1703c90b29734e5520da754884e1c0b1 [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
Andrew Lambf3491802020-05-29 11:41:47 -06009import pathlib
Andrew Lambeceaec02020-02-11 14:16:41 -070010
Andrew Lambc75a6392020-02-14 13:08:14 -070011from checker import constraint_suite_discovery
Andrew Lambeceaec02020-02-11 14:16:41 -070012from checker import io_utils
13
Andrew Lambc75a6392020-02-14 13:08:14 -070014COMMON_CHECKS_PATH = os.path.join(
15 os.path.dirname(__file__), 'checker', 'common_checks')
16
Andrew Lambeceaec02020-02-11 14:16:41 -070017
18def argument_parser():
19 parser = argparse.ArgumentParser(description=__doc__)
20 parser.add_argument(
21 '--program',
22 required=True,
Andrew Lamb2413c982020-05-29 12:15:36 -060023 help=('Path to the program config json proto e.g. '
24 '.../chromiumos/src/program/program1/generated/config.jsonproto.'),
Andrew Lambeceaec02020-02-11 14:16:41 -070025 metavar='PATH')
26 parser.add_argument(
27 '--project',
28 required=True,
Andrew Lamb2413c982020-05-29 12:15:36 -060029 help=('Path to the project config binary proto e.g. '
30 '.../chromiumos/src/project/project1/generated/config.jsonproto.'),
Andrew Lambeceaec02020-02-11 14:16:41 -070031 metavar='PATH')
Andrew Lambf3491802020-05-29 11:41:47 -060032 parser.add_argument(
33 '--factory_dir',
34 # TODO(crbug.com/1085429): Require this once passed by Recipes.
35 required=False,
36 type=pathlib.Path,
37 help=('Path to the project factory confir dir e.g.'
38 '.../chromiumos/src/project/project1/factory'),
39 metavar='PATH',
40 )
Andrew Lambeceaec02020-02-11 14:16:41 -070041 return parser
42
43
44def main():
45 parser = argument_parser()
46 args = parser.parse_args()
47
Andrew Lamb9328c402020-03-05 12:57:59 -070048 project_config = io_utils.read_config(args.project)
49 program_config = io_utils.read_config(args.program)
Andrew Lambeceaec02020-02-11 14:16:41 -070050
Andrew Lambd43ddd72020-05-27 14:06:38 -060051 # Expect program checks in a 'checks' dir under the root of the program repo.
52 # Note that args.program points to the generated file, so use dirname + '..'
53 # to find the root of the program repo.
54 program_checks_dir = os.path.join(os.path.dirname(args.program), '../checks')
55
Andrew Lambc75a6392020-02-14 13:08:14 -070056 constraint_suite_directories = [
57 COMMON_CHECKS_PATH,
Andrew Lambd43ddd72020-05-27 14:06:38 -060058 program_checks_dir,
Andrew Lambc75a6392020-02-14 13:08:14 -070059 ]
60
61 constraint_suites = []
62 for directory in constraint_suite_directories:
63 constraint_suites.extend(
64 constraint_suite_discovery.discover_suites(directory))
65
66 for suite in constraint_suites:
67 suite.run_checks(
Andrew Lambf3491802020-05-29 11:41:47 -060068 program_config=program_config,
69 project_config=project_config,
70 factory_dir=args.factory_dir,
71 verbose=1,
72 )
Andrew Lambeceaec02020-02-11 14:16:41 -070073
74
75if __name__ == '__main__':
76 main()