Skip to content

Commit

Permalink
lisa._kmod: Make toolchain selection reproducible
Browse files Browse the repository at this point in the history
FIX

Remove impact of set iteration order from the toolchain selection
process.
  • Loading branch information
douglas-raillard-arm committed Jan 29, 2024
1 parent f4c897a commit c64a242
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lisa/_kmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -1550,7 +1550,7 @@ def prio(cc):

# The format of "ccs" dict is:
# (CC=, CROSS_COMPILE=): <binary name>
ccs = {
ccs = [
*(
(Path(f'clang-{i}'), cross_compile)
# Cover for the next 10 years starting from 2021
Expand All @@ -1568,31 +1568,31 @@ 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']
_cc = _make_vars_cc(make_vars, 'clang')
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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c64a242

Please sign in to comment.