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, |
| 22 | help=('Path to the root of the program repo' |
| 23 | ' e.g. .../chromiumos/src/program/program1'), |
| 24 | metavar='PATH') |
| 25 | parser.add_argument( |
| 26 | '--project', |
| 27 | required=True, |
| 28 | help=('Path to the root of the project repo' |
| 29 | ' e.g. .../chromiumos/src/project/program1/project1'), |
| 30 | metavar='PATH') |
| 31 | return parser |
| 32 | |
| 33 | |
| 34 | def main(): |
| 35 | parser = argument_parser() |
| 36 | args = parser.parse_args() |
| 37 | |
| 38 | project_config = io_utils.read_repo_config(args.project) |
| 39 | program_config = io_utils.read_repo_config(args.program) |
| 40 | |
Andrew Lamb | c75a639 | 2020-02-14 13:08:14 -0700 | [diff] [blame] | 41 | constraint_suite_directories = [ |
| 42 | COMMON_CHECKS_PATH, |
| 43 | os.path.join(args.program, 'checks'), |
Andrew Lamb | c75a639 | 2020-02-14 13:08:14 -0700 | [diff] [blame] | 44 | ] |
| 45 | |
| 46 | constraint_suites = [] |
| 47 | for directory in constraint_suite_directories: |
| 48 | constraint_suites.extend( |
| 49 | constraint_suite_discovery.discover_suites(directory)) |
| 50 | |
| 51 | for suite in constraint_suites: |
| 52 | suite.run_checks( |
| 53 | program_config=program_config, project_config=project_config, verbose=1) |
Andrew Lamb | eceaec0 | 2020-02-11 14:16:41 -0700 | [diff] [blame] | 54 | |
| 55 | |
| 56 | if __name__ == '__main__': |
| 57 | main() |