ww: unify directory package-test products

This commit is contained in:
2026-08-15 01:27:16 +09:00
parent 9c9bed4e65
commit 8dad2755b3
10 changed files with 1553 additions and 485 deletions

View File

@@ -327,6 +327,11 @@ fn allocimportptrs(count: i32) ([]*u8 | nomem) = {
return value;
};
fn allocimportstrs(count: i32) ([]str | nomem) = {
let value: []str = alloc([], count: u64)?;
return value;
};
fn allocnodeptrs(count: i32) ([]*syntax.node | nomem) = {
let value: []*syntax.node = alloc([], count: u64)?;
return value;
@@ -457,7 +462,6 @@ export fn main(argc: i32, argv: **u8) i32 = {
let out: *u8 = nil;
let wwiout: *u8 = nil; // -I <out.wwi>: M2 export-data producer
let testsupport: *u8 = nil;
let testtarget: *u8 = nil;
let testmode: i32 = 0i32; // #15: `-T` test-mode
let testpackage: i32 = 0i32;
let commandpackage: i32 = 0i32;
@@ -469,8 +473,10 @@ export fn main(argc: i32, argv: **u8) i32 = {
// only; treat `.wwi` deps as external)
let pathallocation: ([]*u8 | nomem) = allocimportptrs(argc);
let fileallocation: ([]*u8 | nomem) = allocimportptrs(argc);
let targetallocation: ([]str | nomem) = allocimportstrs(argc);
let importpaths: []*u8;
let importfiles: []*u8;
let testtargets: []str;
let astallocation: ([]*syntax.node | nomem) = allocnodeptrs(argc);
let importasts: []*syntax.node;
match (pathallocation) {
@@ -491,6 +497,15 @@ export fn main(argc: i32, argv: **u8) i32 = {
};
importpaths.len = argc;
importfiles.len = argc;
match (targetallocation) {
case let value: []str => testtargets = value;
case nomem => {
let m: str = "w6c: out of memory\n";
os.write(2, m.ptr, m.len: u64);
return 1;
};
};
testtargets.len = argc;
match (astallocation) {
case let value: []*syntax.node => importasts = value;
case nomem => {
@@ -501,6 +516,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
};
importasts.len = argc;
let nimports: i32 = 0;
let ntesttargets: i32 = 0;
let mapallocation: ([]importmap | nomem) = allocimportmaps(argc);
let importmaps: []importmap;
match (mapallocation) {
@@ -572,7 +588,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
os.write(2, m.ptr, m.len: u64);
return 2;
};
testtarget = argv[i];
testtargets[ntesttargets] = pathstr(argv[i]);
ntesttargets += 1;
} else { if (cstreq(a, "-c")) {
sepmode = 1i32;
} else { if (cstreq(a, "--import")) {
@@ -711,17 +728,24 @@ export fn main(argc: i32, argv: **u8) i32 = {
os.write(2, m.ptr, m.len: u64);
return 2;
};
if (testtarget != nil && (sepmode == 0 || testmode == 0
|| testtarget[0u64] == 0u8)) {
let m: str = "w6c: invalid --test-target-package\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
if (testtarget != nil) {
let targeti: i32 = 0;
for (targeti < ntesttargets) {
let testtarget: str = testtargets[targeti];
if (sepmode == 0 || testmode == 0 || testtarget.len == 0) {
let m: str = "w6c: invalid --test-target-package\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
if (targeti > 0
&& strings.compare(testtargets[targeti - 1], testtarget) >= 0) {
let m: str = "w6c: --test-target-package paths must be sorted and unique\n";
os.write(2, m.ptr, m.len: u64);
return 2;
};
let direct: bool = false;
importi = 0;
for (importi < nimports) {
if (cstreq(importpaths[importi], pathstr(testtarget))) {
if (syntax.streq(pathstr(importpaths[importi]), testtarget)) {
direct = true;
};
importi += 1;
@@ -731,6 +755,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
os.write(2, m.ptr, m.len: u64);
return 2;
};
targeti += 1;
};
let importhead: *syntax.node = nil;
@@ -848,13 +873,14 @@ export fn main(argc: i32, argv: **u8) i32 = {
testsupport)) {
return 1;
};
if (testtarget != nil) {
targeti = 0;
for (targeti < ntesttargets) {
let seen: i32 = 0;
let targetuse: *syntax.node = f.list;
for (targetuse != nil) {
if (targetuse.kind == syntax.nkind.N_USE
&& targetuse.imported == 0
&& syntax.streq(targetuse.usepath, pathstr(testtarget))) {
&& syntax.streq(targetuse.usepath, testtargets[targeti])) {
targetuse.str = targetuse.usepath;
seen += 1;
};
@@ -865,6 +891,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
os.write(2, m.ptr, m.len: u64);
return 2;
};
targeti += 1;
};
if (importhead != nil) {
importtail.next = f.list;
@@ -896,8 +923,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
let testmodule: str;
if (testsupport != nil) { testmodule = pathstr(testsupport); };
let testtargetmodule: str;
if (testtarget != nil) { testtargetmodule = pathstr(testtarget); };
testtargets.len = ntesttargets;
let packageinitsymbol: str;
if (packageinit != nil) { packageinitsymbol = pathstr(packageinit); };
let initdispatchsymbol: str;
@@ -905,7 +931,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
let haswwi: i32 = 0;
if (wwiout != nil) { haswwi = 1; };
let compilerc: i32 = wcc.compilefile(f, testmode, testpackage, testmodule,
testtargetmodule, sepmode, wwifd, haswwi, entrymode,
testtargets, sepmode, wwifd, haswwi, entrymode,
packageinitsymbol, initdispatchsymbol);
if (out != nil) { os.close(1i32); };
if (compilerc != 0) {

View File

@@ -3,7 +3,7 @@ package wcc;
import syntax;
export fn compilefile(file: *syntax.node, testmode: i32, testpackage: i32,
testmodule: str, testtarget: str, sepmode: i32, wwifd: i32,
testmodule: str, testtargets: []str, sepmode: i32, wwifd: i32,
haswwi: i32,
entrymode: i32, packageinitsymbol: str, initdispatchsymbol: str) i32 = {
let tc: syntax.tctx;
@@ -13,7 +13,7 @@ export fn compilefile(file: *syntax.node, testmode: i32, testpackage: i32,
ck.istest = testmode;
ck.istestpackage = testpackage;
if (testmodule.len > 0) { ck.testmodule = testmodule; };
ck.testtarget = testtarget;
ck.testtargets = testtargets;
ck.sepmode = sepmode;
ck.packageinitsymbol = packageinitsymbol;
checkfile(&ck, file);

View File

@@ -23,8 +23,8 @@ type checker = struct {
istestpackage: i32, // validate/retain package-owned @test bodies and
// export compiler-private metadata; no entry synth
testmodule: str, // generated dispatcher support qualifier
testtarget: str, // canonical target path used only as the
// compiler-owned generated-main qualifier
testtargets: []str, // canonical generated-main target paths used only as
// compiler-owned generated-main qualifiers
sepmode: i32, // -c package compilation: imported interfaces are
// present, so absent members are hard export errors.
synthtestrun: *syntax.node, // exact generated support.run DOT; its
@@ -8507,8 +8507,8 @@ fn checkinit(c: *checker, tc: *syntax.tctx) void = {
c.istest = 0i32; // #15: caller (w6c main) sets it after init
c.istestpackage = 0i32;
c.testmodule = "test";
let emptytesttarget: str;
c.testtarget = emptytesttarget;
let emptytesttargets: []str;
c.testtargets = emptytesttargets;
c.sepmode = 0i32; // caller (w6c main) sets it from -c
c.synthtestrun = nil;
c.verbose = 0;
@@ -8524,6 +8524,15 @@ fn checkinit(c: *checker, tc: *syntax.tctx) void = {
seedprimitives(c);
};
fn checktesttarget(c: *checker, path: str) bool = {
let i: i32 = 0;
for (i < c.testtargets.len) {
if (syntax.streq(c.testtargets[i], path)) { return true; };
i += 1;
};
return false;
};
fn checkfile(c: *checker, file: *syntax.node) void = {
if (file == nil) { return; };
if (file.kind != syntax.nkind.N_FILE) { return; };
@@ -8547,8 +8556,7 @@ fn checkfile(c: *checker, file: *syntax.node) void = {
if (su.kind == syntax.nkind.N_USE
&& su.imported == 0 && su.sourceid == file.sourceid
&& (syntax.streq(su.usepath, c.testmodule)
|| (c.testtarget.len > 0
&& syntax.streq(su.usepath, c.testtarget)))) {
|| checktesttarget(c, su.usepath))) {
su.used = 1i32;
};
if (su.kind == syntax.nkind.N_USE && su.imported == 0
@@ -8719,9 +8727,8 @@ fn checkfile(c: *checker, file: *syntax.node) void = {
if (t.imported != 0 && t.nmod.len > 0) {
let alias: str = t.pkgname;
if (alias.len == 0) { alias = t.nmod; };
if (c.testtarget.len > 0
&& syntax.streq(t.nmod, c.testtarget)) {
alias = c.testtarget;
if (checktesttarget(c, t.nmod)) {
alias = t.nmod;
};
id = syntax.newnode(syntax.nkind.N_DOT, pf, pl, pc);
id.lhs = syntax.newnode(syntax.nkind.N_IDENT, pf, pl, pc);

File diff suppressed because it is too large Load Diff

View File

@@ -148,7 +148,8 @@ export fn main(argc: i32, argv: **u8) i32 = {
// silently). Mirrors w6c main.ww:162 / cmd/w6c/main.c.
if (l.errs > 0 || ps.errs > 0) { return 1; };
let empty: str;
if (wcc.compilefile(f, 0, 0, empty, empty, 0, -1, 0, 0,
let emptytargets: []str;
if (wcc.compilefile(f, 0, 0, empty, emptytargets, 0, -1, 0, 0,
empty, empty) != 0) { return 1; };
};};};};