Skip to content

Commit 9e251e8

Browse files
iavclaude
authored andcommitted
extension: kernel-version-toolchain for compiler in artifact version
Add opt-in extension that includes gcc/clang major.minor version in the kernel artifact version string for cache invalidation when the toolchain changes. Enable with ENABLE_EXTENSIONS="kernel-version-toolchain". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent baa0fdb commit 9e251e8

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Add compiler (gcc/clang) identifier to kernel artifact version string.
2+
# This ensures cache invalidation when the toolchain changes.
3+
# Enable with: ENABLE_EXTENSIONS="kernel-version-toolchain"
4+
5+
function artifact_kernel_version_parts__add_toolchain() {
6+
# Determine compiler binary
7+
declare kernel_compiler_bin="${KERNEL_COMPILER}gcc"
8+
if [[ "${KERNEL_COMPILER}" == "clang" ]]; then
9+
kernel_compiler_bin="clang"
10+
fi
11+
12+
# Get compiler version (major.minor only)
13+
declare toolchain_id="unknown"
14+
if command -v "${kernel_compiler_bin}" &> /dev/null; then
15+
declare full_version
16+
full_version="$(${kernel_compiler_bin} -dumpfullversion -dumpversion 2>/dev/null || echo "")"
17+
if [[ -n "${full_version}" ]]; then
18+
# Extract major.minor, drop patch version
19+
declare short_version
20+
short_version="$(echo "${full_version}" | cut -d'.' -f1-2)"
21+
# Build identifier: gcc13.3 or clang18.1
22+
if [[ "${KERNEL_COMPILER}" == "clang" ]]; then
23+
toolchain_id="clang${short_version}"
24+
else
25+
toolchain_id="gcc${short_version}"
26+
fi
27+
fi
28+
fi
29+
30+
display_alert "Extension: ${EXTENSION}: Adding toolchain to kernel version" "${toolchain_id}" "debug"
31+
32+
# Add to version parts
33+
artifact_version_parts["_T"]="${toolchain_id}"
34+
artifact_version_part_order+=("0085-_T")
35+
}

lib/functions/artifacts/artifact-kernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function artifact_kernel_prepare_version() {
131131
# tac reverses order so last becomes first, then sort -uk keeps first occurrence of each key.
132132
declare -a kernel_config_modifying_hashes_reduced=()
133133
mapfile -t kernel_config_modifying_hashes_reduced < <(
134-
printf '%s\n' "${kernel_config_modifying_hashes[@]}" | tac | LC_ALL=C sort -t '=' -uk 1,1
134+
printf '%s\n' "${kernel_config_modifying_hashes[@]}" | tac | LC_ALL=C sort -s -t '=' -uk 1,1
135135
)
136136
kernel_config_modification_hash="$(printf '%s\n' "${kernel_config_modifying_hashes_reduced[@]}" | sha256sum | cut -d' ' -f1)"
137137
kernel_config_modification_hash="${kernel_config_modification_hash:0:16}" # "long hash"

0 commit comments

Comments
 (0)