ww: preserve command package identities

This commit is contained in:
2026-08-13 03:37:08 +09:00
parent 10d24a3237
commit 4377634bb9
10 changed files with 348 additions and 43 deletions

View File

@@ -899,6 +899,33 @@ fn sepimportbasevalid(base: *u8) bool = {
return false;
};
// Go-style command packages keep their canonical import identity while
// declaring main; an external command-test variant declares main_test. These
// declarations classify package kind but never enter action identity.
fn sepcommanddeclaredname(p: *seppkg) bool = {
if (p.name == nil) { return false; };
if (p.variant == SEP_VARIANT_EXTERNAL) {
return cstreqlit(p.name, "main_test");
};
return cstreqlit(p.name, "main");
};
fn sepforbiddencommandimport(g: *sepgraph, importer: i32, dep: i32) bool = {
let from: *seppkg = &g.pkg[importer];
let to: *seppkg = &g.pkg[dep];
if (to.name == nil || !cstreqlit(to.name, "main")
|| to.role != SEP_ROLE_NORMAL) { return false; };
// An external test's exact colocated production edge is variant wiring,
// not a general source-importable command-package alias.
return !(from.variant == SEP_VARIANT_EXTERNAL
&& sepcommanddeclaredname(from)
&& cstreq(from.canon, to.canon));
};
fn sepcommandcompilermarker(g: *sepgraph, pi: i32) bool = {
return sepcommanddeclaredname(&g.pkg[pi]) && !g.pkg[pi].linkentry;
};
// Bind a provisional directory action to its canonical ordinary import
// identity. The compiler path is derived from that base and the semantic
// variant; root/product/artifact state never participates.
@@ -1458,7 +1485,8 @@ fn sepscanfile(g: *sepgraph, pi: i32, file: *u8, searchpath: *u8,
sepbindadd(bindings, 'D': u8, u.usepath, ipath);
let self: bool = os.samefile(pathstr(ipath),
pathstr(g.pkg[pi].entry));
if (self && sepexternalname(&g.pkg[pi], idp, idn, true)) {
if (self && (sepexternalname(&g.pkg[pi], idp, idn, true)
|| sepcommanddeclaredname(&g.pkg[pi]))) {
externalproduction = true;
};
if (self && !externalproduction) {
@@ -1719,7 +1747,8 @@ fn seploadpkg(g: *sepgraph, pi: i32, context: i32) i32 = {
if (g.pkg[pi].path[j] == '.') { leaf = g.pkg[pi].path + j + 1u64; };
j += 1u64;
};
if (!cstreq(g.pkg[pi].name, leaf)) {
if (!cstreq(g.pkg[pi].name, leaf)
&& !sepcommanddeclaredname(&g.pkg[pi])) {
cerr("ww: package ");
cerr(pathstr(g.pkg[pi].name));
cerr(" does not match import path ");
@@ -1765,7 +1794,17 @@ fn seploadpkg(g: *sepgraph, pi: i32, context: i32) i32 = {
g.pkg[pi].contextstate[context] = 2u8;
let k: i32 = 0;
for (k < g.pkg[pi].ndeps) {
if (seploadpkg(g, g.pkg[pi].deps[k], context) < 0) {
let dep: i32 = g.pkg[pi].deps[k];
if (seploadpkg(g, dep, context) < 0) {
g.pkg[pi].failed = true;
return -1;
};
if (dep != pi && sepforbiddencommandimport(g, pi, dep)) {
cerr("ww: package ");
if (g.pkg[dep].path[0u64] != 0u8) {
cerr(pathstr(g.pkg[dep].path));
} else { cerr(pathstr(g.pkg[dep].canon)); };
cerr(" is a program, not an importable package\n");
g.pkg[pi].failed = true;
return -1;
};
@@ -1997,7 +2036,8 @@ fn sepfinalizedirectoryidentities(g: *sepgraph) i32 = {
let supportalias: bool = p.role == SEP_ROLE_TEST_SUPPORT
&& cstreqlit(p.path, SEP_TEST_SUPPORT_MODULE)
&& cstreqlit(p.name, "test");
if (!supportalias && !cstreq(p.name, leaf)) {
if (!supportalias && !cstreq(p.name, leaf)
&& !sepcommanddeclaredname(p)) {
cerr("ww: package "); cerr(pathstr(p.name));
cerr(" does not match import path "); cerr(pathstr(p.path));
cerr("\n");
@@ -2969,12 +3009,14 @@ fn buildonesepimpl(selfdir: *u8, src: *u8, entryisdir: i32,
let gent: bool = g.pkg[pi].generatedmain || rawtest;
let testpkg: bool = g.pkg[pi].variant == SEP_VARIANT_SAME_TEST
|| g.pkg[pi].variant == SEP_VARIANT_EXTERNAL;
let commandpkg: bool = sepcommandcompilermarker(g, pi);
let entry: bool = g.pkg[pi].linkentry;
let supportpkg: bool = g.pkg[pi].testsupport;
let alen: u64 = 8u64;
if (gent) { alen += 4u64; }
else {
if (testpkg) { alen += 1u64; };
if (commandpkg) { alen += 1u64; };
if (entry) { alen += 1u64; };
if (supportpkg) { alen += 2u64; };
};
@@ -2988,6 +3030,7 @@ fn buildonesepimpl(selfdir: *u8, src: *u8, entryisdir: i32,
append(argv, testsupportmodule);
} else {
if (testpkg) { append(argv, "--test-package"); };
if (commandpkg) { append(argv, "--command-package"); };
if (entry) { append(argv, "--entry"); };
if (supportpkg) {
append(argv, "--test-support-module");