Commit 43bb35fe

43bb35fe5d04Merged

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

Description

build: detect timeout/gtimeout, run without time limits if missing

GNU coreutils' timeout is present on Linux but missing on macOS by default. The previous Makefile chain-failed at the very first timeout call with exit 127, leaving make bench reporting 0 pass / 0 fail / 0 skip with a wall of silent ERRs above it.

Detect timeout (or gtimeout from brew install coreutils); if neither is found, drop the time-limit prefix entirely and print a one-line note. Slow benches won't be auto-killed in that mode but everything else works.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
43bb35fe5d04
Parent
761af06d3f8c

MakefilemodifiedView file

@@ -39,6 +39,16 @@
3939 LDFLAGS += -Wl,--stack,67108864
4040 endif
4141
42+# `timeout` is GNU coreutils — present by default on Linux but missing
43+# on macOS unless `brew install coreutils` is run (where it's named
44+# `gtimeout`). Without it test/bench would chain-fail at the very first
45+# `timeout` call with exit 127, reporting 0 pass / 0 fail. Detect both
46+# names; if neither is found, run without time limits (slow benches
47+# won't be auto-killed, but otherwise everything works).
48+TIMEOUT_BIN := $(shell command -v timeout 2>/dev/null || command -v gtimeout 2>/dev/null)
49+TIMEOUT10 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 10,)
50+TIMEOUT60 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 60,)
51+
4252 # Prism library: prefer vendor/prism (fetched via `make deps`), then
4353 # fall back to the Prism gem if one is installed. Override by setting
4454 # PRISM_DIR=/path/to/prism on the command line.
@@ -148,6 +158,7 @@
148158
149159 test: spinel_parse$(EXE) $(SP_RT_LIB)
150160 @if [ ! -f spinel_codegen$(EXE) ]; then echo "Run 'make bootstrap' first"; exit 1; fi
161+ @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
151162 @pass=0; fail=0; err=0; \
152163 for f in test/*.rb; do \
153164 bn=$$(basename "$$f" .rb); \
@@ -155,8 +166,8 @@
155166 ./spinel_codegen$(EXE) /tmp/_sp_t.ast /tmp/_sp_t.c 2>/dev/null && \
156167 $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_t.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_t_bin$(EXE) 2>/dev/null; \
157168 if [ $$? -eq 0 ]; then \
158- expected=$$(timeout 10 ruby "$$f" 2>/dev/null); \
159- actual=$$(timeout 10 /tmp/_sp_t_bin$(EXE) 2>/dev/null); \
169+ expected=$$($(TIMEOUT10) ruby "$$f" 2>/dev/null); \
170+ actual=$$($(TIMEOUT10) /tmp/_sp_t_bin$(EXE) 2>/dev/null); \
160171 if [ "$$expected" = "$$actual" ]; then \
161172 pass=$$((pass+1)); \
162173 else \
@@ -171,19 +182,20 @@
171182
172183 bench: spinel_parse$(EXE) $(SP_RT_LIB)
173184 @if [ ! -f spinel_codegen$(EXE) ]; then echo "Run 'make bootstrap' first"; exit 1; fi
185+ @if [ -z "$(TIMEOUT_BIN)" ]; then echo "Note: no 'timeout' command found; running without time limits."; fi
174186 @pass=0; fail=0; skip=0; \
175187 for f in benchmark/*.rb; do \
176188 bn=$$(basename "$$f" .rb); \
177- timeout 10 ./spinel_parse$(EXE) "$$f" /tmp/_sp_b.ast 2>/dev/null && \
178- timeout 10 ./spinel_codegen$(EXE) /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \
189+ $(TIMEOUT10) ./spinel_parse$(EXE) "$$f" /tmp/_sp_b.ast 2>/dev/null && \
190+ $(TIMEOUT10) ./spinel_codegen$(EXE) /tmp/_sp_b.ast /tmp/_sp_b.c 2>/dev/null && \
179191 $(CC) $(CFLAGS) -Werror $(SEC_FLAGS) -Ilib /tmp/_sp_b.c $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o /tmp/_sp_b_bin$(EXE) 2>/dev/null; \
180192 if [ $$? -eq 0 ]; then \
181- expected=$$(timeout 60 ruby "$$f" 2>/dev/null); \
193+ expected=$$($(TIMEOUT60) ruby "$$f" 2>/dev/null); \
182194 ruby_rc=$$?; \
183195 if [ $$ruby_rc -eq 124 ]; then \
184196 echo "SKIP: $$bn (ruby timeout)"; skip=$$((skip+1)); \
185197 else \
186- actual=$$(timeout 60 /tmp/_sp_b_bin$(EXE) 2>/dev/null); \
198+ actual=$$($(TIMEOUT60) /tmp/_sp_b_bin$(EXE) 2>/dev/null); \
187199 if [ "$$expected" = "$$actual" ]; then \
188200 pass=$$((pass+1)); \
189201 else \