Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Leonardo Sandoval | 579c737 | 2020-10-23 15:23:32 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # Output to stdout the chosen run configuration fragments for a given run |
| 9 | # configuration. With -p, the script prints all fragments considered without |
| 10 | # validating whether it exists. |
| 11 | |
| 12 | import argparse |
| 13 | import os |
| 14 | import sys |
| 15 | |
| 16 | parser = argparse.ArgumentParser(description="Choose run configurations") |
| 17 | parser.add_argument("--print-only", "-p", action="store_true", default=False, |
| 18 | help="Print only; don't check for matching run configs.") |
| 19 | parser.add_argument("args", nargs=argparse.REMAINDER, help="Run configuration") |
| 20 | opts = parser.parse_args() |
| 21 | |
| 22 | if len(opts.args) != 1: |
| 23 | raise Exception("Exactly one argument expected") |
| 24 | |
Leonardo Sandoval | 0f7c772 | 2020-09-14 17:26:23 -0500 | [diff] [blame] | 25 | exit_code = 0 |
| 26 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 27 | # Obtain path to run_config directory |
| 28 | script_root = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 29 | run_config_dir = os.path.join(script_root, os.pardir, "run_config") |
| 30 | |
| 31 | arg = opts.args[0] |
| 32 | run_config = arg.split(":")[-1] |
| 33 | if not run_config: |
| 34 | raise Exception("Couldn't extract run config from " + arg) |
| 35 | |
| 36 | if run_config == "nil": |
Leonardo Sandoval | 0f7c772 | 2020-09-14 17:26:23 -0500 | [diff] [blame] | 37 | sys.exit(exit_code) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 38 | |
| 39 | fragments = run_config.split("-") |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 40 | |
Leonardo Sandoval | 0f7c772 | 2020-09-14 17:26:23 -0500 | [diff] [blame] | 41 | ignored_fragments = ['bmcov'] |
| 42 | not_prefixed_fragments = ['debug'] |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 43 | |
Leonardo Sandoval | 0f7c772 | 2020-09-14 17:26:23 -0500 | [diff] [blame] | 44 | for f in fragments[1:]: |
| 45 | if f in ignored_fragments: |
| 46 | # these fragments are ignored |
| 47 | continue |
| 48 | elif f in not_prefixed_fragments: |
| 49 | # these fragments are NOT prefixed by first fragment |
| 50 | fragment = f |
| 51 | else: |
| 52 | # for the rest of the cases, prefix first fragment |
| 53 | fragment = "-".join([fragments[0],f]) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 54 | |
Leonardo Sandoval | 0f7c772 | 2020-09-14 17:26:23 -0500 | [diff] [blame] | 55 | if opts.print_only: |
| 56 | print(fragment) |
| 57 | else: |
| 58 | # Output only if a matching run config exists |
| 59 | if os.path.isfile(os.path.join(run_config_dir, fragment)): |
| 60 | # Stop looking for generic once a specific fragment is found |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 61 | print(fragment) |
| 62 | else: |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 63 | print("warning: {}: no matches for fragment '{}'".format( |
| 64 | arg, fragment), file=sys.stderr) |
| 65 | exit_code = 1 |
Leonardo Sandoval | 0f7c772 | 2020-09-14 17:26:23 -0500 | [diff] [blame] | 66 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 67 | sys.exit(exit_code) |