driver: ignore wrong-suffix files as named sources
This commit is contained in:
@@ -7241,6 +7241,13 @@ basename_no_ext(const char *path, char *out, size_t outsz)
|
||||
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
source_operand_named(const char *path)
|
||||
{
|
||||
size_t n = strlen(path);
|
||||
return n >= 3 && strcmp(path + n - 3, ".ww") == 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
|
||||
@@ -7250,8 +7257,7 @@ 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 (!source_operand_named(path)) return 0;
|
||||
if (stat(path, &st) != 0 || S_ISDIR(st.st_mode)) return 0;
|
||||
const char *base = strrchr(path, '/');
|
||||
base = base ? base + 1 : path;
|
||||
@@ -7342,7 +7348,7 @@ resolve_module(const char *name, const char *incs, char *out, size_t outsz,
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(name, &st) == 0) {
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
if (S_ISREG(st.st_mode) && source_operand_named(name)) {
|
||||
if (strlen(name) + 1 > outsz) return 0;
|
||||
memcpy(out, name, strlen(name) + 1);
|
||||
*is_dir = 0;
|
||||
@@ -7578,7 +7584,9 @@ do_build(int argc, char **argv)
|
||||
return exec_package_command(argc, argv, src, NULL, NULL, 0, 1);
|
||||
}
|
||||
struct stat requested;
|
||||
int literal = stat(src, &requested) == 0;
|
||||
int literal = stat(src, &requested) == 0
|
||||
&& (S_ISDIR(requested.st_mode)
|
||||
|| source_operand_named(src));
|
||||
int requested_nondirectory = literal && !S_ISDIR(requested.st_mode);
|
||||
if (source_operand_ignored(src)) {
|
||||
source_operand_no_sources(src);
|
||||
@@ -7705,10 +7713,12 @@ do_run(int argc, char **argv)
|
||||
if (next < 0) { free(incs); return 2; }
|
||||
if (src == NULL) src = ".";
|
||||
struct stat requested;
|
||||
int literal = stat(src, &requested) == 0;
|
||||
int literal = stat(src, &requested) == 0
|
||||
&& (S_ISDIR(requested.st_mode)
|
||||
|| source_operand_named(src));
|
||||
if (literal && S_ISDIR(requested.st_mode)) {
|
||||
size_t n = strlen(src);
|
||||
if (n >= 3 && strcmp(src + n - 3, ".ww") == 0) {
|
||||
if (source_operand_named(src)) {
|
||||
if (n >= 8 && strcmp(src + n - 8, "_test.ww") == 0)
|
||||
fprintf(stderr,
|
||||
"ww: cannot run *_test.ww files (%s)\n", src);
|
||||
@@ -8188,10 +8198,14 @@ do_test(int argc, char **argv)
|
||||
}
|
||||
if (pattern != NULL) {
|
||||
struct stat first;
|
||||
if (stat(target, &first) != 0 || !S_ISREG(first.st_mode)) {
|
||||
int first_found = stat(target, &first) == 0;
|
||||
int first_logical = !first_found
|
||||
|| (!S_ISDIR(first.st_mode) && !source_operand_named(target));
|
||||
if (!first_found || !S_ISREG(first.st_mode)
|
||||
|| !source_operand_named(target)) {
|
||||
char first_resolved[PATH_MAX];
|
||||
int first_is_dir = 0;
|
||||
if (stat(target, &first) == 0
|
||||
if (!first_logical
|
||||
|| !resolve_module(target, incs, first_resolved,
|
||||
sizeof first_resolved, &first_is_dir)
|
||||
|| first_is_dir) {
|
||||
@@ -8229,7 +8243,8 @@ do_test(int argc, char **argv)
|
||||
return exec_package_command(argc, argv, src, NULL, NULL, 0, 0);
|
||||
}
|
||||
struct stat st;
|
||||
if (stat(target, &st) != 0) {
|
||||
if (stat(target, &st) != 0
|
||||
|| (!S_ISDIR(st.st_mode) && !source_operand_named(target))) {
|
||||
/* not a literal path — try module resolution and run as
|
||||
* a single test program. */
|
||||
char resolved[PATH_MAX];
|
||||
@@ -8349,7 +8364,7 @@ do_test(int argc, char **argv)
|
||||
if (test_failed) fputs("FAIL\n", stdout);
|
||||
return rc;
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
if (S_ISREG(st.st_mode) && source_operand_named(target)) {
|
||||
if (nproducts != 0) {
|
||||
fprintf(stderr,
|
||||
"ww test: package-test variant needs one directory\n");
|
||||
|
||||
Reference in New Issue
Block a user