From a3f1bb6cb764e087e8e9e38ec514599ed3cd8d0d Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Thu, 15 Oct 2026 09:48:02 -0500 Subject: [PATCH 1/3] make: stamp the linker cfg's content so a cfg edit relinks (#305) Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 2 +- Makefile | 6 ++++ tools/test_build_flags_stamp.py | 60 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index 8099621..0ba8fa1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -57,7 +57,7 @@ Fresh clone (ip65 backend; UCI needs none of the ip65 steps): mtimes, not the command line, so this used to be a discipline you only had to forget once. It is now an enforced invariant: `build/flags.stamp` holds the fully expanded `CA65FLAGS`/`LD65FLAGS` (`LD65FLAGS` carries `$(CFG)`, so -`BACKEND=` and the profile cfg variants ride along), is content-compared +`BACKEND=` and the profile cfg variants ride along) plus the cfg's sha256 (#305: a cfg edit relinks), is content-compared **at Makefile parse time**, and on any change deletes every `.o` and the PRG. Absence, not an mtime — which is what macOS GNU Make 3.81's 1-second resolution cannot defeat. Both silent failure modes the old rule guarded diff --git a/Makefile b/Makefile index 01703e6..925870d 100644 --- a/Makefile +++ b/Makefile @@ -743,6 +743,11 @@ STAMP_SKIP := $(if $(MAKECMDGOALS),$(if $(filter-out $(STAMP_EXEMPT_GOALS),$(MAK TOOLCHAIN_ID := $(shell bash tools/integration/toolchain_id.sh \ 'CA65=$(or $(CA65),ca65)' 'AR65=$(or $(AR65),ar65)' 'LD65=$(or $(LD65),ld65)') +# The linker cfg by CONTENT: LD65FLAGS carries only its NAME, so an edit to +# the selected cfg moved nothing the stamp saw and the PRG stayed "up to date". +# Content, not an mtime or a $(CFG) prerequisite: 3.81's 1-second mtimes. +CFG_SHA256 := $(firstword $(shell (sha256sum $(CFG) 2>/dev/null || shasum -a 256 $(CFG)) 2>/dev/null)) + FLAGS_STAMP_BODY := printf '%s\n' \ 'c64-https build flags. Generated by the Makefile; do not edit.' \ 'A change to any line deletes every object and the PRG at parse time.' \ @@ -754,6 +759,7 @@ FLAGS_STAMP_BODY := printf '%s\n' \ 'BACKEND=$(BACKEND)' \ 'CA65FLAGS=$(CA65FLAGS)' \ 'LD65FLAGS=$(LD65FLAGS)' \ + 'CFG_SHA256=$(CFG_SHA256)' \ 'SIBLING_LIB_ARCHIVES=$(SIBLING_LIB_ARCHIVES)' \ 'X25519_SEG_FE25519=$(X25519_SEG_FE25519)' \ 'X25519_SEG_LADDER=$(X25519_SEG_LADDER)' \ diff --git a/tools/test_build_flags_stamp.py b/tools/test_build_flags_stamp.py index 0625748..204f99a 100644 --- a/tools/test_build_flags_stamp.py +++ b/tools/test_build_flags_stamp.py @@ -781,6 +781,66 @@ def test_hand_set_makeflags_is_refused_without_touching_the_tree(): ) +class CfgFarm(Farm): + """A Farm whose cfg/ is a private COPY, so a test may edit a linker cfg.""" + + def __init__(self): + super().__init__() + os.unlink(self.dir / "cfg") + shutil.copytree(REPO / "cfg", self.dir / "cfg") + + def append_comment(self, rel): + """A comment-only edit: the cfg's text changes, the link's bytes do not.""" + with open(self.path(rel), "a") as fh: + fh.write("\n# edited by test_build_flags_stamp\n") + + +# Every cfg a build can select (Makefile: CFG, and the two variants it swaps +# in), each with the flags that select it. ip65 is left out for cost, as in +# FARM_LINKS: it needs the ip65 libs built first. +CFG_PROFILES = ( + ("cfg/c64-https-uci.cfg", ("BACKEND=uci",)), + ("cfg/c64-https-uci.cfg", UCI), # onchip alone keeps the base cfg + ("cfg/c64-https-uci-onchip.cfg", UCI + ("USE_NISTCURVES_ONCHIP_COMB=1", + "COLD_BANK=0")), + ("cfg/c64-https-uci-onchip-cold.cfg", UCI + ("USE_NISTCURVES_ONCHIP_COMB=1",)), + ("cfg/c64-https-uci-m3.cfg", ("BACKEND=uci-m3",)), +) + + +def test_cfg_edit_relinks_every_link_output(): + """Editing only the selected linker cfg must relink, without `make clean`. + + The PRG's prerequisites were objects and archives; the cfg reached the + stamp only as the NAME in LD65FLAGS, so an edit to its contents left + `make` at "Nothing to be done" and the old image, map, labels and dbg in + place. The edit here is comment-only, so the relinked PRG must also be + byte-identical. The inverse is pinned in the same case: an untouched cfg + relinks nothing. + """ + _require_toolchain() + for cfg, flags in CFG_PROFILES: + with CfgFarm() as farm: + farm.make(*flags) + before = farm.sha() + old = {o: farm.path(o).stat().st_mtime_ns for o in LINK_OUTPUTS} + proc = farm.make(*flags) + assert "ld65 " not in proc.stdout, ( + f"{cfg}: an unchanged cfg relinked:\n" + proc.stdout) + assert all(farm.path(o).stat().st_mtime_ns == old[o] + for o in LINK_OUTPUTS), f"{cfg}: unchanged cfg touched outputs" + time.sleep(1.1) + farm.append_comment(cfg) + proc = farm.make(*flags) + assert "ld65 " in proc.stdout, ( + f"{cfg} edited, {flags}: make did not relink:\n" + proc.stdout) + for o in LINK_OUTPUTS: + assert farm.exists(o), f"{cfg}: {o} missing after relink" + assert farm.path(o).stat().st_mtime_ns != old[o], ( + f"{cfg}: {o} is stale after a cfg edit") + assert farm.sha() == before, f"{cfg}: a comment edit moved the PRG" + + def test_unchanged_flags_rebuild_nothing(): """The inverse property: the stamp must not make every build a rebuild.""" _require_toolchain() From 9cc5292b56cd6323b50a5e0d8dce211335cb9d9b Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Thu, 15 Oct 2026 09:59:49 -0500 Subject: [PATCH 2/3] test/make: pin cfg stamp as content-based (no sleep), cover ip65, doc wording (#305) Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 6 +++--- Makefile | 3 ++- tools/test_build_flags_stamp.py | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 0ba8fa1..6930453 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -57,9 +57,9 @@ Fresh clone (ip65 backend; UCI needs none of the ip65 steps): mtimes, not the command line, so this used to be a discipline you only had to forget once. It is now an enforced invariant: `build/flags.stamp` holds the fully expanded `CA65FLAGS`/`LD65FLAGS` (`LD65FLAGS` carries `$(CFG)`, so -`BACKEND=` and the profile cfg variants ride along) plus the cfg's sha256 (#305: a cfg edit relinks), is content-compared -**at Makefile parse time**, and on any change deletes every `.o` and the -PRG. Absence, not an mtime — which is what macOS GNU Make 3.81's 1-second +`BACKEND=` and the profile cfg variants ride along) plus the cfg's sha256 +(#305: a cfg edit rebuilds), is content-compared **at Makefile parse +time**, and on any change deletes every `.o` and the PRG. Absence, not an mtime — which is what macOS GNU Make 3.81's 1-second resolution cannot defeat. Both silent failure modes the old rule guarded against are closed, and `tools/test_build_flags_stamp.py` pins each against a `make clean` oracle: the mixed link (`HTTPS_SNI=` invalidating `boot.o` diff --git a/Makefile b/Makefile index 925870d..dffa86c 100644 --- a/Makefile +++ b/Makefile @@ -609,7 +609,8 @@ build/net/ip65/ip65_blob.o: $(IP65_BIN) # hand-kept list of knob names: every flag that reaches the toolchain does so # through CA65FLAGS or LD65FLAGS (which carries $(CFG), hence BACKEND and the # onchip/comb cfg variants), so a new knob added at the top of this file is -# covered on the day it is written. The archive list and the three exported +# covered on the day it is written. The cfg's CONTENT is stamped too (an edit +# to the file moves no command line). The archive list and the three exported # X25519 segment names are added because they steer build inputs without # appearing on either command line. # diff --git a/tools/test_build_flags_stamp.py b/tools/test_build_flags_stamp.py index 204f99a..8d1ad95 100644 --- a/tools/test_build_flags_stamp.py +++ b/tools/test_build_flags_stamp.py @@ -829,7 +829,8 @@ def test_cfg_edit_relinks_every_link_output(): f"{cfg}: an unchanged cfg relinked:\n" + proc.stdout) assert all(farm.path(o).stat().st_mtime_ns == old[o] for o in LINK_OUTPUTS), f"{cfg}: unchanged cfg touched outputs" - time.sleep(1.1) + # No sleep, on purpose: a same-second edit is invisible to an + # mtime prerequisite on make 3.81, so only a content stamp passes. farm.append_comment(cfg) proc = farm.make(*flags) assert "ld65 " in proc.stdout, ( @@ -841,6 +842,25 @@ def test_cfg_edit_relinks_every_link_output(): assert farm.sha() == before, f"{cfg}: a comment edit moved the PRG" +def test_ip65_cfg_edit_changes_the_stamp_and_clears_outputs(): + """The ip65 cfg, without an ip65 link: the goal is build/flags.stamp.""" + _require_toolchain() + with CfgFarm() as farm: + farm.make(*UCI) + farm.make("BACKEND=ip65", STAMP, check=False) + line = lambda: [l for l in farm.path(STAMP).read_text().splitlines() + if l.startswith("CFG_SHA256=")] + before = line() + assert len(before) == 1 and len(before[0]) > len("CFG_SHA256=") + 8 + for o in LINK_OUTPUTS: + farm.path(o).write_text("planted") + farm.append_comment("cfg/c64-https-ip65.cfg") + farm.make("BACKEND=ip65", STAMP, check=False) + assert line() != before, "ip65 cfg edit did not move CFG_SHA256" + for o in LINK_OUTPUTS: + assert not farm.exists(o), f"{o} survived an ip65 cfg edit" + + def test_unchanged_flags_rebuild_nothing(): """The inverse property: the stamp must not make every build a rebuild.""" _require_toolchain() From 5343155de65afca8228b5194e91ea2cf3f299e93 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Thu, 15 Oct 2026 10:06:48 -0500 Subject: [PATCH 3/3] CLAUDE.md rewrap, assert message in ip65 cfg test (#305) Co-Authored-By: Claude Sonnet 5.5 --- CLAUDE.md | 5 +++-- tools/test_build_flags_stamp.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6930453..8523337 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,8 +59,9 @@ to forget once. It is now an enforced invariant: `build/flags.stamp` holds the fully expanded `CA65FLAGS`/`LD65FLAGS` (`LD65FLAGS` carries `$(CFG)`, so `BACKEND=` and the profile cfg variants ride along) plus the cfg's sha256 (#305: a cfg edit rebuilds), is content-compared **at Makefile parse -time**, and on any change deletes every `.o` and the PRG. Absence, not an mtime — which is what macOS GNU Make 3.81's 1-second -resolution cannot defeat. Both silent failure modes the old rule guarded +time**, and on any change deletes every `.o` and the PRG. Absence, +not an mtime — which is what macOS GNU Make 3.81's 1-second resolution +cannot defeat. Both silent failure modes the old rule guarded against are closed, and `tools/test_build_flags_stamp.py` pins each against a `make clean` oracle: the mixed link (`HTTPS_SNI=` invalidating `boot.o` but not `http.o`, which cost a false negative on #141) and no link at all diff --git a/tools/test_build_flags_stamp.py b/tools/test_build_flags_stamp.py index 8d1ad95..f578c78 100644 --- a/tools/test_build_flags_stamp.py +++ b/tools/test_build_flags_stamp.py @@ -851,7 +851,8 @@ def test_ip65_cfg_edit_changes_the_stamp_and_clears_outputs(): line = lambda: [l for l in farm.path(STAMP).read_text().splitlines() if l.startswith("CFG_SHA256=")] before = line() - assert len(before) == 1 and len(before[0]) > len("CFG_SHA256=") + 8 + assert len(before) == 1 and len(before[0]) > len("CFG_SHA256=") + 8, ( + "flags.stamp has no CFG_SHA256 line") for o in LINK_OUTPUTS: farm.path(o).write_text("planted") farm.append_comment("cfg/c64-https-ip65.cfg")