ae749ffb23
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).
290 lines
11 KiB
Bash
Executable File
290 lines
11 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
source "$SCRIPT_DIR/lib/relibc-surface.sh"
|
|
|
|
# Source .config for build settings, but NEVER auto-set REDBEAR_RELEASE.
|
|
# Release mode requires explicit REDBEAR_RELEASE= in the environment.
|
|
if [ -f "$PROJECT_ROOT/.config" ]; then
|
|
while IFS= read -r line; do
|
|
line="${line%%#*}"
|
|
line=$(echo "$line" | xargs)
|
|
[ -z "$line" ] && continue
|
|
if [[ "$line" == *"?="* ]]; then
|
|
key="${line%%\?=*}"
|
|
value="${line#*\?=}"
|
|
elif [[ "$line" == *"="* ]]; then
|
|
key="${line%%=*}"
|
|
value="${line#*=}"
|
|
else
|
|
continue
|
|
fi
|
|
key=$(echo "$key" | xargs)
|
|
value=$(echo "$value" | xargs)
|
|
[ -z "$key" ] && continue
|
|
# Skip REDBEAR_RELEASE — dev builds must not use release mode
|
|
[ "$key" = "REDBEAR_RELEASE" ] && continue
|
|
# Only set if not already set in environment
|
|
[ -n "${!key:-}" ] || export "$key=$value"
|
|
done < "$PROJECT_ROOT/.config"
|
|
fi
|
|
|
|
CONFIG="redbear-full"
|
|
JOBS="${JOBS:-$(nproc)}"
|
|
APPLY_PATCHES="${APPLY_PATCHES:-1}"
|
|
ALLOW_UPSTREAM=0
|
|
NO_CACHE=0
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [OPTIONS] [CONFIG]
|
|
|
|
Build a tracked Red Bear OS profile.
|
|
|
|
Options:
|
|
--upstream Allow Redox/upstream recipe source refresh during build
|
|
--no-cache Force clean rebuild, discarding cached packages
|
|
-h, --help Show this help
|
|
|
|
Configs:
|
|
redbear-full Desktop/graphics target (default)
|
|
redbear-mini Text-only console/recovery target
|
|
redbear-grub Text-only with GRUB boot manager
|
|
|
|
Environment:
|
|
REDBEAR_RELEASE If set, builds from immutable release archives.
|
|
Override to empty for development builds.
|
|
EOF
|
|
}
|
|
|
|
POSITIONAL=()
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--upstream)
|
|
ALLOW_UPSTREAM=1
|
|
;;
|
|
--no-cache)
|
|
NO_CACHE=1
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
-*)
|
|
echo "Unknown option: $1" >&2
|
|
usage >&2
|
|
exit 1
|
|
;;
|
|
*)
|
|
POSITIONAL+=("$1")
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [ ${#POSITIONAL[@]} -gt 1 ]; then
|
|
echo "ERROR: Too many positional arguments" >&2
|
|
usage >&2
|
|
exit 1
|
|
fi
|
|
|
|
[ ${#POSITIONAL[@]} -eq 1 ] && CONFIG="${POSITIONAL[0]}"
|
|
|
|
case "$CONFIG" in
|
|
redbear-full|redbear-mini|redbear-grub)
|
|
;;
|
|
*)
|
|
echo "ERROR: Unknown config '$CONFIG'" >&2
|
|
echo "Supported: redbear-full, redbear-mini, redbear-grub" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo "========================================"
|
|
echo " Red Bear OS Build System"
|
|
echo "========================================"
|
|
echo "Config: $CONFIG"
|
|
echo "Jobs: $JOBS"
|
|
echo "Apply patches: $APPLY_PATCHES"
|
|
echo "Upstream: $ALLOW_UPSTREAM"
|
|
echo "Root: ${PROJECT_ROOT##*/}"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
cd "$PROJECT_ROOT"
|
|
|
|
if [ -x "$PROJECT_ROOT/local/scripts/verify-overlay-integrity.sh" ] && [ -z "${REDBEAR_RELEASE:-}" ]; then
|
|
echo ">>> Skipping overlay repair (causes recipe symlink corruption)"
|
|
# "$PROJECT_ROOT/local/scripts/verify-overlay-integrity.sh" --repair || true
|
|
echo ""
|
|
fi
|
|
|
|
# Per AGENTS.md: local recipes ALWAYS supersede WIP.
|
|
# Any WIP directory that shadows a local/recipes/ package must be
|
|
# replaced with a symlink to the local version.
|
|
if [ -z "${REDBEAR_RELEASE:-}" ]; then
|
|
echo ">>> Enforcing local-over-WIP recipe policy..."
|
|
for local_recipe in "$PROJECT_ROOT"/local/recipes/*/*/; do
|
|
pkg=$(basename "$local_recipe")
|
|
[ ! -f "$local_recipe/recipe.toml" ] && continue
|
|
while IFS= read -r -d '' wip_dir; do
|
|
if [ ! -L "$wip_dir" ]; then
|
|
wip_rel=$(realpath --relative-to="$(dirname "$wip_dir")" "$local_recipe")
|
|
rm -rf "$wip_dir"
|
|
ln -sf "$wip_rel" "$wip_dir"
|
|
echo " WIP $pkg -> local ($wip_rel)"
|
|
fi
|
|
done < <(find "$PROJECT_ROOT"/recipes/wip -maxdepth 5 -name "$pkg" -type d -print0 2>/dev/null || true)
|
|
done
|
|
echo ""
|
|
fi
|
|
|
|
stash_nested_repo_if_dirty() {
|
|
local target_dir="$1"
|
|
local label="$2"
|
|
if [ -d "$target_dir/.git" ]; then
|
|
if ! git -C "$target_dir" diff --quiet || ! git -C "$target_dir" diff --cached --quiet || [ -n "$(git -C "$target_dir" ls-files --others --exclude-standard)" ]; then
|
|
echo ">>> Stashing dirty nested $label checkout before build..."
|
|
rm -f "$target_dir/.git/index.lock"
|
|
git -C "$target_dir" stash push --all -m "build-redbear-auto-stash" > /dev/null 2>&1 || true
|
|
fi
|
|
fi
|
|
}
|
|
|
|
stash_nested_repo_if_dirty "$PROJECT_ROOT/recipes/core/relibc/source" "relibc"
|
|
|
|
if [ "$APPLY_PATCHES" = "1" ] && [ -z "${REDBEAR_RELEASE:-}" ]; then
|
|
echo ">>> Patches are applied by 'repo fetch' via recipe.toml (atomic mechanism)"
|
|
echo ">>> Skipping direct patch application (was bypassing cookbook atomicity)"
|
|
echo ""
|
|
elif [ -n "${REDBEAR_RELEASE:-}" ]; then
|
|
echo ">>> Release mode: skipping patch application (patches pre-applied in archived sources)"
|
|
fi
|
|
|
|
if [ ! -f "target/release/repo" ]; then
|
|
echo ">>> Building cookbook binary..."
|
|
cargo build --release
|
|
fi
|
|
|
|
if [ "$CONFIG" = "redbear-full" ]; then
|
|
redbear_ensure_relibc_desktop_surface
|
|
fi
|
|
|
|
FW_AMD_DIR="$PROJECT_ROOT/local/firmware/amdgpu"
|
|
if [ "$CONFIG" = "redbear-full" ]; then
|
|
if [ -d "$FW_AMD_DIR" ] && [ -n "$(ls -A "$FW_AMD_DIR" 2>/dev/null)" ]; then
|
|
FW_COUNT=$(ls "$FW_AMD_DIR"/*.bin 2>/dev/null | wc -l)
|
|
echo ">>> Found $FW_COUNT AMD firmware blobs"
|
|
else
|
|
echo ">>> WARNING: No AMD firmware blobs found."
|
|
echo " Run: ./local/scripts/fetch-firmware.sh"
|
|
echo " GPU driver will NOT function without firmware."
|
|
fi
|
|
echo ""
|
|
fi
|
|
|
|
echo ">>> Building Red Bear OS with config: $CONFIG"
|
|
echo ">>> This may take 30-60 minutes on first build..."
|
|
|
|
# Stale-build prevention: if a low-level source repo has commits newer
|
|
# than its pkgar, delete that package's pkgar and target dir AND clean
|
|
# build/sysroot dirs across all recipes. Low-level packages (relibc,
|
|
# kernel, base) provide the C runtime and compiler support libs; when
|
|
# they change, autotools packages (pcre2, gettext, libiconv, etc.)
|
|
# retain stale configure/libtool scripts that reference the old runtime,
|
|
# causing "libtool version mismatch" and "not a valid libtool object"
|
|
# errors. Cleaning build/ and sysroot/ forces re-configuration while
|
|
# preserving stage/ and source/ so the cookbook can skip unchanged
|
|
# packages that don't use autotools.
|
|
if [ "$NO_CACHE" != "1" ]; then
|
|
STALE_DETECTED=0
|
|
for src in relibc kernel base bootloader installer; do
|
|
src_dir="$PROJECT_ROOT/local/sources/$src"
|
|
pkgar="$PROJECT_ROOT/repo/x86_64-unknown-redox/$src.pkgar"
|
|
if [ -d "$src_dir/.git" ] && [ -f "$pkgar" ]; then
|
|
src_commit=$(git -C "$src_dir" rev-parse HEAD 2>/dev/null || echo "")
|
|
pkgar_commit=$(python3 -c "
|
|
import tomllib
|
|
try:
|
|
with open('$pkgar'.replace('.pkgar','.toml'),'rb') as f:
|
|
d = tomllib.load(f)
|
|
print(d.get('commit_identifier',''))
|
|
except: pass
|
|
" 2>/dev/null || echo "")
|
|
if [ -n "$src_commit" ] && [ "$src_commit" != "$pkgar_commit" ] && [ -n "$pkgar_commit" ]; then
|
|
echo ">>> Stale $src detected (source newer than pkgar); invalidating..."
|
|
rm -f "$PROJECT_ROOT/repo/x86_64-unknown-redox/$src".*
|
|
find "$PROJECT_ROOT/recipes" -path "*/$src/target" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
STALE_DETECTED=1
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ "$STALE_DETECTED" = "1" ]; then
|
|
echo ">>> Cleaning stale build/sysroot dirs (low-level runtime changed)..."
|
|
find "$PROJECT_ROOT/recipes" "$PROJECT_ROOT/local/recipes" \
|
|
\( -path "*/target/x86_64-unknown-redox/build" \
|
|
-o -path "*/target/x86_64-unknown-redox/sysroot" \) \
|
|
-type d -exec rm -rf {} + 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
if [ "$NO_CACHE" = "1" ]; then
|
|
echo ">>> Cleaning repo and recipe caches for clean build..."
|
|
make repo_clean 2>/dev/null || true
|
|
rm -rf "$PROJECT_ROOT"/repo
|
|
find "$PROJECT_ROOT"/local/recipes -maxdepth 4 -name "target" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
find "$PROJECT_ROOT"/recipes -maxdepth 3 -name "target" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
fi
|
|
|
|
if [ -n "${REDBEAR_RELEASE:-}" ]; then
|
|
bash "$PROJECT_ROOT/local/scripts/build-release-mode.sh" --release="$REDBEAR_RELEASE" --config="$CONFIG" --extra-package=relibc
|
|
fi
|
|
|
|
bash "$PROJECT_ROOT/local/scripts/build-preflight.sh" --config="$CONFIG" ${REDBEAR_RELEASE:+--release="$REDBEAR_RELEASE"} --extra-package=relibc
|
|
|
|
# Pre-cook critical packages that may fail in the dependency chain.
|
|
# --with-package-deps resolves ALL transitive deps; pre-cooking ensures
|
|
# the repo has valid pkgars before make live processes the full graph.
|
|
# Only pre-cook the desktop chain for redbear-full; mini/grub don't need it.
|
|
# llvm21 is a Mesa (graphics) dep — only needed when the Mesa chain is in scope.
|
|
echo ">>> Pre-cooking critical packages..."
|
|
if [ "$CONFIG" = "redbear-full" ]; then
|
|
PRECOOK_PKGS="relibc icu llvm21 mesa libdrm libepoxy redox-drm lcms2 libdisplay-info libxcvt kwin sddm qtbase"
|
|
else
|
|
PRECOOK_PKGS="relibc icu"
|
|
fi
|
|
for pkg in $PRECOOK_PKGS; do
|
|
if [ ! -f "$PROJECT_ROOT/repo/x86_64-unknown-redox/$pkg.pkgar" ]; then
|
|
echo " cooking $pkg..."
|
|
"$PROJECT_ROOT/target/release/repo" cook "$pkg" 2>&1 | tail -1 || true
|
|
fi
|
|
done
|
|
|
|
if [ "${REDBEAR_ALLOW_UPSTREAM:-0}" = "1" ]; then
|
|
echo ">>> WARNING: Upstream fetch ENABLED (REDBEAR_ALLOW_UPSTREAM=1)"
|
|
REPO_OFFLINE=0 COOKBOOK_OFFLINE=false CI=1 make live "CONFIG_NAME=$CONFIG" "JOBS=$JOBS" 2>&1
|
|
elif [ -n "${REDBEAR_RELEASE:-}" ]; then
|
|
echo ">>> Release mode: building from immutable archives (offline)"
|
|
REPO_OFFLINE=1 COOKBOOK_OFFLINE=true CI=1 make live "CONFIG_NAME=$CONFIG" "JOBS=$JOBS" 2>&1
|
|
elif [ "$ALLOW_UPSTREAM" -eq 1 ]; then
|
|
echo ">>> Upstream recipe refresh enabled"
|
|
REPO_OFFLINE=0 COOKBOOK_OFFLINE=false CI=1 make live "CONFIG_NAME=$CONFIG" "JOBS=$JOBS" 2>&1
|
|
else
|
|
echo ">>> Upstream recipe refresh disabled (default: offline)"
|
|
REPO_OFFLINE=1 COOKBOOK_OFFLINE=true CI=1 make live "CONFIG_NAME=$CONFIG" "JOBS=$JOBS" 2>&1
|
|
fi
|
|
|
|
ARCH="${ARCH:-$(uname -m)}"
|
|
echo ""
|
|
echo "========================================"
|
|
echo " Build Complete!"
|
|
echo "========================================"
|
|
echo "ISO: build/$ARCH/$CONFIG.iso"
|
|
echo ""
|
|
echo "To run in QEMU:"
|
|
echo " make qemu QEMUFLAGS=\"-m 4G\""
|
|
ls -lh "$PROJECT_ROOT/build/$ARCH/$CONFIG.iso" 2>/dev/null
|