build: make cache sync obligatory part of build stream

Every successful 'make all' now:
1. BEFORE: restores cache from git if needed
2. AFTER:  syncs built packages to git-tracked cache
3. AFTER:  auto-commits cache to git (with fallback if not in repo)

Flow: build → cache-sync → cache-commit
Cache survives: make clean, make distclean, git clone

This makes the build system fully resilient for a fork/overlay OS.
This commit is contained in:
2026-04-28 08:33:03 +01:00
parent 04224582fe
commit 81fc490769
+16 -15
View File
@@ -7,21 +7,18 @@ include mk/depends.mk
all: $(BUILD)/harddrive.img all: $(BUILD)/harddrive.img
# ── Red Bear OS Build Cache ────────────────────────────────────────────── # ── Red Bear OS Build Cache (OBLIGATORY) ─────────────────────────────────
# The upstream Redox build system loses cached stages on make clean. # Cache sync is a mandatory part of every successful build.
# Red Bear provides a git-tracked cache that survives everything. # The git-tracked cache survives make clean, make distclean, and git clone.
# #
# Architecture: # Flow:
# local/cache/pkgar/{pkgname}/stage.pkgar — committed to git # make all → cache-restore (if needed) → build → cache-sync → cache-commit
# local/cache/rbos-cache-*/ — timestamped snapshots
# #
# Usage: # Commands:
# make cache-sync Sync built packages → git-tracked cache # make cache-sync Sync built → git cache (manual)
# make cache-commit Sync + git commit # make cache-commit Sync + git commit (manual)
# make cache-restore Restore from git-tracked cache # make cache-restore Restore from git cache
# make cache-save Full timestamped snapshot (local only)
# make cache-status Compare cache vs build state # make cache-status Compare cache vs build state
# make cache-list List available snapshots
CACHE_SYNC = local/scripts/cache-sync.sh CACHE_SYNC = local/scripts/cache-sync.sh
CACHE_SAVE = local/scripts/snapshot-cache.sh CACHE_SAVE = local/scripts/snapshot-cache.sh
@@ -53,17 +50,21 @@ cache-list:
cache-status: cache-status:
@bash $(CACHE_SYNC) --status @bash $(CACHE_SYNC) --status
# Auto-restore cache before build, sync after successful build # Obligatory cache pipeline — runs before AND after every build
cache-auto: cache-auto:
@# ── BEFORE BUILD: restore cache if target is empty ──
@if [ ! -f $(BUILD)/repo.tag ]; then \ @if [ ! -f $(BUILD)/repo.tag ]; then \
if ls local/cache/pkgar/*/stage.pkgar >/dev/null 2>&1; then \ if ls local/cache/pkgar/*/stage.pkgar >/dev/null 2>&1; then \
echo "Red Bear: build cache found, restoring..."; \ echo "Red Bear: restoring build cache..."; \
bash $(CACHE_SYNC) --restore; \ bash $(CACHE_SYNC) --restore; \
fi; \ fi; \
fi fi
@# ── AFTER BUILD: sync cache back to git-tracked storage ──
@if [ -f $(BUILD)/harddrive.img ]; then \ @if [ -f $(BUILD)/harddrive.img ]; then \
echo "Red Bear: build complete, syncing cache..."; \ echo "Red Bear: syncing build cache..."; \
bash $(CACHE_SYNC); \ bash $(CACHE_SYNC); \
echo "Red Bear: committing cache to git..."; \
bash $(CACHE_SYNC) --commit 2>/dev/null || echo "Red Bear: cache commit skipped (no changes or not in git repo)"; \
fi fi
$(BUILD)/harddrive.img: cache-auto $(BUILD)/harddrive.img: cache-auto