Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 1 | #!/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 | |
| 7 | import argparse |
| 8 | import os |
| 9 | |
Andrew Lamb | c75a639 | 2020-02-14 13:08:14 -0700 | [diff] [blame] | 10 | from checker import constraint_suite_discovery |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 11 | from checker import io_utils |
| 12 | |
Andrew Lamb | c75a639 | 2020-02-14 13:08:14 -0700 | [diff] [blame] | 13 | COMMON_CHECKS_PATH = os.path.join( |
| 14 | os.path.dirname(__file__), 'checker', 'common_checks') |
| 15 | |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 16 | |
| 17 | def argument_parser(): |
| 18 | parser = argparse.ArgumentParser(description=__doc__) |
| 19 | parser.add_argument( |
| 20 | '--program', |
| 21 | required=True, |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 22 | 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 Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 26 | metavar='PATH') |
| 27 | parser.add_argument( |
| 28 | '--project', |
| 29 | required=True, |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 30 | 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 Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 34 | metavar='PATH') |
| 35 | return parser |
| 36 | |
| 37 | |
| 38 | def main(): |
| 39 | parser = argument_parser() |
| 40 | args = parser.parse_args() |
| 41 | |
Andrew Lamb | 9328c40 | 2020-03-05 12:57:59 -0700 | [diff] [blame] | 42 | project_config = io_utils.read_config(args.project) |
| 43 | program_config = io_utils.read_config(args.program) |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 44 | |
Andrew Lamb | c75a639 | 2020-02-14 13:08:14 -0700 | [diff] [blame] | 45 | constraint_suite_directories = [ |
| 46 | COMMON_CHECKS_PATH, |
| 47 | os.path.join(args.program, 'checks'), |
Andrew Lamb | c75a639 | 2020-02-14 13:08:14 -0700 | [diff] [blame] | 48 | ] |
| 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 Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 58 | |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | main() |