From c64a242f19fbf061258a2bdf1fb2e74d22cd813f Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 29 Jan 2024 13:46:53 +0000 Subject: [PATCH] lisa._kmod: Make toolchain selection reproducible FIX Remove impact of set iteration order from the toolchain selection process. --- lisa/_kmod.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lisa/_kmod.py b/lisa/_kmod.py index d0e782b578..0edc13ca5f 100644 --- a/lisa/_kmod.py +++ b/lisa/_kmod.py @@ -1463,7 +1463,7 @@ def _resolve_toolchain(cls, abi, build_conf, target=None): env = cls._make_toolchain_env_from_conf(build_conf) def priority_to(cc): - def prio(_cc): + def prio(_cc, _cross_compile): prio = 0 if cc in _cc.name else 1 return (prio, prio == 0) return prio @@ -1490,7 +1490,7 @@ def version_key(version): abs(clang_version - version) ) - def cc_priority(cc): + def cc_priority(cc, cross_compile): def prio(cc): if 'clang' in cc.name: version = re.search(r'[0-9]+', cc.name) @@ -1550,7 +1550,7 @@ def prio(cc): # The format of "ccs" dict is: # (CC=, CROSS_COMPILE=): - ccs = { + ccs = [ *( (Path(f'clang-{i}'), cross_compile) # Cover for the next 10 years starting from 2021 @@ -1568,14 +1568,14 @@ def prio(cc): (Path('gcc'), cross_compile) for cross_compile in cross_compiles ), - } + ] if 'CC' in make_vars: _cc = _make_vars_cc(make_vars) - ccs = { + ccs = [ (_cc, cross_compile) for cross_compile in cross_compiles - } + ] if 'LLVM' in make_vars: llvm = make_vars['LLVM'] @@ -1583,16 +1583,16 @@ def prio(cc): llvm_version = llvm if llvm.startswith('-') else None if _cc.name == 'clang' and llvm_version: _cc = _cc.with_name(f'{_cc.name}{llvm_version}') - ccs = { + ccs = [ (_cc, cross_compile) for cross_compile in cross_compiles - } + ] # Give priority for the toolchain the kernel seem to have been compiled # with def key(item): (cc, cross_compile) = item - return cc_priority(cc) + return cc_priority(cc, cross_compile) ccs = sorted(ccs, key=key) @@ -1687,9 +1687,9 @@ def version_cmd(cc, cross_compile): if cross_compile is None: raise ValueError(f'Could not detect which CROSS_COMPILE value to use') - ideal_cc, _ = ccs[0] - cc_is_perfect = cc_priority(cc)[1] - if str(cc) != str(ideal_cc) or not cc_is_perfect: + ideal_cc, ideal_cross_compile = ccs[0] + cc_is_perfect = cc_priority(cc, cross_compile)[1] + if str(cc) != str(ideal_cc) or ideal_cross_compile != cross_compile or not cc_is_perfect: logger.warning(f'Could not find ideal CC={ideal_cc} but found CC={cc} instead. Results may vary from working fine to crashing the kernel') return (cc, cross_compile, cc_key)