test: library behavior owned by the coordinator lib/... walk
Go has no per-file test targets: the PACKAGE is the unit of testing (`go test ./...`) and same-package test files compose together. The 59-target LIBRARY_TESTS fan-out (per-file -w workdirs, one Make rule per suite) collapses to one line: `ww test -j $(JOBS) -w out/wwbuild/wwtest-lib -I lib/ww lib/...` — the regex dir-route precedent generalized. The lib/regex line and the per-file pattern rule instance dissolve with it (test/lang keeps its own rule). Measured before committing (-j4, strings edit row): old per-file warm 4.7-4.9s; bare walk 5.2-5.6s — a real regression, so the coordinator first gained the brief's persistent per-package workdir: `-w DIR` on a package target forwards to wwpackage, which keys DIR/<dir>_<pkg> per group and hands it to each inner `ww test -c` build. Reuse stays entirely with the driver's existing content-identity contract — the coordinator adds pure path policy, no cache machinery. Both driver stages drop their package-target -w rejects (forward instead); -w with -c stays rejected at the coordinator (two ownership contracts). After: 3.9-4.0s on the edit row, 1.0s warm no-op, 2.5s cold — faster than the old flow on every row. package_test's tree -w reject row becomes the positive contract (cold+warm byte-stable stream, cs/ww same) plus the -c conflict reject. libbyteid roster shape DECIDED: per-file fx entries stay — every enrolled file is still standalone-buildable, so coverage is byte-for-byte unchanged; the dir-mode entry form arrives only with the B3 shared-helper split that first needs it. Docs: owner table, target table, -w contract paragraph.
This commit is contained in:
@@ -32,6 +32,7 @@ type pkggroup = struct {
|
||||
external: bool,
|
||||
root: str,
|
||||
combined: str,
|
||||
workdir: str,
|
||||
bin: str,
|
||||
buildout: str,
|
||||
builderr: str,
|
||||
@@ -105,9 +106,10 @@ fn pkgfailpath(path: str, reason: str) void = {
|
||||
|
||||
fn pkgusage() void = {
|
||||
let s: str = strings.concat(
|
||||
"usage: wwtest package [-c] [-list] [-j N] [-I DIR] [-run|-filter GLOB] [-timeout-ms=N] [DIR | DIR/...] [-- GLOB ...]\n",
|
||||
"usage: wwtest package [-c] [-list] [-j N] [-I DIR] [-w DIR] [-run|-filter GLOB] [-timeout-ms=N] [DIR | DIR/...] [-- GLOB ...]\n",
|
||||
" *_test.ww is canonical; noncanonical files require an actual @test declaration\n",
|
||||
" -c retains the compiled package binaries; -j N runs up to N package groups at once\n");
|
||||
" -c retains the compiled package binaries; -j N runs up to N package groups at once\n",
|
||||
" -w DIR keys a persistent per-package-group build workdir under DIR\n");
|
||||
pkgput(os.STDERR_FILENO, s);
|
||||
};
|
||||
|
||||
@@ -505,12 +507,35 @@ fn pkgcombined(g: *pkggroup, srcs: []pkgsource) bool = {
|
||||
return ok;
|
||||
};
|
||||
|
||||
fn pkgworkkey(dir: str, pkg: str) str = {
|
||||
let s: str = strings.dup(strings.concat(dir, "_", pkg));
|
||||
let b: []u8 = strings.toutf8(s);
|
||||
let i: i32 = 0;
|
||||
for (i < b.len) {
|
||||
if (b[i] == '/') { b[i] = '_'; };
|
||||
i += 1;
|
||||
};
|
||||
return strings.frombytes(b);
|
||||
};
|
||||
|
||||
fn pkgsetpaths(g: *pkggroup, root: str, index: i32,
|
||||
compileonly: bool, outname: str) bool = {
|
||||
compileonly: bool, outname: str, workroot: str) bool = {
|
||||
let num: str = strconv.i32tos(index, strconv.base.DEC);
|
||||
g.root = strings.concat(root, "/group-", num);
|
||||
if (!pkgmakedir(g.root)) { return false; };
|
||||
g.combined = strings.concat(g.root, "/package.ww");
|
||||
// A caller-owned persistent workdir root keys one driver -w dir
|
||||
// per (dir, pkg) group; the driver's content-identity contract
|
||||
// owns every reuse decision, so this stays a pure path policy.
|
||||
g.workdir = "";
|
||||
if (workroot.len != 0) {
|
||||
g.workdir = strings.concat(workroot, "/",
|
||||
pkgworkkey(g.dir, g.pkg));
|
||||
match (os.mkdirs(g.workdir, 448)) {
|
||||
case void => void;
|
||||
case let e: os.oserror => return false;
|
||||
};
|
||||
};
|
||||
if (compileonly) {
|
||||
if (outname.len != 0) {
|
||||
g.bin = outname;
|
||||
@@ -561,7 +586,7 @@ fn pkgreportcommand(kind: str, g: *pkggroup, r: *exec.result) void = {
|
||||
|
||||
fn pkgstartbuild(g: *pkggroup, builder: str, includes: []str,
|
||||
h: *exec.process) void = {
|
||||
let ba: []str = alloc([], (9 + includes.len * 2): u64)!;
|
||||
let ba: []str = alloc([], (11 + includes.len * 2): u64)!;
|
||||
append(ba, builder);
|
||||
append(ba, "test");
|
||||
append(ba, "-c");
|
||||
@@ -575,6 +600,10 @@ fn pkgstartbuild(g: *pkggroup, builder: str, includes: []str,
|
||||
append(ba, includes[ii]);
|
||||
ii += 1;
|
||||
};
|
||||
if (g.workdir.len != 0) {
|
||||
append(ba, "-w");
|
||||
append(ba, g.workdir);
|
||||
};
|
||||
append(ba, g.combined);
|
||||
let bcmd: exec.command;
|
||||
bcmd.path = builder;
|
||||
@@ -674,6 +703,7 @@ export fn packagecommand(args: []str) int = {
|
||||
let includes: []str = alloc([], (args.len + 1): u64)!;
|
||||
let timeoutarg: str = "";
|
||||
let outname: str = "";
|
||||
let workroot: str = "";
|
||||
let builder: str = pkgdefaultbuilder();
|
||||
let i: i32 = 0;
|
||||
for (i < args.len) {
|
||||
@@ -704,6 +734,17 @@ export fn packagecommand(args: []str) int = {
|
||||
i += 1;
|
||||
continue;
|
||||
};
|
||||
if (strings.compare(a, "-w") == 0) {
|
||||
if (i + 1 >= args.len) { pkgusage(); return 2; };
|
||||
workroot = args[i + 1];
|
||||
i += 2;
|
||||
continue;
|
||||
};
|
||||
if (strings.hasprefix(a, "-w") && a.len > 2) {
|
||||
workroot = a[2:a.len];
|
||||
i += 1;
|
||||
continue;
|
||||
};
|
||||
if (strings.hasprefix(a, "-timeout-ms=")) {
|
||||
if (timeoutarg.len != 0 || a.len == 12
|
||||
|| pkgparsedec(a[12:a.len], 3600000i64) <= 0i64) {
|
||||
@@ -757,6 +798,14 @@ export fn packagecommand(args: []str) int = {
|
||||
pkgputln(os.STDERR_FILENO, "wwtest package: -o needs -c");
|
||||
return 2;
|
||||
};
|
||||
// -c publishes caller-owned sepwork artifacts; mixing that
|
||||
// contract with a persistent workdir is unwired — reject rather
|
||||
// than guess which tree the caller owns.
|
||||
if (workroot.len != 0 && compileonly) {
|
||||
pkgputln(os.STDERR_FILENO,
|
||||
"wwtest package: -w conflicts with -c");
|
||||
return 2;
|
||||
};
|
||||
|
||||
// Go's ./... form: a trailing "..." path element walks the tree
|
||||
// rooted at the prefix instead of one explicit directory.
|
||||
@@ -924,7 +973,7 @@ export fn packagecommand(args: []str) int = {
|
||||
for (!stopped && launched < groups.len && active < jobs) {
|
||||
let g: *pkggroup = &groups[launched];
|
||||
if (!pkgsetpaths(g, tmproot, launched, compileonly,
|
||||
outname)) {
|
||||
outname, workroot)) {
|
||||
g.fail = PKGFAILSETUP;
|
||||
g.state = PKGDONE;
|
||||
stopped = true;
|
||||
|
||||
Reference in New Issue
Block a user