ww: build intermediates follow -o output stem, not the source dir (test-perf T3a)

build_one/buildone gain an explicit objstem: 'ww build -o X' derives
main.{combined.ww,s,o} beside X; 'ww run' uses its per-pid /tmp stem;
default no--o stays next-to-source (load-bearing for the make regen of
tracked combined.ww and the freshness gate). Realizes the redirect TODO
in 995_self_rebuild.c. Kills the concurrent-test torn-read race on
selfhost/cmd/<tool>/main.* (the 991 transient). 993/995/949 pass -o
into their per-pid workdirs; 949's '-o /dev/null' relied on the old
driver ignoring -o (audited: the only live driver case). Atomic
combined write (os.rename) deferred to its own commit - lib/os lacks
rename and that addition is an import-floor regen.
This commit is contained in:
2026-06-10 17:02:28 +09:00
parent 9b99d0883f
commit 44c47c3ea0
6 changed files with 178 additions and 60 deletions

View File

@@ -82,10 +82,12 @@ struct buildjob {
/* Fork a child that runs the `ww_ww build` for this tool. The child
* inherits no concurrent siblings — system() spawns a fresh /bin/sh -c.
* stderr lands in <workdir>/build.err so concurrent builds don't merge
* their diagnostics. The driver leaves intermediates next to every
* source it traverses (selfhost/cmd/<tool>/main.s, etc.) — task #15 in
* the queue will let us redirect via `-o <outdir>`; until then, test/run
* serializes 990/995 after the parallel phase. */
* their diagnostics. `-o <workdir>/main` (T3) makes the driver write its
* intermediates (main.{combined.ww,s,o}) beside the output in <workdir>
* instead of next to every traversed source — so concurrent driver
* builds no longer share the next-to-source fixed paths, and this gate
* may run in the parallel group. The rebuilt binary still lands at
* <workdir>/main where collect_build diffs it. */
static int
spawn_build(const char *bin, const char *cwd, struct buildjob *j)
{
@@ -99,17 +101,17 @@ spawn_build(const char *bin, const char *cwd, struct buildjob *j)
char cmd[4096];
if (j->inc_local && j->inc_local[0]) {
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww_ww build -I %s/%s "
"cd %s && timeout 180 %s/ww_ww build -o %s/main -I %s/%s "
"-I %s/lib/ww -I %s/lib/ww/lex -I %s/lib/ww/parse "
"-I %s/selfhost/cmd/wcc %s/%s >/dev/null 2>%s/build.err",
j->workdir, bin, cwd, j->inc_local,
j->workdir, bin, j->workdir, cwd, j->inc_local,
cwd, cwd, cwd, cwd, cwd, j->src_rel, j->workdir);
} else {
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww_ww build "
"cd %s && timeout 180 %s/ww_ww build -o %s/main "
"-I %s/lib/ww -I %s/lib/ww/lex -I %s/lib/ww/parse "
"-I %s/selfhost/cmd/wcc %s/%s >/dev/null 2>%s/build.err",
j->workdir, bin, cwd, cwd, cwd, cwd, cwd, j->src_rel, j->workdir);
j->workdir, bin, j->workdir, cwd, cwd, cwd, cwd, cwd, j->src_rel, j->workdir);
}
pid_t p = fork();