Commit 0329df95

0329df9568dcMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 7 files · +5 added · ~2 modified

Description

Ship spinel-doctor / spinel-reduce / spinel-flatten in tools/

Three developer tools that ride along with the compiler, written in the spinel subset and compiled by spinel itself so their only runtime dependency is cc (the same as the compiler) -- no Ruby and no python at run time. They are companion executables (spinel-doctor, the git-* style) rather than subcommands, because spinel's command line is spinel [flags] <app.rb> with the source file as the first positional; a verb there would fork the argument parser. The companion form reads like a subcommand to users while leaving the compiler's parser untouched.

  • spinel-doctor: one health report -- build (compile + C-build, line- mapped), unsupported (codegen stubs), unresolved (silent nil/0 calls, via SPINEL_WARN_UNRESOLVED), requires (native/no-op requires), and an optional behavior leg (compiled output vs CRuby) that skips cleanly when ruby is absent.
  • spinel-reduce: ddmin a degrading program to a minimal repro, with the doctor checks (or a custom --oracle-cmd) as the interestingness test.
  • spinel-flatten: inline a require_relative graph into one file.

Build/install: make compiles each tools/.rb to build/spinel- (wired into all); make install places them on PATH beside spinel so each is found next to the compiler it drives, and the run-time discovery is $SPINEL / $SPINEL_DIR / PATH. A tool that stops fitting the subset breaks the build, keeping them honest.

Behavior and ideas adapted from the spinel-dev tooling (RFC #1381); implemented in-tree here. Refs #1381

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
0329df9568dc
Parent
e25d8e3e2050

MakefilemodifiedView file

@@ -41,7 +41,7 @@
4141 .PHONY: all parse legacy bootstrap codegen regexp rbs_extract rbs-test rbs-seed-test \
4242 analyze-fail-test test test-run clean-test-results regen-rbs-expected \
4343 regen-expected bench optcarrot gate check gate-legs gate-test gate-bench \
44- gate-optcarrot clean install uninstall deps
44+ gate-optcarrot clean install uninstall deps tools
4545
4646 # `make all` includes spinel_rbs_extract when vendor/rbs has been fetched
4747 # (via `make deps`); without it the extractor is silently omitted.
@@ -55,7 +55,7 @@
5555 # `all` rule, because a rule's prerequisites are expanded as it is read.
5656 SPINEL = build/spinel$(EXE)
5757
58-all: parse regexp $(SPINEL) $(RBS_EXTRACT_TARGET)
58+all: parse regexp $(SPINEL) $(RBS_EXTRACT_TARGET) tools
5959
6060 # ---- Dependencies ----
6161 deps: vendor/prism/include/prism/diagnostic.h vendor/rbs/include/rbs/parser.h
@@ -243,6 +243,22 @@
243243
244244 regexp: $(SP_RT_LIB)
245245
246+# ---- In-tree developer tools ----
247+
248+# spinel-doctor / spinel-reduce / spinel-flatten: written in the spinel subset
249+# and compiled by spinel itself (dogfood), so their only runtime dependency is
250+# cc — the same as the compiler. Each tools/<name>.rb becomes build/spinel-<name>;
251+# install places them beside `spinel` so the `spinel-<name>` command is found
252+# next to the compiler it drives. A tool that no longer fits the subset breaks
253+# the build, which keeps them honest.
254+TOOL_NAMES = doctor reduce flatten
255+TOOL_BINS = $(addprefix build/spinel-,$(TOOL_NAMES))
256+
257+tools: $(TOOL_BINS)
258+
259+build/spinel-%$(EXE): tools/%.rb tools/tool_common.rb $(SPINEL) $(SP_RT_LIB)
260+ $(SPINEL) $< -o $@
261+
246262 # ---- Test ----
247263
248264 TESTS := $(wildcard test/*.rb)
@@ -564,9 +580,13 @@
564580 install -m 644 lib/*.rb $(SPNLDIR)/lib/
565581 install -d $(PREFIX)/bin
566582 ln -sf $(SPNLDIR)/spinel $(PREFIX)/bin/spinel
583+ for t in $(TOOL_NAMES); do \
584+ install -m 755 build/spinel-$$t$(EXE) $(PREFIX)/bin/spinel-$$t$(EXE); \
585+ done
567586
568587 uninstall:
569588 rm -f $(PREFIX)/bin/spinel
589+ for t in $(TOOL_NAMES); do rm -f $(PREFIX)/bin/spinel-$$t$(EXE); done
570590 rm -rf $(SPNLDIR)
571591
572592 # ---- Clean ----