Files
cnc_wams/wasm-port/tools/verify_hal_component_source_sync.sh
2026-07-10 21:26:42 -04:00

57 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
UPSTREAM_DIR="$ROOT_DIR/../linuxcnc"
VENDOR_DIR="$ROOT_DIR/vendor/linuxcnc"
SOURCE_MANIFEST="$ROOT_DIR/tools/source-manifest.txt"
TASK_HAL_MANIFEST="$ROOT_DIR/tools/task-hal-source-manifest.txt"
BASELINE_FILE="$ROOT_DIR/tools/upstream-baseline.txt"
declare -A EXPECTED_SHA256=(
[and2]="29f02d1342bae24d138bbb1387b006b97f592967b8688ccb1c6c0af451cae419"
[or2]="c27663ce45f9562d7a5dc1b542da50ec2cc60802ef591ee729222002083a3c08"
[not]="9fd9522627db9926d037dc0c116badce7dc880f190c6f8b85c690cbb8b638332"
[mux2]="b75e3eeb74297d09d13052e812de53a38613ea8287522c371cc2fdaf76be3284"
[scale]="d6830d74fd3462c7b7285a9e0b37cbcd2c53d2243007a198e3f19bfed9817f4f"
)
components=(and2 or2 not mux2 scale)
fail() {
printf 'hal component source sync error: %s\n' "$1" >&2
exit 1
}
for required_file in "$SOURCE_MANIFEST" "$TASK_HAL_MANIFEST" "$BASELINE_FILE"; do
[[ -f "$required_file" ]] || fail "missing required file: $required_file"
done
expected_commit="$(tr -d '[:space:]' < "$BASELINE_FILE")"
actual_commit="$(git -C "$UPSTREAM_DIR" rev-parse HEAD)"
[[ -n "$expected_commit" ]] || fail "empty upstream baseline"
[[ "$actual_commit" == "$expected_commit" ]] || fail "upstream commit does not match tools/upstream-baseline.txt"
for component in "${components[@]}"; do
source_rel="src/hal/components/$component.comp"
upstream_file="$UPSTREAM_DIR/$source_rel"
vendor_file="$VENDOR_DIR/$source_rel"
grep -Fqx "$source_rel" "$SOURCE_MANIFEST" || fail "$source_rel missing from source-manifest.txt"
grep -Fqx "$source_rel" "$TASK_HAL_MANIFEST" || fail "$source_rel missing from task-hal-source-manifest.txt"
[[ -f "$upstream_file" ]] || fail "missing upstream source: $source_rel"
[[ -f "$vendor_file" ]] || fail "missing vendored source: $source_rel"
cmp -s "$upstream_file" "$vendor_file" || fail "vendored source differs from upstream: $source_rel"
upstream_sha256="$(sha256sum "$upstream_file" | awk '{print $1}')"
vendor_sha256="$(sha256sum "$vendor_file" | awk '{print $1}')"
[[ "$upstream_sha256" == "${EXPECTED_SHA256[$component]}" ]] || fail "locked source hash changed: $source_rel"
[[ "$vendor_sha256" == "${EXPECTED_SHA256[$component]}" ]] || fail "vendored source hash changed: $source_rel"
printf 'hal_component_source=%s sha256=%s vendor_match=1\n' "$component" "$vendor_sha256"
done
printf 'hal_component_upstream_commit=%s\n' "$actual_commit"
printf 'hal_component_source_count=%s\n' "${#components[@]}"
printf 'hal_component_source_sync=ok\n'