wcc,ww: flip driver to separate-compilation only; delete build_one amalgamator (M4 E3-C1, #22)

build_one_sep (per-package compile + .wwi interfaces + link) becomes the
sole build path. do_build/do_run/do_test and the ww twins all route
through it; --sep is now an accepted no-op and the run-rejects-sep guard
is removed.

Deleted the single-file amalgamator, both stages: build_one, expand,
expand_dir, peek_package (+ the wwstage twins + strictpkgmismatch).
unit_has_package is retained -- the sep scan loop's inline-package check
needs it. The sep-shared helpers (enumerate_dir_ww, locate_import*,
import_path_form, ImportSet, and ww counterparts) stay; they back the
surviving sep path.

Restores missing-package enforcement under sep by construction: the sep
scan loop loudly rejects an unresolvable import (cannot find package
<name>) unless the package is defined inline in the same unit -- matching
the deleted amalgamator and closing the silent-accept the flip would
otherwise introduce.

All 5 wwstage tools relink (each is built via the now-sep `ww build`);
emitted asm is byte-identical to the combined build per bootstrap input,
so the binary md5 delta is pure link layout, not codegen.

selfhost/cmd/ww/main.combined.ww is now stale and unregenerable (its
writer build_one is deleted); #90 deletes it next.

Test retargets folded in (rule-11 carve-out, #61/#133 precedent): each
asserts post-flip-only behavior, is un-pre-migratable unlike #93/#94/#103,
and splitting reddens one side. Closes #97.
- 989_slttypepref -> dir-package layout (xb imports xa so both same-leaf
  `invalid` types are in scope at xb.f); inline-multipackage was the
  amalgamator shape, deleted with the flip.
- 989_sepbuild_run -> run --sep now genuinely runs (exit 7), not the old
  loud-reject (exit 2); + a private per-pid WW_PKGCACHE so the cs/ww
  per-package byte-id compare on the shared real lib pkgs (rt/time/os) no
  longer races concurrent siblings on the global out/.pkgcache (the flip
  made sep the sole path, so every test now contends that cache).
- 737_direnum -> the deleted strictpkgmismatch "differs from" wording ->
  sep's "does not match import path" (shared substring, wwstage terser #68).
- 989_lib_byteid -> corpus-completeness scan excludes generated .sepwork
  scratch (the old `! -name '*.combined.ww'` exclude didn't cover the new
  sep artifact).
This commit is contained in:
2026-06-18 02:51:31 +09:00
parent f98033293e
commit 33edc386f1
6 changed files with 275 additions and 1047 deletions

View File

@@ -236,366 +236,13 @@ enumerate_dir_ww(const char *dirpath, char ***out_files)
return n;
}
static void expand(FILE *out, const char *path, struct ImportSet *visited,
const char *libdir, const char *modpath);
/* Scan `path` for its first non-comment-non-blank line; if it starts
* with `package <name>;` write the name into `out` (NUL-terminated)
* and return 1, else 0. Strict-same-package enforcement (task #23
* subset) is bundled here because the failure mode is dir-enum's
* own — a non-dir-enum compilation unit cannot trigger it. Hare's
* hare/module/srcs.ha:131 has the same constraint via the README
* gate; we encode it as same-package across all enumerated files. */
static int
peek_package(const char *path, char *out, size_t outsz)
{
FILE *in = fopen(path, "rb");
if (in == NULL) return 0;
char line[2048];
int found = 0;
while (fgets(line, sizeof line, in)) {
const char *p = line;
while (*p == ' ' || *p == '\t') p++;
if (*p == '\n' || *p == '\0') continue;
if (p[0] == '/' && p[1] == '/') continue;
if (strncmp(p, "package ", 8) != 0
&& strncmp(p, "package\t", 8) != 0) break;
p += 8;
while (*p == ' ' || *p == '\t') p++;
size_t i = 0;
while (i + 1 < outsz && ((p[i] >= 'a' && p[i] <= 'z')
|| (p[i] >= 'A' && p[i] <= 'Z')
|| p[i] == '_' || (p[i] >= '0' && p[i] <= '9')))
out[i] = p[i], i++;
out[i] = '\0';
found = (i > 0);
break;
}
fclose(in);
return found;
}
/* unit_has_package — does `path` declare `package <leaf>;` ANYWHERE?
* #16 ENFORCE-driver (rob A): distinguishes a genuinely-missing import
* from one satisfied by an INLINE package in the same unit. Unlike
* peek_package (stops at the FIRST package decl), this scans every line
* — single-file multi-package fixtures carry several `package` decls. The
* comment-skip line scan + name match mirror peek_package, uncapped. The
* wwstage twin unithaspackage must stay byte-identical (rule 10). */
static int
unit_has_package(const char *path, const char *leaf)
{
FILE *in = fopen(path, "rb");
if (in == NULL) return 0;
char line[2048];
int found = 0;
while (fgets(line, sizeof line, in)) {
const char *p = line;
while (*p == ' ' || *p == '\t') p++;
if (p[0] == '/' && p[1] == '/') continue;
if (strncmp(p, "package ", 8) != 0
&& strncmp(p, "package\t", 8) != 0) continue;
p += 8;
while (*p == ' ' || *p == '\t') p++;
size_t i = 0;
while (leaf[i] != '\0' && leaf[i] == p[i]) i++;
if (leaf[i] == '\0') {
char c = p[i];
if (c == ';' || c == ' ' || c == '\t'
|| c == '\n' || c == '\0') { found = 1; break; }
}
}
fclose(in);
return found;
}
/* expand_dir — enumerate <dirpath>/*.ww (skip *test.ww), byte-sort,
* recurse into each. Mirrors ref/hare/hare/module/srcs.ha:183
* `_findsrcs` minus tag handling. The visited set still keys on
* concrete file paths so multi-file modules are pulled once.
* Strict-same-package: all enumerated files must declare the same
* `package <name>;` (task #23 subset; failure mode native to
* dir-enum). */
static void
expand_dir(FILE *out, const char *dirpath, struct ImportSet *visited,
const char *libdir, const char *modpath)
{
char **files = NULL;
int n = enumerate_dir_ww(dirpath, &files);
char dirpkg[128] = {0};
for (int i = 0; i < n; i++) {
char fp[1024];
snprintf(fp, sizeof fp, "%s/%s", dirpath, files[i]);
char pkg[128];
if (peek_package(fp, pkg, sizeof pkg)) {
if (dirpkg[0] == '\0') {
snprintf(dirpkg, sizeof dirpkg, "%s", pkg);
} else if (strcmp(dirpkg, pkg) != 0) {
fprintf(stderr,
"ww: %s: package %s differs from %s in same module dir %s\n",
fp, pkg, dirpkg, dirpath);
exit(1);
}
}
expand(out, fp, visited, libdir, modpath);
free(files[i]);
}
free(files);
}
/* Recursively expand `path`: for each top-level `import IDENT;` we
* find, resolve the import and expand it first, then append our own
* bytes. Already-visited paths are skipped. Each source carries its
* own `package <name>;` declaration (the parser stamps decls from
* it). */
static void
expand(FILE *out, const char *path, struct ImportSet *visited,
const char *libdir, const char *modpath)
{
if (import_seen(visited, path)) return;
import_add(visited, path);
FILE *in = fopen(path, "rb");
if (in == NULL) {
fprintf(stderr, "ww: cannot read %s\n", path);
return;
}
char line[2048];
while (fgets(line, sizeof line, in)) {
const char *p = line;
while (*p == ' ' || *p == '\t') p++;
if (strncmp(p, "import ", 7) != 0 && strncmp(p, "import\t", 7) != 0)
continue;
p += 7;
while (*p == ' ' || *p == '\t') p++;
char name[256] = {0};
int j = 0;
while ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z')
|| *p == '_' || *p == '.' || (*p >= '0' && *p <= '9'))
if (j + 1 < (int)sizeof name) name[j++] = *p++;
if (j == 0) continue;
char path_form[256];
import_path_form(name, path_form, sizeof path_form);
char ipath[1024];
int is_dir = 0;
/* #16 ENFORCE-driver (rob A): an unresolvable import is a hard
* error, not a silent skip — the old `continue` let a typo'd/
* missing package drop its symbols and surface later as a
* confusing downstream failure. BUT a locate-miss is legal when
* the package is defined INLINE in the same unit (single-file
* multi-package: `package aa; ... package main; import aa;`) —
* the bundler can't pull it as a file but the checker binds it.
* So: miss + inline `package <leaf>` present -> silent skip;
* miss + not inline -> fatal. */
if (!locate_import(libdir, path_form, ipath, sizeof ipath,
&is_dir)) {
const char *dot = strrchr(name, '.');
const char *leaf = dot ? dot + 1 : name;
if (unit_has_package(path, leaf))
continue; /* inline-satisfied */
fprintf(stderr, "ww: cannot find package %s\n", name);
exit(1);
}
/* M1 #22 (isdir-gated, rob-ratified): a package IS a directory, so
* only DIRECTORY imports are package boundaries that path-mangle.
* A single-file import (`import opcodes;` → opcodes.ww declaring
* `package w6a`) is an intra-package file-split — it keeps its
* in-file `package` clause as its module (no directive). */
if (is_dir) expand_dir(out, ipath, visited, libdir, name);
else expand(out, ipath, visited, libdir, NULL);
}
/* #16 option-B: a package-less file's decls would otherwise inherit
* the preceding bundled module's sticky curmod (parser parse.c). Emit
* a curmod-reset boundary directive so the lexer/parser attribute the
* file to the primary module ("") — fixes the self-import false-fire
* and the leaked-prefix bug, codegen-neutral (bare symbols kept; not
* `package main`, which would main-prefix them). A packaged file's own
* `package` decl already sets curmod, so it needs nothing — keeping
* the directive out of every tracked combined.ww. (Task #11.) */
if (modpath != NULL && modpath[0] != '\0') {
/* M1 (#22): an import-reached file carries its full dotted
* import path so codegen mangles symbols on the path, not the
* leaf `package` clause. The directive's absence is the root
* marker (#32): root/primary files take the branch below. */
fprintf(out, "//ww:module %s\n", modpath);
} else {
/* Root/primary file: reset the bundle boundary so a preceding
* imported section's sticky pathmod (M1 #22) is cleared. A
* package-less file then stays primary ("") as before; a
* packaged primary's own `package` clause sets curmod fresh
* (pathmod now NULL → real clause, not an assertion). */
fputs("//ww:module-reset\n", out);
}
rewind(in);
int ch;
while ((ch = fgetc(in)) != EOF) fputc(ch, out);
fputc('\n', out);
fclose(in);
}
/* objstem (when non-NULL/non-empty) redirects the .s/.o/.combined.ww
* side files to live beside the build's OUTPUT instead of next to the
* source (task #15/T3). `ww run` and `ww build -o` pass it so concurrent
* builds never share the next-to-source fixed paths; the default
* (objstem == NULL) keeps the old next-to-source layout, load-bearing
* for make's tracked-combined.ww regen + the #110 freshness gate. */
static int
build_one(const char *src, int entry_is_dir, const char *out,
const char *objstem, const char *extra_includes, const char *extra_libs,
const char *extra_libdirs, int is_test)
{
const char *c6 = toolpath("WW_W6C", "w6c");
const char *a6 = toolpath("WW_W6A", "w6a");
const char *l6 = toolpath("WW_W6L", "w6l");
const char *libdir = getenv("WW_LIB");
if (libdir == NULL || libdir[0] == 0) {
static char libbuf[1024];
snprintf(libbuf, sizeof libbuf, "%s/../lib", self_dir);
libdir = libbuf;
}
const char *srcdir = getenv("WW_SRCLIB");
static char srcbuf[1024];
if (srcdir == NULL || srcdir[0] == 0) {
/* in-tree default: ../../lib relative to bin/ */
snprintf(srcbuf, sizeof srcbuf, "%s/../../lib", self_dir);
if (access(srcbuf, 0) == 0) srcdir = srcbuf;
else if (access("lib", 0) == 0) srcdir = "lib";
else srcdir = libdir;
}
/* Compose the search path: source-file's directory first, then any
* -I dirs, then srcdir. The source-dir lead matches Hare's CWD-first
* convention (its `hare test` is run from the module dir, making CWD
* == module-dir); our wrappers don't cd, so dirname(src) is the
* closest analog. Also matches cc -I. — source-dir wins ties over
* the system path. locate_import walks left-to-right.
*
* For a dir entry the source-dir IS src; for a file entry it's
* the dirname. */
char srcd[1024];
if (entry_is_dir) {
snprintf(srcd, sizeof srcd, "%s", src);
size_t n = strlen(srcd);
while (n > 1 && srcd[n-1] == '/') srcd[--n] = '\0';
} else {
const char *slash = strrchr(src, '/');
if (slash) {
size_t n = (size_t)(slash - src);
if (n >= sizeof srcd) n = sizeof srcd - 1;
memcpy(srcd, src, n);
srcd[n] = '\0';
} else {
srcd[0] = '.';
srcd[1] = '\0';
}
}
static char searchpath[4096];
if (extra_includes && extra_includes[0])
snprintf(searchpath, sizeof searchpath, "%s:%s:%s",
srcd, extra_includes, srcdir);
else
snprintf(searchpath, sizeof searchpath, "%s:%s", srcd, srcdir);
srcdir = searchpath;
/* Derive a stem for .s/.o/.combined.ww side files. For a file
* entry strip the .ww. For a dir entry use <dir>/<basename(dir)>
* so artifacts land inside the module directory. */
char stem[1024];
if (entry_is_dir) {
const char *b = strrchr(srcd, '/');
const char *base = b ? b + 1 : srcd;
snprintf(stem, sizeof stem, "%s/%s", srcd, base);
} else {
snprintf(stem, sizeof stem, "%s", src);
char *dot = strrchr(stem, '.');
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
}
const char *ostem = (objstem && objstem[0]) ? objstem : stem;
char asmf[1024], obj[1024], combined[1024];
snprintf(asmf, sizeof asmf, "%s.s", ostem);
snprintf(obj, sizeof obj, "%s.o", ostem);
snprintf(combined, sizeof combined, "%s.combined.ww", ostem);
/* Resolve imports by concatenating sources into a temp file. The
* compiler then sees one flat source. Dir entry → enumerate the
* module dir's *.ww (less *test.ww); file entry → start at the
* file. */
{
FILE *cf = fopen(combined, "wb");
if (cf == NULL) {
fprintf(stderr, "ww: cannot open %s\n", combined);
return 1;
}
struct ImportSet visited = {0};
/* #17 auto-bundle lib/test: the -T synth's main calls lib/test's
* run(), but @test files don't `import test;`. Pull it like an
* implicit import through the same filename-keyed expand path
* (the visited set dedupes if a fixture imports it explicitly).
* The wwstage twin (selfhost/cmd/ww/main.ww) mirrors this. */
if (is_test) {
char tpath[1024];
int tdir = 0;
if (locate_import(srcdir, "test", tpath, sizeof tpath, &tdir)) {
if (tdir) expand_dir(cf, tpath, &visited, srcdir, "test");
else expand(cf, tpath, &visited, srcdir, NULL);
}
}
if (entry_is_dir) expand_dir(cf, srcd, &visited, srcdir, NULL);
else expand(cf, src, &visited, srcdir, NULL);
fclose(cf);
for (int i = 0; i < visited.n; i++) free(visited.paths[i]);
free(visited.paths);
}
char cmd[4096];
snprintf(cmd, sizeof cmd, "%s %s-o %s %s", c6, is_test ? "-T " : "",
asmf, combined);
if (run(cmd) != 0) {
fprintf(stderr, "ww: w6c failed\n");
return 1;
}
snprintf(cmd, sizeof cmd, "%s -o %s %s", a6, obj, asmf);
if (run(cmd) != 0) {
fprintf(stderr, "ww: w6a failed\n");
return 1;
}
/* Link runtime: prefer libwwrt.a (selective archive pull) but
* fall back to start.o + syscall.o in the in-tree obj/ dir if
* we're running uninstalled. */
char rtargs[2048] = {0};
char path[1024];
snprintf(path, sizeof path, "%s/libwwrt.a", libdir);
if (access(path, 0) == 0) {
snprintf(rtargs, sizeof rtargs, "%s", path);
} else {
char a1[1024], a2[1024];
snprintf(a1, sizeof a1, "%s/../obj/rt/start.o", self_dir);
snprintf(a2, sizeof a2, "%s/../obj/rt/syscall.o", self_dir);
snprintf(rtargs, sizeof rtargs, "%s %s", a1, a2);
}
/* -L<dir> goes before -l<name> so w6l can resolve the latter. */
const char *libargs = (extra_libs && extra_libs[0]) ? extra_libs : "";
const char *libdirset = (extra_libdirs && extra_libdirs[0]) ? extra_libdirs : "";
snprintf(cmd, sizeof cmd, "%s -o %s %s %s%s%s%s%s",
l6, out, obj, rtargs,
libdirset[0] ? " " : "", libdirset,
libargs[0] ? " " : "", libargs);
if (run(cmd) != 0) {
fprintf(stderr, "ww: w6l failed\n");
return 1;
}
return 0;
}
/* ====================================================================
* ww build --sep — M3-tail separate-compilation driver (task #46/c3).
* ww build separate-compilation driver (task #46/c3).
* ====================================================================
* The `--sep` path materializes each imported package's `.wwi`
* interface and compiles every package on its own (`w6c -c`), then
* flat-links the `.o` set. combined.ww stays the DEFAULT live path;
* --sep is purely additive (no existing invocation reaches it).
* This is the SOLE build path (E3-C1 flip, task #87): the legacy
* single-file amalgamator (build_one/expand) is gone. Each imported
* package's `.wwi` interface is materialized and every package is
* compiled on its own (`w6c -c`), then the `.o` set is flat-linked.
*
* Each w6c pass is BOTH consumer (reads dep `.wwi` as import scope) AND
* producer (writes this package's `.wwi` for its importers via -I), so
@@ -664,6 +311,40 @@ sep_fname(const struct sepgraph *g, int pi, const char *scratch,
snprintf(out, outsz, "%s/%s%s", scratch, base, suffix);
}
/* unit_has_package — does `path` declare `package <leaf>;` ANYWHERE?
* #16 ENFORCE-driver (rob A): distinguishes a genuinely-missing import
* from one satisfied by an INLINE package in the same unit. Unlike
* peek_package (stops at the FIRST package decl), this scans every line
* — single-file multi-package fixtures carry several `package` decls. The
* comment-skip line scan + name match mirror peek_package, uncapped. The
* wwstage twin unithaspackage must stay byte-identical (rule 10). */
static int
unit_has_package(const char *path, const char *leaf)
{
FILE *in = fopen(path, "rb");
if (in == NULL) return 0;
char line[2048];
int found = 0;
while (fgets(line, sizeof line, in)) {
const char *p = line;
while (*p == ' ' || *p == '\t') p++;
if (p[0] == '/' && p[1] == '/') continue;
if (strncmp(p, "package ", 8) != 0
&& strncmp(p, "package\t", 8) != 0) continue;
p += 8;
while (*p == ' ' || *p == '\t') p++;
size_t i = 0;
while (leaf[i] != '\0' && leaf[i] == p[i]) i++;
if (leaf[i] == '\0') {
char c = p[i];
if (c == ';' || c == ' ' || c == '\t'
|| c == '\n' || c == '\0') { found = 1; break; }
}
}
fclose(in);
return found;
}
/* Scan one source file for top-level `import IDENT;`, resolving each. A
* DIRECTORY import is a package boundary: add it as a direct dep of pkg
* `pi`. A FILE import is an intra-package split — fold its imports into
@@ -699,12 +380,21 @@ sep_scan_file(struct sepgraph *g, int pi, const char *file,
import_path_form(name, path_form, sizeof path_form);
char ipath[1024];
int is_dir = 0;
/* a locate-miss is an inline-satisfied (single-file multi-
* package) import; --sep targets directory packages, so the
* combined path owns that case. Skip, mirroring expand. */
/* #16 ENFORCE-driver: an unresolvable import is a hard error,
* not a silent skip — EXCEPT when the package is defined INLINE
* in the same unit (single-file multi-package; leaf = the last
* dotted component). E3-C1: the combined path that used to own
* the genuine-missing case is gone, so the sep producer enforces
* it here (INV-2, by construction). Mirrors the deleted expand. */
if (!locate_import(searchpath, path_form, ipath, sizeof ipath,
&is_dir))
continue;
&is_dir)) {
const char *dot = strrchr(name, '.');
const char *leaf = dot ? dot + 1 : name;
if (unit_has_package(file, leaf))
continue; /* inline-satisfied */
fprintf(stderr, "ww: cannot find package %s\n", name);
exit(1);
}
if (is_dir) {
int di = sep_find_or_add(g, name, ipath, 1);
if (di < 0) { rc = -1; break; }
@@ -1470,24 +1160,17 @@ parse_build_flags(const char *cmd, int argc, char **argv,
char *libdirs, size_t libdirsz,
char *libs, size_t libsz,
char *outpath, size_t outsz,
const char **src_out, int *want_sep)
const char **src_out)
{
*src_out = NULL;
int i = 0;
for (; i < argc; i++) {
if (strcmp(argv[i], "--sep") == 0) {
/* M3-tail c3: separate-compilation path, build-only.
* `run` has no sep-compile-then-run path (out of #46
* commit-3 scope), so it LOUD-REJECTS rather than
* silently swallowing a typed flag — both stages reject
* identically (rule 10; want_sep==NULL marks the run
* caller). */
if (want_sep == NULL) {
fprintf(stderr,
"ww %s: --sep is only valid with build\n", cmd);
return -1;
}
*want_sep = 1;
/* E3-C1 flip: separate compilation is now the sole build
* path, so --sep no longer selects anything. Retained as an
* accepted no-op (every subcommand) so the existing --sep
* gate corpus keeps driving the default path. (Task #87.) */
;
} else if (strncmp(argv[i], "-l", 2) == 0 && argv[i][2]) {
size_t n = strlen(libs);
snprintf(libs + n, libsz - n,
@@ -1553,10 +1236,9 @@ do_build(int argc, char **argv)
char libdirs[2048] = {0};
char incs[2048] = {0};
char outflag[1024] = {0};
int want_sep = 0;
if (parse_build_flags("build", argc, argv, incs, sizeof incs,
libdirs, sizeof libdirs, libs, sizeof libs,
outflag, sizeof outflag, &src, &want_sep) < 0)
outflag, sizeof outflag, &src) < 0)
return 2;
if (src == NULL) src = "."; /* default: build cwd */
char resolved[1024];
@@ -1582,10 +1264,8 @@ do_build(int argc, char **argv)
} else {
basename_no_ext(resolved, out, sizeof out);
}
if (want_sep)
return build_one_sep(resolved, is_dir, out, objstem, incs,
libs, libdirs, 0);
return build_one(resolved, is_dir, out, objstem, incs, libs, libdirs, 0);
return build_one_sep(resolved, is_dir, out, objstem, incs, libs,
libdirs, 0);
}
static int
@@ -1598,7 +1278,7 @@ do_run(int argc, char **argv)
char outflag[1024] = {0}; /* -o accepted+ignored: run always uses the temp */
int next = parse_build_flags("run", argc, argv, incs, sizeof incs,
libdirs, sizeof libdirs, libs, sizeof libs,
outflag, sizeof outflag, &src, NULL);
outflag, sizeof outflag, &src);
if (next < 0) return 2;
if (src == NULL) src = ".";
char resolved[1024];
@@ -1611,7 +1291,7 @@ do_run(int argc, char **argv)
snprintf(tmp, sizeof tmp, "/tmp/ww_run_%d", getpid());
/* objstem = tmp → intermediates land at /tmp/ww_run_<pid>.{s,o,
* combined.ww}, never next to the source (T3). */
if (build_one(resolved, is_dir, tmp, tmp, incs, libs, libdirs, 0) != 0)
if (build_one_sep(resolved, is_dir, tmp, tmp, incs, libs, libdirs, 0) != 0)
return 1;
/* exec the built binary with any trailing argv as its argv. */
pid_t pid = fork();
@@ -1648,11 +1328,6 @@ do_test(int argc, char **argv)
* wwstage twin (selfhost/cmd/ww/main.ww dotest). */
int compileonly = 0;
char outstem[1024] = {0};
/* #79 E1: --sep routes a single-file/module test through the
* separate-compilation producer (build_one_sep, is_test=1) instead of
* the amalgamator. Additive (combined stays default); dir-mode --sep is
* deferred to E2. */
int use_sep = 0;
/* #17: an optional second positional after the target is a fnmatch
* name-filter pattern, forwarded to the test binary as argv[1]. Only
* meaningful for a single test file/module — rejected in dir mode. */
@@ -1660,7 +1335,8 @@ do_test(int argc, char **argv)
for (int i = 0; i < argc; i++) {
if (argv[i][0] == '-') {
if (strcmp(argv[i], "--sep") == 0) {
use_sep = 1;
/* E3-C1 flip: sep is the sole path; --sep is an
* accepted no-op (task #87). */
continue;
}
if (argv[i][1] == 'I') {
@@ -1715,11 +1391,8 @@ do_test(int argc, char **argv)
const char *outp;
if (outstem[0]) outp = outstem;
else { snprintf(tmp, sizeof tmp, "/tmp/ww_test_%d", getpid()); outp = tmp; }
int br = use_sep
? build_one_sep(resolved, is_dir, outp,
outstem[0] ? outstem : NULL, incs, "", "", 1)
: build_one(resolved, is_dir, outp,
outstem[0] ? outstem : NULL, incs, "", "", 1);
int br = build_one_sep(resolved, is_dir, outp,
outstem[0] ? outstem : NULL, incs, "", "", 1);
if (br != 0) return 1;
if (compileonly) return 0;
int rc = run_test_bin(outp, pattern);
@@ -1732,11 +1405,8 @@ do_test(int argc, char **argv)
const char *outp;
if (outstem[0]) outp = outstem;
else { snprintf(tmp, sizeof tmp, "/tmp/ww_test_%d", getpid()); outp = tmp; }
int br = use_sep
? build_one_sep(target, 0, outp, outstem[0] ? outstem : NULL,
incs, "", "", 1)
: build_one(target, 0, outp, outstem[0] ? outstem : NULL,
incs, "", "", 1);
int br = build_one_sep(target, 0, outp, outstem[0] ? outstem : NULL,
incs, "", "", 1);
if (br != 0) return 1;
if (compileonly) return 0;
int rc = run_test_bin(outp, pattern);
@@ -1751,13 +1421,6 @@ do_test(int argc, char **argv)
fprintf(stderr, "ww test: -c/-o need a single test file\n");
return 2;
}
/* #79 E1: dir-mode --sep is deferred to E2 — single-file/module is
* enough to prove the sep test path. Loud-reject rather than silently
* fall back to the combined per-file build. */
if (use_sep) {
fprintf(stderr, "ww test: --sep needs a single test file\n");
return 2;
}
/* #17: a name-filter pattern is per-binary; directory mode builds one
* binary per *_test.ww, so a single pattern can't sensibly route. */
if (pattern) {
@@ -1781,7 +1444,7 @@ do_test(int argc, char **argv)
snprintf(tmp, sizeof tmp, "/tmp/ww_test_%d_%d", getpid(), i);
const char *label = strrchr(files[i], '/');
label = label ? label + 1 : files[i];
int rc = build_one(files[i], 0, tmp, NULL, target, "", "", 1);
int rc = build_one_sep(files[i], 0, tmp, NULL, target, "", "", 1);
if (rc != 0) {
fprintf(stderr, "FAIL %s (build)\n", label);
fail++;