Commit 42ac7819

42ac78196573Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

Merge pull request #344 from ryanseys/pr/test-binary-cache

perf(test): incremental test caching via make-native stamps + auto-detect ccache

Details

Commit
42ac78196573
Parent
fa218b0ae62c
Merge parent
7cdbc9e716bb

MakefilemodifiedView file

@@ -9,6 +9,21 @@
99 # make clean Remove built binaries
1010
1111 CC ?= cc
12+# Auto-wrap CC with sccache or ccache when present. Skip when CC is
13+# already wrapped — the substring guard catches both "ccache" and
14+# "sccache" since "ccache" is a substring of "sccache", so CI's
15+# `CC=sccache <cc>` env stays untouched. NO_CCACHE=1 opts out.
16+# `override` is required so that `make CC=gcc` (command-line CC) is
17+# also wrapped — without it, command-line CC takes precedence over
18+# Makefile assignments and the wrap is silently ignored.
19+ifeq (,$(findstring ccache,$(CC)))
20+ifeq (,$(NO_CCACHE))
21+ CCACHE_BIN := $(shell command -v sccache 2>/dev/null || command -v ccache 2>/dev/null)
22+ ifneq (,$(CCACHE_BIN))
23+ override CC := $(CCACHE_BIN) $(CC)
24+ endif
25+endif
26+endif
1227 # `-Wno-alloc-size-larger-than` silences a gcc 13+ paranoia warning that
1328 # fires on the inlined `h->cap *= 2` in sp_*Hash_grow when the inliner
1429 # can't bound h->cap. The pattern is bounded in practice (cap doubles
@@ -104,7 +119,10 @@
104119 PRISM_OBJ = $(patsubst $(PRISM_DIR)/src/%.c,build/prism/%.o,$(PRISM_SRC))
105120 PRISM_LIB = build/libprism.a
106121
107-.PHONY: all parse bootstrap codegen test test-run clean-test-results regen-expected bench clean install uninstall deps
122+CODEGEN_STAMP := build/stamps/spinel_codegen.rb.stamp
123+PARSE_STAMP := build/stamps/spinel_parse.c.stamp
124+
125+.PHONY: all parse bootstrap codegen test retest clean-test-results regen-expected bench clean install uninstall deps
108126
109127 all: parse regexp spinel_codegen$(EXE)
110128
@@ -149,12 +167,27 @@
149167 @mkdir -p $(dir $@)
150168 $(CC) -c -O2 -I$(PRISM_INC) -I$(PRISM_DIR)/src $< -o $@
151169
170+# ---- Content stamps ----
171+# Content stamps: rules depend on `build/stamps/foo.stamp` instead of
172+# `foo` directly, so `touch foo` (or `git checkout` of an identical
173+# version) doesn't invalidate downstream targets. cmp-or-replace
174+# advances the stamp's mtime only on real content change.
175+build/stamps:
176+ @mkdir -p $@
177+
178+build/stamps/%.stamp: % | build/stamps
179+ @cmp -s $< $@ 2>/dev/null || cp $< $@
180+
181+# Without .PRECIOUS make would delete these as pattern-rule
182+# intermediates, recreating them with fresh mtimes next run.
183+.PRECIOUS: build/stamps/%.stamp
184+
152185 # ---- C Parser ----
153186
154187 parse: spinel_parse$(EXE)
155188
156-spinel_parse$(EXE): spinel_parse.c $(PRISM_LIB)
157- $(CC) $(CFLAGS) -I$(PRISM_INC) $< $(PRISM_LIB) -lm -o $@
189+spinel_parse$(EXE): $(PARSE_STAMP) $(PRISM_LIB)
190+ $(CC) $(CFLAGS) -I$(PRISM_INC) spinel_parse.c $(PRISM_LIB) -lm -o $@
158191
159192 # ---- Runtime library (regexp + bigint) ----
160193
@@ -184,7 +217,7 @@
184217
185218 codegen: spinel_codegen$(EXE)
186219
187-spinel_codegen$(EXE): spinel_codegen.rb spinel_parse$(EXE)
220+spinel_codegen$(EXE): $(CODEGEN_STAMP) spinel_parse$(EXE)
188221 ./spinel_parse$(EXE) spinel_codegen.rb build/codegen.ast
189222 ruby spinel_codegen.rb build/codegen.ast build/gen1.c
190223 $(CC) $(BOOTSTRAP_CFLAGS) -Ilib build/gen1.c $(LDFLAGS) -lm -o spinel_codegen$(EXE)
@@ -209,10 +242,9 @@
209242 TESTS := $(wildcard test/*.rb)
210243 TEST_TARGETS := $(patsubst test/%.rb,build/test-results/%.ok,$(TESTS))
211244
212-test: clean-test-results
213- @$(MAKE) --no-print-directory test-run
214-
215-test-run: $(TEST_TARGETS)
245+# `make test` is incremental via mtime tracking on .ok files;
246+# `make retest` wipes them for a forced rerun.
247+test: $(TEST_TARGETS)
216248 @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
217249 @if [ -t 1 ]; then printf '\n'; fi
218250 @pass=$$(grep -l '^PASS' build/test-results/*.ok 2>/dev/null | wc -l); \
@@ -231,7 +263,13 @@
231263 echo "Tests: $$pass pass, $$fail fail, $$err error"; \
232264 if [ $$fail -ne 0 ] || [ $$err -ne 0 ]; then exit 1; fi
233265
234-build/test-results/%.ok: test/%.rb spinel_parse$(EXE) $(SP_RT_LIB) spinel_codegen$(EXE)
266+retest: clean-test-results
267+ @$(MAKE) --no-print-directory test
268+
269+# The .ok target is the test's stamp; mtime tracking gives per-test
270+# caching for free. Order-only spinel_parse$(EXE) / spinel_codegen$(EXE)
271+# stop a bootstrap relink from invalidating every test.
272+build/test-results/%.ok: test/%.rb $(SP_RT_LIB) $(CODEGEN_STAMP) $(PARSE_STAMP) | spinel_parse$(EXE) spinel_codegen$(EXE)
235273 @mkdir -p build/test-results
236274 @tmpdir=$$(mktemp -d /tmp/spinel-test.XXXXXX); \
237275 ast=$$tmpdir/test.ast; \