@@ -128,11 +128,15 @@ jobs:
128128
129129 echo "Collecting artifact hashes..."
130130
131- # Collect all hashes
131+ # Collect glint hashes
132132 GLINT_AMD64_SHA=$(compute_sha256 "glint-${GLINT_VERSION}-amd64")
133133 GLINT_ARM64_SHA=$(compute_sha256 "glint-${GLINT_VERSION}-arm64")
134+
135+ # Collect sanitizer hashes
134136 MSAN_SHA=$(compute_sha256 "compile/msan-llvm${LLVM_VERSION}-x86_64.tar.xz")
135137 TSAN_SHA=$(compute_sha256 "compile/tsan-llvm${LLVM_VERSION}-x86_64.tar.xz")
138+
139+ # Collect sysroot hashes
136140 SYSROOT_2_31_BASE_AMD64=$(compute_sha256 "sysroot-glibc2.31-amd64.tar.xz")
137141 SYSROOT_2_31_BASE_ARM64=$(compute_sha256 "sysroot-glibc2.31-arm64.tar.xz")
138142 SYSROOT_2_31_13_AMD64=$(compute_sha256 "sysroot-glibc2.31-libstdc++13-amd64.tar.xz")
@@ -142,63 +146,70 @@ jobs:
142146 SYSROOT_2_28_13_AMD64=$(compute_sha256 "sysroot-glibc2.28-libstdc++13-amd64.tar.xz")
143147 SYSROOT_2_28_13_ARM64=$(compute_sha256 "sysroot-glibc2.28-libstdc++13-arm64.tar.xz")
144148
145- echo "Updating ${VERSIONS_FILE}..."
146-
147- # Update msan/tsan hashes
148- sed -i "s/\"msan_libs_sha256\": \"[^\"]*\"/\"msan_libs_sha256\": \"${MSAN_SHA}\"/" "${VERSIONS_FILE}"
149- sed -i "s/\"tsan_libs_sha256\": \"[^\"]*\"/\"tsan_libs_sha256\": \"${TSAN_SHA}\"/" "${VERSIONS_FILE}"
150-
151- # Update glint hashes - using a state machine approach with awk
152- awk -v amd64="${GLINT_AMD64_SHA}" -v arm64="${GLINT_ARM64_SHA}" '
153- /\"glint_sha256\":/ { in_glint=1 }
154- in_glint && /\"amd64\":/ { sub(/\"[a-f0-9]{64}\"/, "\"" amd64 "\"") }
155- in_glint && /\"arm64\":/ { sub(/\"[a-f0-9]{64}\"/, "\"" arm64 "\"") }
156- in_glint && /^[[:space:]]*\},/ { in_glint=0 }
157- { print }
158- ' "${VERSIONS_FILE}" > "${VERSIONS_FILE}.tmp" && mv "${VERSIONS_FILE}.tmp" "${VERSIONS_FILE}"
159-
160- # Update sysroot hashes - using awk with state tracking for nested structures
161- awk -v glibc_2_31_base_amd64="${SYSROOT_2_31_BASE_AMD64}" \
162- -v glibc_2_31_base_arm64="${SYSROOT_2_31_BASE_ARM64}" \
163- -v glibc_2_31_13_amd64="${SYSROOT_2_31_13_AMD64}" \
164- -v glibc_2_31_13_arm64="${SYSROOT_2_31_13_ARM64}" \
165- -v glibc_2_28_base_amd64="${SYSROOT_2_28_BASE_AMD64}" \
166- -v glibc_2_28_base_arm64="${SYSROOT_2_28_BASE_ARM64}" \
167- -v glibc_2_28_13_amd64="${SYSROOT_2_28_13_AMD64}" \
168- -v glibc_2_28_13_arm64="${SYSROOT_2_28_13_ARM64}" '
169- BEGIN { glibc=""; variant="" }
170- /\"sysroot_hashes\":/ { in_sysroot=1 }
171- in_sysroot && /\"2\.31\":/ { glibc="2.31" }
172- in_sysroot && /\"2\.28\":/ { glibc="2.28" }
173- in_sysroot && glibc != "" && /\"base\":/ { variant="base" }
174- in_sysroot && glibc != "" && /\"13\":/ { variant="13" }
175- in_sysroot && glibc != "" && variant != "" && /\"amd64\":/ {
176- if (glibc == "2.31" && variant == "base") {
177- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_31_base_amd64 "\"")
178- } else if (glibc == "2.31" && variant == "13") {
179- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_31_13_amd64 "\"")
180- } else if (glibc == "2.28" && variant == "base") {
181- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_28_base_amd64 "\"")
182- } else if (glibc == "2.28" && variant == "13") {
183- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_28_13_amd64 "\"")
184- }
185- }
186- in_sysroot && glibc != "" && variant != "" && /\"arm64\":/ {
187- if (glibc == "2.31" && variant == "base") {
188- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_31_base_arm64 "\"")
189- } else if (glibc == "2.31" && variant == "13") {
190- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_31_13_arm64 "\"")
191- } else if (glibc == "2.28" && variant == "base") {
192- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_28_base_arm64 "\"")
193- } else if (glibc == "2.28" && variant == "13") {
194- sub(/\"[a-f0-9]{64}\"/, "\"" glibc_2_28_13_arm64 "\"")
195- }
149+ echo "Updating ${VERSIONS_FILE} using bazel/sha/replace.sh..."
150+
151+ # Build replacement pairs: old_hash:new_hash
152+ # Extract current hashes from versions.bzl and create replacement pairs
153+ REPLACEMENTS=()
154+
155+ # Get current msan hash and replace it
156+ CURRENT_MSAN=$(grep '"msan_libs_sha256":' "${VERSIONS_FILE}" | sed -n 's/.*"\([a-f0-9]\{64\}\)".*/\1/p')
157+ if [[ -n "${CURRENT_MSAN}" && "${CURRENT_MSAN}" != "${MSAN_SHA}" ]]; then
158+ REPLACEMENTS+=("${CURRENT_MSAN}:${MSAN_SHA}")
159+ fi
160+
161+ # Get current tsan hash and replace it
162+ CURRENT_TSAN=$(grep '"tsan_libs_sha256":' "${VERSIONS_FILE}" | sed -n 's/.*"\([a-f0-9]\{64\}\)".*/\1/p')
163+ if [[ -n "${CURRENT_TSAN}" && "${CURRENT_TSAN}" != "${TSAN_SHA}" ]]; then
164+ REPLACEMENTS+=("${CURRENT_TSAN}:${TSAN_SHA}")
165+ fi
166+
167+ # Get current glint hashes from the nested glint_sha256 dict
168+ CURRENT_GLINT_AMD64=$(sed -n '/"glint_sha256":/,/},/p' "${VERSIONS_FILE}" | grep '"amd64":' | sed -n 's/.*"\([a-f0-9]\{64\}\)".*/\1/p')
169+ if [[ -n "${CURRENT_GLINT_AMD64}" && "${CURRENT_GLINT_AMD64}" != "${GLINT_AMD64_SHA}" ]]; then
170+ REPLACEMENTS+=("${CURRENT_GLINT_AMD64}:${GLINT_AMD64_SHA}")
171+ fi
172+
173+ CURRENT_GLINT_ARM64=$(sed -n '/"glint_sha256":/,/},/p' "${VERSIONS_FILE}" | grep '"arm64":' | sed -n 's/.*"\([a-f0-9]\{64\}\)".*/\1/p')
174+ if [[ -n "${CURRENT_GLINT_ARM64}" && "${CURRENT_GLINT_ARM64}" != "${GLINT_ARM64_SHA}" ]]; then
175+ REPLACEMENTS+=("${CURRENT_GLINT_ARM64}:${GLINT_ARM64_SHA}")
176+ fi
177+
178+ # Get current sysroot hashes from the nested sysroot_hashes dict
179+ # Extract the entire sysroot_hashes section and parse it
180+ SYSROOT_SECTION=$(sed -n '/"sysroot_hashes":/,/^[[:space:]]*},$/p' "${VERSIONS_FILE}")
181+
182+ # Helper to extract hash from sysroot section for specific glibc/variant/arch
183+ get_sysroot_hash() {
184+ local glibc=$1
185+ local variant=$2
186+ local arch=$3
187+ echo "$SYSROOT_SECTION" | sed -n "/${glibc}/,/^[[:space:]]*},/p" | \
188+ sed -n "/${variant}/,/^[[:space:]]*},/p" | \
189+ grep "\"${arch}\":" | sed -n 's/.*"\([a-f0-9]\{64\}\)".*/\1/p'
196190 }
197- /^[[:space:]]*\},/ && variant != "" { variant="" }
198- /^[[:space:]]*\},/ && glibc != "" && variant == "" { glibc="" }
199- /^[[:space:]]*\}$/ && in_sysroot { in_sysroot=0 }
200- { print }
201- ' "${VERSIONS_FILE}" > "${VERSIONS_FILE}.tmp" && mv "${VERSIONS_FILE}.tmp" "${VERSIONS_FILE}"
191+
192+ # Add sysroot hash replacements
193+ for glibc in "2.31" "2.28"; do
194+ for variant in "base" "13"; do
195+ for arch in "amd64" "arm64"; do
196+ VAR_NAME="SYSROOT_${glibc//./_}_${variant/base/BASE}_${arch^^}"
197+ NEW_HASH="${!VAR_NAME}"
198+ CURRENT_HASH=$(get_sysroot_hash "$glibc" "\"$variant\"" "$arch")
199+ if [[ -n "${CURRENT_HASH}" && "${CURRENT_HASH}" != "${NEW_HASH}" ]]; then
200+ REPLACEMENTS+=("${CURRENT_HASH}:${NEW_HASH}")
201+ fi
202+ done
203+ done
204+ done
205+
206+ # Use bazel/sha/replace.sh to perform all replacements
207+ if [[ ${#REPLACEMENTS[@]} -gt 0 ]]; then
208+ echo "Performing ${#REPLACEMENTS[@]} hash replacements..."
209+ bash bazel/sha/replace.sh . "${REPLACEMENTS[@]}"
210+ else
211+ echo "No hash updates needed - all hashes are already current"
212+ fi
202213
203214 echo "Successfully updated ${VERSIONS_FILE}"
204215
0 commit comments