Files
RedBear-OS/mk/disk.mk
T
vasilito c2f5bb09fc feat: build-system hardening (validate gate, cache safeguards, status sync)
Phase 1 remediation of the build-system assessment:

- Makefile: wire 'validate' target into build/live/reimage flows; surface
  lint-config and init-service validators as a first-class gate.
- mk/disk.mk: add 'validate' target running lint-config, init-service
  validator, and file-ownership validator; suppress noisy unmount warnings
  that masked real failures.
- mk/redbear.mk: add source-fingerprint tracking so integrate-redbear.sh
  re-runs when local/recipes, local/Assets, or local/firmware change.
- src/cook/cook_build.rs: atomic dep_hashes.toml write (tmp + rename) to
  prevent torn-write cache corruption; binary-store restore now checks
  dep_hashes before silent restore; fix production bug in
  collect_files_recursive that silently dropped subdirectories whose
  name matched an exclude pattern.
- src/cook/fetch.rs, src/cook/fetch_repo.rs: harden atomic patch
  application and protected-recipe gating.
- AGENTS.md, local/AGENTS.md, local/docs/COLLISION-DETECTION-STATUS.md:
  sync collision-detection status to 'implemented (Phase 15.0)' now that
  CollisionTracker is wired across all four installer layers
  (installer submodule pointer tracked separately in 13cc6fb0c3).

Verified: cargo check (0 errors), cargo test --lib (35/35 passed),
cargo clippy (0 new warnings vs baseline), make -n validate, make -n live.
2026-07-18 16:30:23 +09:00

146 lines
5.2 KiB
Makefile

