Files
RedBear-OS/local/scripts/repair-cook.sh
T
kellito ae749ffb23 build: ship build-system hardening arc (5 of 10 improvements)
The v6.0 build-system hardening arc lands 5 of the 10 improvements
proposed in local/docs/BUILD-SYSTEM-IMPROVEMENTS.md. All scripts
have unit tests (62 -> 86, all pass in <1s) and the new 'lint-recipe'
Gitea Actions job runs on every PR.

Per-recipe audit & lint scripts (catch R1/R2 violations BEFORE cook):
  * audit-patch-idempotency.py  — verifies external patches in
    local/patches/ still apply against the upstream pinned rev.
    Caught 1 real bug on first run: libdrm/02-redox-dispatch.patch
    hunk at xf86drm.c:321 no longer matches libdrm-2.4.125.
  * audit-kf6-deps.py           — fetches upstream, scans for
    find_package(KF6Xxx REQUIRED), compares to recipe deps. Catches
    missing + dead dependencies in every kf6-* and qt* recipe.
  * classify-cook-failure.py    — 17-rule cook-failure classifier.
    10-30s diagnosis vs 5-10min manual. exit code is intentionally
    inverted (0=novel failure, 1=known fix) for CI signal.
  * lint-recipe.py              — 7-rule recipe lint: R1-NO-PATCH-FILE,
    R1-PATH-SOURCE, R2-INLINE-SED, R2-PATCHES-DIR-UNUSED,
    NO-LEGACY-MAKE, R1-LEGACY-APPLY-PATCHES, DEP-NOT-FOUND.
    1.1s for 171 recipes (down from 60s+ in v1 via recipe-index
    precomputation). Strict mode promotes warnings to errors.

Build-system convenience:
  * repair-cook.sh              — incremental-build optimizer.
    Equivalent to 'repo cook <pkg>' but with a fast-path that
    skips configure when CMakeCache.txt is newer than source AND
    external patches haven't changed. 30-60s vs 5-10min on KF6
    recipes. make repair.<pkg> / make clean-repair.<pkg> targets.
  * migrate-kf6-seds-to-patches.sh — migration skeleton for
    converting 56 inline 'sed -i' chains across the KF6 recipes
    to durable external patches in local/patches/<name>/.

Gitea Actions (host-execution, no Docker):
  * .gitea/workflows/build-system.yml — 8-job pipeline:
    unit-tests, lint-offline, lint-network (nightly),
    lint-recipe (NEW), lint-docs, build-mini, build-full,
    smoke (QEMU boot).
  * .gitea/RUNNER-SETUP.md — one-time Manjaro/Arch host setup.

Build script hardening:
  * build-redbear.sh            — when a low-level source (relibc,
    kernel, base, bootloader, installer) is newer than its pkgar,
    clean build/ and sysroot/ across all recipes too. Low-level
    package changes leave autotools packages (pcre2, gettext,
    libiconv, ...) with stale configure/libtool scripts referencing
    the old runtime, causing 'libtool version mismatch' and
    'not a valid libtool object' errors. Cleaning forces
    re-configuration; stage/ and source/ are preserved so the
    cookbook skips unchanged packages that don't use autotools.
  * Makefile                    — wire lint-cook-failure,
    lint-cook-failure-explain, lint-recipe, lint-recipe.%,
    lint-recipe.strict, lint-recipe.%.strict, repair.%,
    clean-repair.%, test-lint-scripts[-quiet]. Replace the
    legacy 'validate-patches' target with a deprecation notice
    pointing at validate-sources.

Documentation:
  * BUILD-SYSTEM-IMPROVEMENTS.md   — mark #2 and #5 DONE; full
    implementation notes; updated Make-targets table.
  * BUILD-SYSTEM-V6-HARDENING-POSTMORTEM.md (NEW) — 226-line durable
    record of the 8-session arc: 32 findings categorized, 5 P0
    audit-script bugs fixed, 6 over-broad multi-pattern rules
    discovered + fixed, test coverage 86/86 in <1s, 7/10
    improvements DONE.
  * SCRIPT-BEHAVIOR-MATRIX.md   — apply-patches.sh row marked
    LEGACY/ARCHIVED; build-redbear.sh row no longer claims to
    call it.
  * boot-logs/README.md (NEW)   — frozen-evidence policy:
    'do not edit' rule for REDBEAR-FULL-BOOT-*-RESULTS.md files.
  * libdrm/02-redox-dispatch.patch.README (NEW) — 8-step regen
    procedure for the broken hunk.

Cleanup:
  * local/cache/README.md deleted (1-line placeholder).
  * legacy 'make validate-patches' target removed.

Per build-system improvement #5: lint-recipe.py's first run on
the live tree surfaced 1 broken-patch reference (redbear-sessiond),
1 dangling cookbook_apply_patches call (tc), 19 sed -i calls in
sddm (warning — cookbook_apply_patches present, drop-x11.py
migration in progress), 4 sed -i calls in qt6-wayland-smoke
(uncovers the same bug class the libwayland fix prevented).
2026-06-12 13:37:39 +03:00

