Skip to content

Commit 31f997b

Browse files
committed
Simplify path handling
Signed-off-by: Dave Rodgman <[email protected]>
1 parent ffecec1 commit 31f997b

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

tools/bin/mtest

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ if gitresult.returncode != 0 or not os.path.exists(f"{ROOT}/include/mbedtls"):
100100
else:
101101
# found root, construct the other paths
102102
os.chdir(ROOT)
103-
TEST_DIR = ROOT + "/tests"
103+
TEST_DIR = "tests"
104104

105105
uname = subprocess.run(["uname", "-m"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode("utf-8").strip()
106106
if uname in ["aarch64", "arm64"]:
@@ -110,10 +110,10 @@ else:
110110
else:
111111
NATIVE_TARGET = uname
112112

113-
CONFIG_FILE = ROOT + "/include/mbedtls/mbedtls_config.h"
113+
CONFIG_FILE = "include/mbedtls/mbedtls_config.h"
114114
if not os.path.exists(CONFIG_FILE):
115115
# config file not found, assume we are on 2.x
116-
CONFIG_FILE = ROOT + "/include/mbedtls/config.h"
116+
CONFIG_FILE = "include/mbedtls/config.h"
117117

118118
BACKUP_SUFFIX = ".mtest_backup"
119119

@@ -276,7 +276,7 @@ def toolchain(target, exit_on_failure=True):
276276
# basic CFLAGS setup
277277
# target_c_flags are options generated by mtest, which may get overridden by the user (and dropped from the resulting set of flags)
278278

279-
target_c_flags = [f"-I{ROOT}/include"] + COMPILER_FLAGS.get(target.compiler_family, [])
279+
target_c_flags = [f"-Iinclude"] + COMPILER_FLAGS.get(target.compiler_family, [])
280280

281281
if target.compiler_family != "iar":
282282
# IAR defaults to C99 and doesn't have an option for it to be explicitly specified
@@ -494,9 +494,9 @@ def git_history_contains(hash):
494494

495495
def get_crypto_config_file():
496496
# parse the config file and identify the crypto config file location
497-
cmd = ["clang", "-dM", "-E", f"-I{ROOT}/include", f"{ROOT}/include/mbedtls/mbedtls_config.h"]
497+
cmd = ["clang", "-dM", "-E", f"-Iinclude", f"include/mbedtls/mbedtls_config.h"]
498498
output, _ = subrun(cmd, silent=True)
499-
path = f"{ROOT}/include/psa/crypto_config.h"
499+
path = f"include/psa/crypto_config.h"
500500
for l in output.splitlines():
501501
if l.startswith("#define MBEDTLS_PSA_CRYPTO_CONFIG_FILE "):
502502
path = l.split(" ")[-1][1:-1]
@@ -516,14 +516,14 @@ def set_config_option(action, option, crypto_config_path, silent=True):
516516
if not silent:
517517
log(f"scripts/config.py -f {crypto_config_path} {action} {option} {'1' if action == 'set' else ''}")
518518
if action == "set":
519-
output, success = subrun([f"{ROOT}/scripts/config.py"] + force + ["--file", crypto_config_path, action, option, "1"], silent=True, ignore_failure=True)
519+
output, success = subrun([f"scripts/config.py"] + force + ["--file", crypto_config_path, action, option, "1"], silent=True, ignore_failure=True)
520520
else:
521-
output, success = subrun([f"{ROOT}/scripts/config.py"] + force + ["--file", crypto_config_path, action, option], silent=True, ignore_failure=True)
521+
output, success = subrun([f"scripts/config.py"] + force + ["--file", crypto_config_path, action, option], silent=True, ignore_failure=True)
522522
else:
523523
backup_config_options(CONFIG_FILE)
524524
if not silent:
525525
log(f"scripts/config.py {action} {option}")
526-
output, success = subrun([f"{ROOT}/scripts/config.py"] + force + [action, option], silent=True, ignore_failure=True)
526+
output, success = subrun([f"scripts/config.py"] + force + [action, option], silent=True, ignore_failure=True)
527527
if success != 0:
528528
error(output)
529529

@@ -554,24 +554,24 @@ def configure_options(target):
554554
# identify replacement config files, if any
555555
if COPY_TFM_CONFIG in options:
556556
config_is_tfm = True
557-
if os.path.exists(f"{ROOT}/configs/config-tfm.h"):
558-
new_config = f"{ROOT}/configs/config-tfm.h"
557+
if os.path.exists("configs/config-tfm.h"):
558+
new_config = "configs/config-tfm.h"
559559
else:
560-
new_config = f"{ROOT}/configs/tfm_mbedcrypto_config_profile_medium.h"
561-
new_crypto_config = f"{ROOT}/configs/crypto_config_profile_medium.h"
560+
new_config = "configs/tfm_mbedcrypto_config_profile_medium.h"
561+
new_crypto_config = "configs/crypto_config_profile_medium.h"
562562
# for looking at old checkouts where these configs were not in the tree, fetch from
563563
# date they were first created instead
564564
for config in [new_config, new_crypto_config]:
565565
if not os.path.exists(config):
566566
hash = "2f1ae5a86ebd67faa50c3983b4567656c2234674"
567-
log(f"git show {hash}:configs/{config} > configs/{config}")
568-
output, _ = subrun(["git", "show", f"{hash}:configs/{config}"], silent=True)
569-
with open(f"{ROOT}/configs/{config}", 'w') as f:
567+
log(f"git show {hash}:{config} > {config}")
568+
output, _ = subrun(["git", "show", f"{hash}:{config}"], silent=True)
569+
with open(f"{config}", 'w') as f:
570570
f.write(output)
571571

572572
for config in header_options:
573573
# a config file - overwrite existing config file
574-
path = config if os.path.exists(config) else f"{ROOT}/configs/{config}"
574+
path = config if os.path.exists(config) else f"configs/{config}"
575575
if path.split("/")[-1].startswith("crypto_config_"):
576576
new_crypto_config = path
577577
else:
@@ -582,12 +582,12 @@ def configure_options(target):
582582
# backup and overwrite the config files
583583
if new_config is not None:
584584
backup_config_options(CONFIG_FILE)
585-
log(f"cp {new_config[len(ROOT) + 1:]} {CONFIG_FILE[len(ROOT) + 1:]}")
585+
log(f"cp {new_config} {CONFIG_FILE}")
586586
shutil.copy(new_config, CONFIG_FILE)
587587
if new_crypto_config is not None:
588588
crypto_config_file = get_crypto_config_file()
589589
backup_config_options(crypto_config_file)
590-
log(f"cp {new_crypto_config[len(ROOT) + 1:]} {crypto_config_file[len(ROOT) + 1:]}")
590+
log(f"cp {new_crypto_config} {crypto_config_file}")
591591
shutil.copy(new_crypto_config, crypto_config_file)
592592

593593
# apply bulk config.py settings to main config file
@@ -596,7 +596,7 @@ def configure_options(target):
596596
# a configuration recognised by config.py, e.g. "baremetal"
597597
backup_config_options(CONFIG_FILE)
598598
log(f"scripts/config.py {config}")
599-
subrun([f"{ROOT}/scripts/config.py", config], silent=True)
599+
subrun([f"scripts/config.py", config], silent=True)
600600

601601
if config_is_tfm:
602602
# adjust options for older versions of the config files to allow TF-M config to build
@@ -643,7 +643,7 @@ def disassemble(target):
643643
# run objdump -d to disassemble
644644
objdump = toolchain(target)["OBJDUMP"]
645645
objfiles = ["library/libmbedcrypto.a", "library/libmbedtls.a", "library/libmbedx509.a" ] + args.build_targets
646-
objfiles = [f"{ROOT}/{f}" for f in objfiles if os.path.exists(f"{ROOT}/{f}")]
646+
objfiles = [f for f in objfiles if os.path.exists(f)]
647647
result = []
648648
for fn in args.disassemble:
649649
if fn is None:
@@ -775,7 +775,7 @@ def run(target, tests, quiet=False):
775775
for t in tests:
776776
log(f"running {t} on {target.arch_isa}")
777777
if target.is_native:
778-
output, _ = subrun(f"{TEST_DIR}/" + t, test_dir=True, silent=quiet)
778+
output, _ = subrun(f"./{t}", test_dir=True, silent=quiet)
779779
else:
780780
qemu_exe = toolchain_exes(target)["qemu"]
781781
output, _ = subrun([qemu_exe, t], test_dir=True, silent=quiet)
@@ -792,7 +792,7 @@ def get_supported_configs():
792792
s = [x[:24].split()[0] for x in s if len(s) >= 24 and len(x[:24].strip()) > 0]
793793
s = [x for x in s if x not in ["get", "set", "set-all", "unset", "unset-all"] and "," not in x]
794794
# get the list of config files
795-
config_files = [x for x in os.listdir(f'{ROOT}/configs') if x.endswith(".h")]
795+
config_files = [x for x in os.listdir(f'configs') if x.endswith(".h")]
796796
return s + config_files
797797

798798

@@ -931,7 +931,7 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
931931
args.rest = [x for x in args.rest if not x.startswith("CFLAGS=") and not x.startswith("LDFLAGS=") and not x.startswith("CC=")]
932932

933933
# find any things in programs to build
934-
all_programs = [x[len(ROOT)+1:-2] for x in glob.glob(f'{ROOT}/programs/**/*.c', recursive=True)]
934+
all_programs = [x[:-2] for x in glob.glob(f'programs/**/*.c', recursive=True)]
935935
args.build_targets = []
936936
for x in list(args.rest):
937937
found = [p for p in all_programs if p.endswith("/" + x)]

0 commit comments

Comments
 (0)