# Configuration file with the commands configuration of the Red Bear OS image
$(BUILD)/harddrive.img: $(FSTOOLS) $(REPO_TAG)
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
mkdir -p $(BUILD)
-$(FUMOUNT) $(MOUNT_DIR) 2>/dev/null || true
-$(FUMOUNT) /tmp/redox_installer 2>/dev/null || true
rm -rf $@ $@.partial $(MOUNT_DIR)
FILESYSTEM_SIZE=$(FILESYSTEM_SIZE) && \
if [ -z "$$FILESYSTEM_SIZE" ] ; then \
FILESYSTEM_SIZE=$(shell $(INSTALLER) --filesystem-size -c $(FILESYSTEM_CONFIG)); \
fi && \
truncate -s "$$FILESYSTEM_SIZE"m $@.partial
umask 002 && $(INSTALLER) $(INSTALLER_OPTS) --no-mount -c $(FILESYSTEM_CONFIG) $@.partial
mv $@.partial $@
endif
$(LIVE_IMG): $(FSTOOLS) $(REPO_TAG) sources
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
mkdir -p $(LIVE_BUILD)
rm -rf $@ $@.partial
$(FUMOUNT) /tmp/redox_installer 2>/dev/null || echo "Warning: failed to unmount /tmp/redox_installer (may not have been mounted)"
FILESYSTEM_SIZE=$(FILESYSTEM_SIZE) && \
if [ -z "$$FILESYSTEM_SIZE" ] ; then \
FILESYSTEM_SIZE=$(shell $(INSTALLER) --filesystem-size -c $(FILESYSTEM_CONFIG)); \
fi && \
truncate -s "$$FILESYSTEM_SIZE"m $@.partial
umask 002 && $(INSTALLER) $(INSTALLER_OPTS) --no-mount -c $(FILESYSTEM_CONFIG) --write-bootloader="$(LIVE_BOOTLOADER)" --live $@.partial
mv $@.partial $@
endif
$(LIVE_ISO): $(LIVE_IMG) redbear.ipxe
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
mkdir -p $(LIVE_BUILD)
rm -rf $@ $@.partial
cp "$(LIVE_IMG)" $@.partial
mv $@.partial $@
cp redbear.ipxe $(LIVE_IPXE)
endif
$(BUILD)/filesystem.img: $(FSTOOLS) $(REPO_TAG)
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
mkdir -p $(BUILD)
$(FUMOUNT) $(MOUNT_DIR) 2>/dev/null || echo "Warning: failed to unmount $(MOUNT_DIR) (may not have been mounted)"
rm -rf $@ $@.partial $(MOUNT_DIR)
$(FUMOUNT) /tmp/redox_installer 2>/dev/null || echo "Warning: failed to unmount /tmp/redox_installer (may not have been mounted)"
FILESYSTEM_SIZE=$(FILESYSTEM_SIZE) && \
if [ -z "$$FILESYSTEM_SIZE" ] ; then \
FILESYSTEM_SIZE=$(shell $(INSTALLER) --filesystem-size -c $(FILESYSTEM_CONFIG)); \
fi && \
truncate -s "$$FILESYSTEM_SIZE"m $@.partial
$(REDOXFS_MKFS) $(REDOXFS_MKFS_FLAGS) $@.partial
mkdir -p $(MOUNT_DIR)
$(REDOXFS) $@.partial $(MOUNT_DIR)
sleep 1
pgrep redoxfs
umask 002 && $(INSTALLER) $(INSTALLER_OPTS) -c $(FILESYSTEM_CONFIG) $(MOUNT_DIR)
sync
$(FUMOUNT) $(MOUNT_DIR) 2>/dev/null || echo "Warning: failed to unmount $(MOUNT_DIR) after install"
rm -rf $(MOUNT_DIR)
mv $@.partial $@
endif
mount: $(FSTOOLS) FORCE
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
@mkdir -p $(MOUNT_DIR)
$(REDOXFS) $(BUILD)/harddrive.img $(MOUNT_DIR)
@sleep 2
@echo "\033[1;36;49mharddrive.img mounted ($$(pgrep redoxfs))\033[0m"
endif
mount_extra: $(FSTOOLS) FORCE
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
@mkdir -p $(MOUNT_DIR)
$(REDOXFS) $(BUILD)/extra.img $(MOUNT_DIR)
@sleep 2
@echo "\033[1;36;49mextra.img mounted ($$(pgrep redoxfs))\033[0m"
endif
mount_live: $(FSTOOLS) FORCE
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
@mkdir -p $(MOUNT_DIR)
$(REDOXFS) $(LIVE_IMG) $(MOUNT_DIR)
@sleep 2
@echo "\033[1;36;49m$(notdir $(LIVE_IMG)) mounted ($$(pgrep redoxfs))\033[0m"
endif
unmount: FORCE
ifeq ($(FSTOOLS_IN_PODMAN),1)
$(PODMAN_RUN) make $@
else
@sync
-$(FUMOUNT) $(MOUNT_DIR) 2>/dev/null || true
@rm -rf $(MOUNT_DIR)
@-$(FUMOUNT) /tmp/redox_installer 2>/dev/null || true
@echo "\033[1;36;49mFilesystem unmounted\033[0m"
endif
validate-init: $(BUILD)/harddrive.img
@scripts/validate-init-services.sh $(BUILD)/harddrive.img
# Detect config [[files]] paths that would be silently overwritten by package
# staging during install. See AGENTS.md § "INSTALLER FILE LAYERING" and
# local/docs/COLLISION-DETECTION-STATUS.md.
#
# This is the build-time complement to the installer's runtime CollisionTracker
# (local/sources/installer): the build-time scan catches the same class of bug
# before the expensive disk-image step runs, and it covers configs that the
# installer never sees (because they were filtered out by package groups).
#
# Strict mode (default): any collision fails the build. Override with
# REDBEAR_COLLISIONS_WARN=1 to emit warnings only (e.g. during triage).
validate-collisions:
ifeq ($(REDBEAR_COLLISIONS_WARN),1)
@echo "\033[1;33;49mValidating config [[files]] vs recipe installs (WARN-ONLY)...\033[0m"
@python3 local/scripts/verify-collision-detection.py --report summary "$(FILESYSTEM_CONFIG)" \
|| true
else
@echo "\033[1;36;49mValidating config [[files]] vs recipe installs...\033[0m"
@python3 local/scripts/verify-collision-detection.py --strict --report summary "$(FILESYSTEM_CONFIG)" \
|| { echo "\033[1;31;49mCollision detection FAILED: a config [[files]] path would be overwritten by package staging.\033[0m"; \
echo "See local/docs/COLLISION-DETECTION-STATUS.md for the layering rules."; \
echo "Override with REDBEAR_COLLISIONS_WARN=1 or REDBEAR_NO_VALIDATE=1 if you are triaging."; \
exit 1; }
endif
# Full post-build validation gate. Wired as a prerequisite of `all` in the
# root Makefile (overridable via REDBEAR_NO_VALIDATE=1).
validate: lint-config validate-init validate-collisions
@scripts/validate-file-ownership.sh
@echo "\033[1;36;49mBuild validation passed\033[0m"