ww build: name current directory output

This commit is contained in:
2026-08-21 17:38:00 +09:00
parent 17b2879c3e
commit b03bbb1428
5 changed files with 436 additions and 23 deletions

View File

@@ -8629,7 +8629,7 @@ fn resolvemodule(selfdir: *u8, name: *u8, incs: *u8, isdir: *i32) *u8 = {
};
fn writeusage(fd: i32) void = {
let s: str = "usage: ww [-V] <subcommand> [args...]\n -V print version and exit\n build [-S] [-w DIR] [-I DIR] [-o FILE|DIR] [path ...] build local package graphs\n run [path] ... build then exec, passing extra args to the program\n test [-S -o STEM] [-w DIR] [options] [path ...] build/run tests; -S emits package asm\n version print version and exit\n\n path forms:\n foo.ww literal file\n foo search cwd, -I dirs, then the source library for foo.ww or foo/\n lib/foo directory: build its package sources\n -o FILE publishes a non-main archive FILE + FILE.wwi\n -o DIR publishes each selected command beneath DIR\n lib/... every eligible package under lib, recursively\n . build the cwd's <basename>.ww\n";
let s: str = "usage: ww [-V] <subcommand> [args...]\n -V print version and exit\n build [-S] [-w DIR] [-I DIR] [-o FILE|DIR] [path ...] build local package graphs\n run [path] ... build then exec, passing extra args to the program\n test [-S -o STEM] [-w DIR] [options] [path ...] build/run tests; -S emits package asm\n version print version and exit\n\n path forms:\n foo.ww literal file\n foo search cwd, -I dirs, then the source library for foo.ww or foo/\n lib/foo directory: build its package sources\n -o FILE publishes a non-main archive FILE + FILE.wwi\n -o DIR publishes each selected command beneath DIR\n lib/... every eligible package under lib, recursively\n . current directory package (default when no path is given)\n";
os.write(fd, s.ptr, s.len: u64);
};
@@ -8716,6 +8716,43 @@ fn defaultimportoutpath(identity: *u8) *u8 = {
return out.ptr;
};
fn buildcurrentdirspelling(path: *u8) bool = {
if (path[0u64] == 0u8 || path[0u64] == '/': u8) { return false; };
let i: u64 = 0u64;
let found: bool = false;
for (true) {
for (path[i] == '/': u8) { i += 1u64; };
if (path[i] == 0u8) { return found; };
if (path[i] != '.': u8) { return false; };
i += 1u64;
if (path[i] != 0u8 && path[i] != '/': u8) { return false; };
found = true;
};
return false;
};
fn buildlocaldirleaf(resolved: *u8) *u8 = {
let selected: *u8 = resolved;
if (buildcurrentdirspelling(resolved)) {
let canonical: *u8 = canonicaldir(pathstr(resolved));
if (canonical != nil) { selected = canonical; };
};
let rlen: u64 = cstrlen(selected);
for (rlen > 1u64) {
if (selected[rlen - 1u64] != '/': u8) { break; };
rlen -= 1u64;
};
let bo: u64 = basenameoff(selected, rlen);
let outbuf: []u8 = alloc([], (os.PATH_MAX: u64))!;
outbuf.len = os.PATH_MAX;
let out: *u8 = outbuf.ptr;
let i: u64 = bo;
let off: u64 = 0u64;
for (i < rlen) { out[off] = selected[i]; off += 1u64; i += 1u64; };
cstrseal(out, off);
return out;
};
fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
let src: *u8 = nil;
let srcindex: i32 = -1;
@@ -8897,22 +8934,14 @@ fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = {
} else { if (isdir != 0 && rootidentity != nil) {
out = defaultimportoutpath(rootidentity);
} else { if (isdir != 0) {
let rlen: u64 = cstrlen(resolved);
for (rlen > 1u64) {
if (resolved[rlen - 1u64] != 47u8) { break; };
rlen -= 1u64;
};
let bo: u64 = basenameoff(resolved, rlen);
let outbuf: []u8 = alloc([], (os.PATH_MAX: u64))!;
outbuf.len = os.PATH_MAX;
out = outbuf.ptr;
let i: u64 = bo;
let off: u64 = 0u64;
for (i < rlen) { out[off] = resolved[i]; off += 1u64; i += 1u64; };
cstrseal(out, off);
out = buildlocaldirleaf(resolved);
} else {
out = defaultoutpath(resolved);
}; }; };
if ((outflag == nil || outflag[0u64] == 0u8) && isdir != 0
&& buildcurrentdirspelling(resolved)) {
objstem = out;
};
let defaultoutputdir: *u8 = nil;
if ((outflag == nil || outflag[0u64] == 0u8) && buildoutputdir(out)) {
defaultoutputdir = out;