137 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# repair-cook.sh — incremental-build optimizer for `repo cook`
#
# Equivalent to `./target/release/repo cook <recipe>` but checks
# whether the existing build directory is still valid before
# re-running the full configure + build cycle. Saves 30-60 seconds
# per cook on incremental builds of CMake-based recipes.
#
# Triggers a "fast path" only when ALL of the following are true:
# 1. The recipe's build/ directory already exists.
# 2. The recipe's CMakeCache.txt exists in build/.
# 3. CMakeCache.txt is newer than every source file in source/.
# 4. The recipe's external patches (local/patches/<name>/) have
# not been modified since the last successful cook.
# 5. The user did NOT pass --clean-build (which forces a clean run).
#
# If any condition fails, falls through to a full `repo cook` run.
#
# Usage:
# ./local/scripts/repair-cook.sh <recipe-path>
# ./local/scripts/repair-cook.sh <recipe-path> --clean-build
# make repair.qtbase # via Makefile wrapper below
#
# Env vars:
# REPAIR_FORCE=1 skip the fast-path check, always full cook
# REPAIR_VERBOSE=1 print why fast-path was rejected
# REPAIR_DRY_RUN=1 print what would happen, don't execute
#
# This is build-system improvement #2 per local/docs/BUILD-SYSTEM-IMPROVEMENTS.md.
set -euo pipefail
REPO_BIN="${REPO_BIN:-$(cd "$(dirname "$0")/../.." && pwd)/target/release/repo}"
RECIPE="${1:?usage: $0 <recipe-path> [--clean-build]}"
shift
CLEAN_BUILD=0
for arg in "$@"; do
case "$arg" in
--clean-build) CLEAN_BUILD=1 ;;
esac
done
if [ "${REPAIR_FORCE:-0}" = "1" ]; then
CLEAN_BUILD=1
fi
# Resolve recipe to absolute path
RECIPE="$(cd "$(dirname "$RECIPE")" && pwd)/$(basename "$RECIPE")"
# Recipe's name (last path component of the dir)
RECIPE_NAME="$(basename "$RECIPE")"
# Build directory: discovered from the cookbook's actual convention.
# Per src/cook/cook_build.rs:357, the build dir is created at
# `<recipe>/target/<target>/build`. The target string comes from
# `redoxer::target()` (cross) or `redoxer::host_target()` (host).
# We probe the most common targets. The fast path requires
# CMakeCache.txt to exist inside build/ — that is the canonical
# signal that a prior cook completed configure.
cmake_cache=""
build_dir=""
for try_dir in "$RECIPE/target"/*/build/CMakeCache.txt; do
if [ -f "$try_dir" ]; then
cmake_cache="$try_dir"
build_dir="$(dirname "$cmake_cache")"
break
fi
done
verbose() {
[ "${REPAIR_VERBOSE:-0}" = "1" ] && echo "repair-cook: $*" >&2 || true
}
# ---------------------------------------------------------------------------
# Fast path: skip configure if existing build/ is still valid
# ---------------------------------------------------------------------------
if [ "$CLEAN_BUILD" = "0" ] && [ -n "$build_dir" ] && [ -f "$build_dir/CMakeCache.txt" ]; then
source_is_newer=0
if [ -d "$RECIPE/source" ]; then
# find -newer exits 0 if any file under source/ (excluding
# .git/ and target/) is newer than CMakeCache.txt
if [ -n "$(find "$RECIPE/source" \
-not -path '*/.git/*' \
-not -path '*/target/*' \
-newer "$build_dir/CMakeCache.txt" \
-print -quit 2>/dev/null)" ]; then
source_is_newer=1
fi
fi
# patches_dir is `<tmp>/local/patches/<name>/`, three levels up
# from RECIPE which is `<tmp>/local/recipes/<cat>/<name>/`
patches_dir="$RECIPE/../../../patches/$RECIPE_NAME"
patches_are_newer=0
if [ -d "$patches_dir" ]; then
if [ -n "$(find "$patches_dir" -name '[0-9]*.patch' \
-newer "$build_dir/CMakeCache.txt" \
-print -quit 2>/dev/null)" ]; then
patches_are_newer=1
fi
fi
if [ "$source_is_newer" = "0" ] && [ "$patches_are_newer" = "0" ]; then
verbose "fast path: $RECIPE_NAME — CMakeCache.txt is fresh, "\
"no source/ or patch changes since last cook"
if [ "${REPAIR_DRY_RUN:-0}" = "1" ]; then
echo "Would run: $REPO_BIN cook $RECIPE (fast path)"
exit 0
fi
# Fast path: re-package existing build/ artifacts into the
# per-recipe sysroot. We do NOT pass --clean-build, so the
# cookbook skips the configure + compile phases and just
# runs the install/stage/package pipeline. This saves 30-60
# seconds per cook on incremental builds of CMake recipes.
verbose "running: $REPO_BIN cook $RECIPE (fast path)"
exec "$REPO_BIN" cook "$RECIPE" "$@"
else
verbose "fast path rejected for $RECIPE_NAME: "\
"source_is_newer=$source_is_newer, "\
"patches_are_newer=$patches_are_newer"
fi
fi
# Slow path: full `repo cook` (configure + build + stage + package).
# Falls through when (a) no prior build/ exists, (b) --clean-build
# was passed, or (c) source/ or patches are newer than CMakeCache.txt.
if [ "${REPAIR_DRY_RUN:-0}" = "1" ]; then
echo "Would run: $REPO_BIN cook $RECIPE $@ (slow path)"
exit 0
fi
verbose "running: $REPO_BIN cook $RECIPE (slow path)"
exec "$REPO_BIN" cook "$RECIPE" "$@"