94 lines
2.4 KiB
Bash
Executable File
94 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
project_root="$(git -C "$script_dir" rev-parse --show-toplevel)"
|
|
|
|
if [[ -t 1 ]]; then
|
|
c_reset=$'\033[0m'
|
|
c_red=$'\033[31m'
|
|
c_green=$'\033[32m'
|
|
c_yellow=$'\033[33m'
|
|
else
|
|
c_reset=''
|
|
c_red=''
|
|
c_green=''
|
|
c_yellow=''
|
|
fi
|
|
|
|
ok() { printf '%sOK%s: %s\n' "$c_green" "$c_reset" "$*"; }
|
|
warn() { printf '%sWARN%s: %s\n' "$c_yellow" "$c_reset" "$*"; }
|
|
fail() { printf '%sFAIL%s: %s\n' "$c_red" "$c_reset" "$*" >&2; }
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [--doctor] [--simulate-staleness]
|
|
|
|
Check whether the compiled prefix libc.a is older than local fork commits.
|
|
|
|
Options:
|
|
--doctor Print verbose component/file diagnostics
|
|
--simulate-staleness Force an artificial stale-prefix result for testing
|
|
-h, --help Show this help
|
|
EOF
|
|
}
|
|
|
|
doctor=0
|
|
simulate_staleness=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--doctor) doctor=1 ;;
|
|
--simulate-staleness) simulate_staleness=1 ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) fail "unknown argument: $arg"; usage; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
latest_prefix_mtime() {
|
|
local latest=0 path ts
|
|
for path in \
|
|
"$project_root/prefix/x86_64-unknown-redox/sysroot/x86_64-unknown-redox/lib/libc.a" \
|
|
"$project_root/prefix/x86_64-unknown-redox/relibc-install/x86_64-unknown-redox/lib/libc.a"; do
|
|
if [[ -e "$path" ]]; then
|
|
ts=$(stat -c %Y "$path")
|
|
(( ts > latest )) && latest=$ts
|
|
fi
|
|
done
|
|
printf '%s' "$latest"
|
|
}
|
|
|
|
fork_mtime() {
|
|
local path="$1"
|
|
git -C "$project_root" log -1 --format=%ct -- "$path" 2>/dev/null || printf '0'
|
|
}
|
|
|
|
components=(relibc kernel base)
|
|
stale=0
|
|
prefix_ts="$(latest_prefix_mtime)"
|
|
|
|
if (( simulate_staleness )); then
|
|
prefix_ts=0
|
|
fi
|
|
|
|
for component in "${components[@]}"; do
|
|
path="local/sources/$component"
|
|
fork_ts="$(fork_mtime "$path")"
|
|
delta=$((fork_ts - prefix_ts))
|
|
if (( doctor )); then
|
|
printf '%s: fork=%s prefix=%s delta=%s\n' "$path" "$fork_ts" "$prefix_ts" "$delta"
|
|
fi
|
|
if (( fork_ts > prefix_ts )); then
|
|
printf '%s: lib too old by %s seconds\n' "$component" "$delta"
|
|
stale=1
|
|
else
|
|
ok "$component: prefix fresh"
|
|
fi
|
|
done
|
|
|
|
if (( stale )); then
|
|
warn "prefix is stale — run ./local/scripts/build-redbear.sh --upstream"
|
|
exit 1
|
|
fi
|
|
|
|
ok "prefix is fresh"
|