diff --git a/.gitignore b/.gitignore index a882a3cb..1f61271f 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,8 @@ TASK_COMPLETION_SUMMARY.md __pycache__/ extra.img: 1073741824 bytes extra.img +local/cache/pkgar/ + +# Red Bear git-tracked build cache (survives make clean) +!local/cache/pkgar/ +!local/cache/pkgar/** diff --git a/Makefile b/Makefile index 16c61e5a..401b8f36 100644 --- a/Makefile +++ b/Makefile @@ -9,41 +9,63 @@ all: $(BUILD)/harddrive.img # ── Red Bear OS Build Cache ────────────────────────────────────────────── # The upstream Redox build system loses cached stages on make clean. -# Red Bear provides snapshot/restore so the build can recover quickly. -# Essential package caches are tracked in git under local/cache/essential/. +# Red Bear provides a git-tracked cache that survives everything. +# +# Architecture: +# local/cache/pkgar/{pkgname}/stage.pkgar — committed to git +# local/cache/rbos-cache-*/ — timestamped snapshots # # Usage: -# make cache-save Save full cache snapshot -# make cache-save-essential Save only essential (boot) packages -# make cache-restore Auto-restore latest cache before build -# make cache-verify Check cache integrity +# make cache-sync Sync built packages → git-tracked cache +# make cache-commit Sync + git commit +# make cache-restore Restore from git-tracked cache +# make cache-save Full timestamped snapshot (local only) +# make cache-status Compare cache vs build state +# make cache-list List available snapshots -CACHE_SCRIPT = local/scripts/snapshot-cache.sh -RESTORE_SCRIPT = local/scripts/restore-cache.sh +CACHE_SYNC = local/scripts/cache-sync.sh +CACHE_SAVE = local/scripts/snapshot-cache.sh +CACHE_RESTORE = local/scripts/restore-cache.sh -cache-save: - @bash $(CACHE_SCRIPT) +cache-sync: + @bash $(CACHE_SYNC) -cache-save-essential: - @bash $(CACHE_SCRIPT) --essential +cache-commit: + @bash $(CACHE_SYNC) --commit cache-restore: - @bash $(RESTORE_SCRIPT) + @echo "Red Bear: restoring from git-tracked cache..." + @bash $(CACHE_SYNC) --restore + @bash $(CACHE_RESTORE) 2>/dev/null || true + +cache-save: + @bash $(CACHE_SAVE) + +cache-save-essential: + @bash $(CACHE_SAVE) --essential cache-verify: - @bash $(RESTORE_SCRIPT) --verify + @bash $(CACHE_RESTORE) --verify cache-list: - @bash $(CACHE_SCRIPT) --list + @bash $(CACHE_SAVE) --list -# Auto-restore cache if available (runs before all builds) +cache-status: + @bash $(CACHE_SYNC) --status + +# Auto-restore cache before build, sync after successful build cache-auto: - @if [ -d local/cache ] && ls local/cache/rbos-cache-* >/dev/null 2>&1; then \ - echo "Red Bear: restoring build cache..."; \ - bash $(RESTORE_SCRIPT); \ + @if [ ! -f $(BUILD)/repo.tag ]; then \ + if ls local/cache/pkgar/*/stage.pkgar >/dev/null 2>&1; then \ + echo "Red Bear: build cache found, restoring..."; \ + bash $(CACHE_SYNC) --restore; \ + fi; \ + fi + @if [ -f $(BUILD)/harddrive.img ]; then \ + echo "Red Bear: build complete, syncing cache..."; \ + bash $(CACHE_SYNC); \ fi -# Ensure cache is restored before build $(BUILD)/harddrive.img: cache-auto live: diff --git a/local/cache/.gitignore b/local/cache/.gitignore deleted file mode 100644 index 07f8b449..00000000 --- a/local/cache/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -* -!essential/ -!.gitignore -!.gitkeep diff --git a/local/cache/README.md b/local/cache/README.md new file mode 100644 index 00000000..92220932 --- /dev/null +++ b/local/cache/README.md @@ -0,0 +1 @@ +# Red Bear git-tracked cache — survives make clean and git clone diff --git a/local/cache/pkgar/.gitkeep b/local/cache/pkgar/.gitkeep new file mode 100644 index 00000000..7233025e --- /dev/null +++ b/local/cache/pkgar/.gitkeep @@ -0,0 +1 @@ +# Red Bear package caches — committed to git diff --git a/local/cache/pkgar/base-initfs/auto_deps.toml b/local/cache/pkgar/base-initfs/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/base-initfs/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/base-initfs/stage.pkgar b/local/cache/pkgar/base-initfs/stage.pkgar new file mode 100644 index 00000000..9008da94 Binary files /dev/null and b/local/cache/pkgar/base-initfs/stage.pkgar differ diff --git a/local/cache/pkgar/base/auto_deps.toml b/local/cache/pkgar/base/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/base/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/base/stage.pkgar b/local/cache/pkgar/base/stage.pkgar new file mode 100644 index 00000000..00c8d442 Binary files /dev/null and b/local/cache/pkgar/base/stage.pkgar differ diff --git a/local/cache/pkgar/bash/auto_deps.toml b/local/cache/pkgar/bash/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/bash/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/bash/stage.pkgar b/local/cache/pkgar/bash/stage.pkgar new file mode 100644 index 00000000..5274273a Binary files /dev/null and b/local/cache/pkgar/bash/stage.pkgar differ diff --git a/local/cache/pkgar/bootloader/auto_deps.toml b/local/cache/pkgar/bootloader/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/bootloader/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/bootloader/stage.pkgar b/local/cache/pkgar/bootloader/stage.pkgar new file mode 100644 index 00000000..5ed27e02 Binary files /dev/null and b/local/cache/pkgar/bootloader/stage.pkgar differ diff --git a/local/cache/pkgar/bottom/auto_deps.toml b/local/cache/pkgar/bottom/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/bottom/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/bottom/stage.pkgar b/local/cache/pkgar/bottom/stage.pkgar new file mode 100644 index 00000000..0c1846fc Binary files /dev/null and b/local/cache/pkgar/bottom/stage.pkgar differ diff --git a/local/cache/pkgar/ca-certificates/auto_deps.toml b/local/cache/pkgar/ca-certificates/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/ca-certificates/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/ca-certificates/stage.pkgar b/local/cache/pkgar/ca-certificates/stage.pkgar new file mode 100644 index 00000000..f622827f Binary files /dev/null and b/local/cache/pkgar/ca-certificates/stage.pkgar differ diff --git a/local/cache/pkgar/coreutils/auto_deps.toml b/local/cache/pkgar/coreutils/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/coreutils/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/coreutils/stage.pkgar b/local/cache/pkgar/coreutils/stage.pkgar new file mode 100644 index 00000000..c13f2144 Binary files /dev/null and b/local/cache/pkgar/coreutils/stage.pkgar differ diff --git a/local/cache/pkgar/installer/auto_deps.toml b/local/cache/pkgar/installer/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/installer/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/installer/stage.pkgar b/local/cache/pkgar/installer/stage.pkgar new file mode 100644 index 00000000..c9ca138f Binary files /dev/null and b/local/cache/pkgar/installer/stage.pkgar differ diff --git a/local/cache/pkgar/ion/auto_deps.toml b/local/cache/pkgar/ion/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/ion/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/ion/stage.pkgar b/local/cache/pkgar/ion/stage.pkgar new file mode 100644 index 00000000..a8609f3e Binary files /dev/null and b/local/cache/pkgar/ion/stage.pkgar differ diff --git a/local/cache/pkgar/ncurses/auto_deps.toml b/local/cache/pkgar/ncurses/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/ncurses/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/ncurses/stage.pkgar b/local/cache/pkgar/ncurses/stage.pkgar new file mode 100644 index 00000000..4abc7f0c Binary files /dev/null and b/local/cache/pkgar/ncurses/stage.pkgar differ diff --git a/local/cache/pkgar/ncursesw/auto_deps.toml b/local/cache/pkgar/ncursesw/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/ncursesw/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/ncursesw/stage.pkgar b/local/cache/pkgar/ncursesw/stage.pkgar new file mode 100644 index 00000000..4ba353b3 Binary files /dev/null and b/local/cache/pkgar/ncursesw/stage.pkgar differ diff --git a/local/cache/pkgar/nghttp2/auto_deps.toml b/local/cache/pkgar/nghttp2/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/nghttp2/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/nghttp2/stage.pkgar b/local/cache/pkgar/nghttp2/stage.pkgar new file mode 100644 index 00000000..f59b6edf Binary files /dev/null and b/local/cache/pkgar/nghttp2/stage.pkgar differ diff --git a/local/cache/pkgar/readline/auto_deps.toml b/local/cache/pkgar/readline/auto_deps.toml new file mode 100644 index 00000000..b8a3f351 --- /dev/null +++ b/local/cache/pkgar/readline/auto_deps.toml @@ -0,0 +1 @@ +packages = ["ncursesw"] diff --git a/local/cache/pkgar/readline/stage.pkgar b/local/cache/pkgar/readline/stage.pkgar new file mode 100644 index 00000000..99a2ddec Binary files /dev/null and b/local/cache/pkgar/readline/stage.pkgar differ diff --git a/local/cache/pkgar/redoxfs/auto_deps.toml b/local/cache/pkgar/redoxfs/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/redoxfs/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/redoxfs/stage.pkgar b/local/cache/pkgar/redoxfs/stage.pkgar new file mode 100644 index 00000000..5653a713 Binary files /dev/null and b/local/cache/pkgar/redoxfs/stage.pkgar differ diff --git a/local/cache/pkgar/termcap/auto_deps.toml b/local/cache/pkgar/termcap/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/termcap/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/termcap/stage.pkgar b/local/cache/pkgar/termcap/stage.pkgar new file mode 100644 index 00000000..5f0fe4bb Binary files /dev/null and b/local/cache/pkgar/termcap/stage.pkgar differ diff --git a/local/cache/pkgar/zlib/auto_deps.toml b/local/cache/pkgar/zlib/auto_deps.toml new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/pkgar/zlib/auto_deps.toml @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/pkgar/zlib/stage.pkgar b/local/cache/pkgar/zlib/stage.pkgar new file mode 100644 index 00000000..7f3af4a4 Binary files /dev/null and b/local/cache/pkgar/zlib/stage.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/base-initfs.deps b/local/cache/rbos-cache-20260428-080713/base-initfs.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/base-initfs.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/base-initfs.pkgar b/local/cache/rbos-cache-20260428-080713/base-initfs.pkgar new file mode 100644 index 00000000..9008da94 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/base-initfs.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/base.deps b/local/cache/rbos-cache-20260428-080713/base.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/base.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/base.pkgar b/local/cache/rbos-cache-20260428-080713/base.pkgar new file mode 100644 index 00000000..00c8d442 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/base.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/bash.deps b/local/cache/rbos-cache-20260428-080713/bash.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/bash.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/bash.pkgar b/local/cache/rbos-cache-20260428-080713/bash.pkgar new file mode 100644 index 00000000..5274273a Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/bash.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/bootloader.deps b/local/cache/rbos-cache-20260428-080713/bootloader.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/bootloader.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/bootloader.pkgar b/local/cache/rbos-cache-20260428-080713/bootloader.pkgar new file mode 100644 index 00000000..5ed27e02 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/bootloader.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/bottom.deps b/local/cache/rbos-cache-20260428-080713/bottom.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/bottom.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/bottom.pkgar b/local/cache/rbos-cache-20260428-080713/bottom.pkgar new file mode 100644 index 00000000..0c1846fc Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/bottom.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/ca-certificates.deps b/local/cache/rbos-cache-20260428-080713/ca-certificates.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/ca-certificates.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/ca-certificates.pkgar b/local/cache/rbos-cache-20260428-080713/ca-certificates.pkgar new file mode 100644 index 00000000..f622827f Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/ca-certificates.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/coreutils.deps b/local/cache/rbos-cache-20260428-080713/coreutils.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/coreutils.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/coreutils.pkgar b/local/cache/rbos-cache-20260428-080713/coreutils.pkgar new file mode 100644 index 00000000..c13f2144 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/coreutils.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/installer.deps b/local/cache/rbos-cache-20260428-080713/installer.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/installer.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/installer.pkgar b/local/cache/rbos-cache-20260428-080713/installer.pkgar new file mode 100644 index 00000000..c9ca138f Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/installer.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/ion.deps b/local/cache/rbos-cache-20260428-080713/ion.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/ion.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/ion.pkgar b/local/cache/rbos-cache-20260428-080713/ion.pkgar new file mode 100644 index 00000000..a8609f3e Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/ion.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/manifest.toml b/local/cache/rbos-cache-20260428-080713/manifest.toml new file mode 100644 index 00000000..bfab158c --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/manifest.toml @@ -0,0 +1,6 @@ +[snapshot] +name = "rbos-cache-20260428-080713" +timestamp = "20260428-080713" +mode = "--full" +packages = 16 +total_size = 129468786 diff --git a/local/cache/rbos-cache-20260428-080713/ncurses.deps b/local/cache/rbos-cache-20260428-080713/ncurses.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/ncurses.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/ncurses.pkgar b/local/cache/rbos-cache-20260428-080713/ncurses.pkgar new file mode 100644 index 00000000..4abc7f0c Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/ncurses.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/ncursesw.deps b/local/cache/rbos-cache-20260428-080713/ncursesw.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/ncursesw.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/ncursesw.pkgar b/local/cache/rbos-cache-20260428-080713/ncursesw.pkgar new file mode 100644 index 00000000..4ba353b3 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/ncursesw.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/nghttp2.deps b/local/cache/rbos-cache-20260428-080713/nghttp2.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/nghttp2.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/nghttp2.pkgar b/local/cache/rbos-cache-20260428-080713/nghttp2.pkgar new file mode 100644 index 00000000..f59b6edf Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/nghttp2.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/readline.deps b/local/cache/rbos-cache-20260428-080713/readline.deps new file mode 100644 index 00000000..b8a3f351 --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/readline.deps @@ -0,0 +1 @@ +packages = ["ncursesw"] diff --git a/local/cache/rbos-cache-20260428-080713/readline.pkgar b/local/cache/rbos-cache-20260428-080713/readline.pkgar new file mode 100644 index 00000000..99a2ddec Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/readline.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/redoxfs.deps b/local/cache/rbos-cache-20260428-080713/redoxfs.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/redoxfs.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/redoxfs.pkgar b/local/cache/rbos-cache-20260428-080713/redoxfs.pkgar new file mode 100644 index 00000000..5653a713 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/redoxfs.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/termcap.deps b/local/cache/rbos-cache-20260428-080713/termcap.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/termcap.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/termcap.pkgar b/local/cache/rbos-cache-20260428-080713/termcap.pkgar new file mode 100644 index 00000000..5f0fe4bb Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/termcap.pkgar differ diff --git a/local/cache/rbos-cache-20260428-080713/zlib.deps b/local/cache/rbos-cache-20260428-080713/zlib.deps new file mode 100644 index 00000000..1fc07aab --- /dev/null +++ b/local/cache/rbos-cache-20260428-080713/zlib.deps @@ -0,0 +1 @@ +packages = [] diff --git a/local/cache/rbos-cache-20260428-080713/zlib.pkgar b/local/cache/rbos-cache-20260428-080713/zlib.pkgar new file mode 100644 index 00000000..7f3af4a4 Binary files /dev/null and b/local/cache/rbos-cache-20260428-080713/zlib.pkgar differ diff --git a/local/scripts/cache-sync.sh b/local/scripts/cache-sync.sh new file mode 100755 index 00000000..df4ae62f --- /dev/null +++ b/local/scripts/cache-sync.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash +# Red Bear OS — Git-Tracked Build Cache +# Automatically syncs recipe stage.pkgar files to local/cache/pkgar/ +# and commits them to git so the cache survives make clean AND git clone. +# +# The cache is organized as: local/cache/pkgar/{pkgname}/stage.pkgar +# This keeps individual files small enough for git (<100MB each). +# +# Usage: +# ./local/scripts/cache-sync.sh # Sync all built packages to cache +# ./local/scripts/cache-sync.sh --commit # Sync + git commit +# ./local/scripts/cache-sync.sh --restore # Restore cache to recipe targets +# ./local/scripts/cache-sync.sh --status # Show cache vs build state + +set -euo pipefail +cd "$(dirname "$0")/../.." + +CACHE_ROOT="local/cache/pkgar" +mkdir -p "${CACHE_ROOT}" + +MODE="${1:-}" + +if [ "$MODE" = "--status" ]; then + echo "=== Red Bear Cache Status ===" + cached=0; stale=0; missing=0 + for pkgar in "${CACHE_ROOT}"/*/stage.pkgar; do + [ -f "$pkgar" ] || continue + pkg=$(basename "$(dirname "$pkgar")") + recipe_dir=$(find recipes -maxdepth 3 -name "$pkg" -type d 2>/dev/null | head -1) + if [ -z "$recipe_dir" ]; then + echo " ORPHAN $pkg (no recipe)" + stale=$((stale + 1)) + continue + fi + target="${recipe_dir}/target/x86_64-unknown-redox/stage.pkgar" + if [ -f "$target" ]; then + if [ "$pkgar" -nt "$target" ]; then + echo " STALE $pkg (cache newer than build)" + stale=$((stale + 1)) + else + echo " SYNCED $pkg" + cached=$((cached + 1)) + fi + else + echo " CACHED $pkg (no build)" + cached=$((cached + 1)) + fi + done + # Check built but not cached + while IFS= read -r target; do + pkg=$(echo "$target" | sed 's|recipes/[^/]*/[^/]*/||; s|/target/.*||') + if [ ! -f "${CACHE_ROOT}/${pkg}/stage.pkgar" ]; then + size=$(stat -c%s "$target" 2>/dev/null || echo 0) + echo " UNCACHED $pkg ($(numfmt --to=iec $size 2>/dev/null || echo ${size}B))" + missing=$((missing + 1)) + fi + done < <(find recipes -name "stage.pkgar" -path "*/target/x86_64-unknown-redox/*" 2>/dev/null | head -100) + echo "" + echo "Synced: $cached Stale: $stale Uncached: $missing" + exit 0 +fi + +if [ "$MODE" = "--restore" ]; then + echo "=== Restoring Cache to Recipes ===" + count=0 + for pkgar in "${CACHE_ROOT}"/*/stage.pkgar; do + [ -f "$pkgar" ] || continue + pkg=$(basename "$(dirname "$pkgar")") + recipe_dir=$(find recipes -maxdepth 4 -name "$pkg" -type d 2>/dev/null | head -1) + if [ -z "$recipe_dir" ]; then continue; fi + target="${recipe_dir}/target/x86_64-unknown-redox/stage.pkgar" + if [ ! -f "$target" ] || [ "$pkgar" -nt "$target" ]; then + mkdir -p "$(dirname "$target")" + cp "$pkgar" "$target" + count=$((count + 1)) + fi + done + echo "Restored $count packages" + exit 0 +fi + +# Default: --sync mode +echo "=== Syncing Build Cache ===" +synced=0 +while IFS= read -r target; do + pkg_path="${target%/target/x86_64-unknown-redox/stage.pkgar}" + # Extract package name: recipes/{category}/{name}/target/... → {name} + pkg=$(basename "$pkg_path") + [ -z "$pkg" ] && continue + + cache_dir="${CACHE_ROOT}/${pkg}" + cache_file="${cache_dir}/stage.pkgar" + + # Only copy if build is newer + if [ -f "$cache_file" ] && [ ! "$target" -nt "$cache_file" ]; then + continue + fi + + mkdir -p "$cache_dir" + cp "$target" "$cache_file" + + # Also save auto_deps + deps_file="${pkg_path}/target/x86_64-unknown-redox/auto_deps.toml" + if [ -f "$deps_file" ]; then + cp "$deps_file" "${cache_dir}/auto_deps.toml" + fi + + synced=$((synced + 1)) +done < <(find recipes -name "stage.pkgar" -path "*/target/x86_64-unknown-redox/*" 2>/dev/null) + +echo "Synced $synced packages to ${CACHE_ROOT}/" + +if [ "$MODE" = "--commit" ] && [ $synced -gt 0 ]; then + echo "" + echo "=== Committing Cache ===" + git add "${CACHE_ROOT}/" + + # Only commit if there are staged changes + if git diff --cached --quiet; then + echo "No cache changes to commit" + else + commit_msg="cache: $(date +%Y-%m-%d) — ${synced} packages" + git commit -m "$commit_msg" + echo "Committed: $commit_msg" + echo "To push: git push" + fi +fi