fix: ignore hidden named source operands

This commit is contained in:
2026-08-22 19:28:54 +09:00
parent 6279d46652
commit 3922f1c34e
6 changed files with 627 additions and 0 deletions

View File

@@ -7136,6 +7136,38 @@ basename_no_ext(const char *path, char *out, size_t outsz)
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
}
/* Go's named-file package still applies matchFile's unconditional basename
* exclusion before UseAllFiles, platform suffixes, source parsing, or test-file
* classification. Keep this predicate on the public operand spelling: a
* hidden parent does not hide a visible named file, while a hidden symlink
* spelling remains hidden regardless of its non-directory target kind. */
static int
source_operand_ignored(const char *path)
{
struct stat st;
size_t n = strlen(path);
if (n < 3 || strcmp(path + n - 3, ".ww") != 0) return 0;
if (stat(path, &st) != 0 || S_ISDIR(st.st_mode)) return 0;
const char *base = strrchr(path, '/');
base = base ? base + 1 : path;
return base[0] == '.' || base[0] == '_';
}
static void
source_operand_no_sources(const char *path)
{
const char *slash = strrchr(path, '/');
fputs("ww: ", stderr);
if (slash == NULL) {
fputc('.', stderr);
} else if (slash == path) {
fputc('/', stderr);
} else {
(void)fwrite(path, 1, (size_t)(slash - path), stderr);
}
fputs(": directory contains no WW package sources\n", stderr);
}
/* Go's build -o directory branch follows an existing destination through
* stat, and a trailing platform separator declares a directory which the
* request may need to create. WW's platform separator is '/'. */
@@ -7442,6 +7474,11 @@ do_build(int argc, char **argv)
}
struct stat requested;
int literal = stat(src, &requested) == 0;
if (source_operand_ignored(src)) {
source_operand_no_sources(src);
free(incs);
return 1;
}
char resolved[PATH_MAX];
int is_dir = 0;
if (!resolve_module(src, incs, resolved, sizeof resolved, &is_dir)) {
@@ -7988,6 +8025,29 @@ do_test(int argc, char **argv)
}
}
int discard_output = strcmp(outstem, "/dev/null") == 0;
if (strstr(target, "...") == NULL && source_operand_ignored(target)) {
if (nproducts != 0 && outstem[0]) {
fprintf(stderr,
"ww test: package-test products reject -o\n");
return 2;
}
if (nproducts != 0) {
fprintf(stderr,
"ww test: package-test variant needs one directory\n");
return 2;
}
if (packageopts) {
fprintf(stderr,
"ww test: package options need a directory\n");
return 2;
}
source_operand_no_sources(target);
if (src != NULL && !compileonly && !emit_asm)
fputs("FAIL\n", stdout);
free(products);
free(incs);
return 1;
}
if (pattern != NULL) {
struct stat first;
if (stat(target, &first) != 0 || !S_ISREG(first.st_mode)) {