blob: 6a1e4ae43d910bf14edda09aede360b565a1d2e1 [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#!/usr/bin/env python3
2#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05003# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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
12import argparse
13import os
14import sys
15
16parser = argparse.ArgumentParser(description="Choose run configurations")
17parser.add_argument("--print-only", "-p", action="store_true", default=False,
18 help="Print only; don't check for matching run configs.")
19parser.add_argument("args", nargs=argparse.REMAINDER, help="Run configuration")
20opts = parser.parse_args()
21
22if len(opts.args) != 1:
23 raise Exception("Exactly one argument expected")
24
Leonardo Sandoval0f7c7722020-09-14 17:26:23 -050025exit_code = 0
26
Fathi Boudra422bf772019-12-02 11:10:16 +020027# Obtain path to run_config directory
28script_root = os.path.dirname(os.path.abspath(sys.argv[0]))
29run_config_dir = os.path.join(script_root, os.pardir, "run_config")
30
31arg = opts.args[0]
32run_config = arg.split(":")[-1]
33if not run_config:
34 raise Exception("Couldn't extract run config from " + arg)
35
36if run_config == "nil":
Leonardo Sandoval0f7c7722020-09-14 17:26:23 -050037 sys.exit(exit_code)
Fathi Boudra422bf772019-12-02 11:10:16 +020038
39fragments = run_config.split("-")
Fathi Boudra422bf772019-12-02 11:10:16 +020040
Leonardo Sandoval0f7c7722020-09-14 17:26:23 -050041ignored_fragments = ['bmcov']
42not_prefixed_fragments = ['debug']
Fathi Boudra422bf772019-12-02 11:10:16 +020043
Leonardo Sandoval0f7c7722020-09-14 17:26:23 -050044for 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 Boudra422bf772019-12-02 11:10:16 +020054
Leonardo Sandoval0f7c7722020-09-14 17:26:23 -050055 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 Boudra422bf772019-12-02 11:10:16 +020061 print(fragment)
62 else:
Fathi Boudra422bf772019-12-02 11:10:16 +020063 print("warning: {}: no matches for fragment '{}'".format(
64 arg, fragment), file=sys.stderr)
65 exit_code = 1
Leonardo Sandoval0f7c7722020-09-14 17:26:23 -050066
Fathi Boudra422bf772019-12-02 11:10:16 +020067sys.exit(exit_code)