pkgsrc-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: odd -J complaint from make on netbsd-11
>On further pondering, trying to expand commands before we have read alll
>makefiles is not a good idea. So the call to MaybeSubMake should be
>move to when we first run a target (if OP_SUBMAKE not already set)
>hopefully when expanding it anyway. That way we reduce overhead (not
>expanding commands for targets that never run, and for those that do,
>avoid expanding multiple times).
>
>I expect that will reduce the test churn a little too.
Indeed, only 3 tests changed results - all of which looked correct.
The diff below passes all tests - we have to make a .make symlink to
${MAKE} so we can invoke something to trigger the expected error.
diff -r fbc7b47463d3 bmake/job.c
--- a/bmake/job.c Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/job.c Thu Feb 05 09:10:50 2026 -0800
@@ -988,6 +988,51 @@
}
/*
+ * Does cmd contain name?
+ * To match; name must be at the start or preceded by '/' or space,
+ * and it must be followed by '\0' or space.
+ */
+static bool
+maybeSubMake(const char *cmd, const char *name, size_t len)
+{
+ const char *p;
+
+ for (p = strstr(cmd, name); p != NULL; p = strstr(&p[1], name)) {
+ if (p == cmd || p[-1] == '/' || ch_isspace(p[-1])) {
+ if (p[len] == '\0' || ch_isspace(p[len]))
+ return true;
+ }
+ }
+ return false;
+}
+
+/*
+ * See if the command possibly calls a sub-make by using the
+ * words progname or "make".
+ */
+static bool
+MaybeSubMake(const char *cmd)
+{
+ static size_t prognameLen;
+ static size_t makeLen;
+ bool rc = false;
+
+ if (!prognameLen) {
+ prognameLen = strlen(progname);
+
+ /* we are always called make for unit-tests */
+ if (prognameLen != 4 || strcmp(progname, "make") != 0)
+ makeLen = 4;
+ }
+ if (maybeSubMake(cmd, progname, prognameLen))
+ rc = true;
+ else if (makeLen > 0 &&
+ maybeSubMake(cmd, "make", makeLen))
+ rc = true;
+ return rc;
+}
+
+/*
* Write a shell command to the job's commands file, to be run later.
*
* If the command starts with '@' and neither the -s nor the -n flag was
@@ -1020,6 +1065,10 @@
/* TODO: handle errors */
xcmdStart = xcmd;
+ if ((job->node->type & OP_SUBMAKE) == 0
+ && MaybeSubMake(xcmd))
+ job->node->type |= OP_SUBMAKE;
+
cmdTemplate = "%s\n";
ParseCommandFlags(&xcmd, &cmdFlags);
diff -r fbc7b47463d3 bmake/parse.c
--- a/bmake/parse.c Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/parse.c Thu Feb 05 09:10:50 2026 -0800
@@ -1985,46 +1985,6 @@
}
-/*
- * See if the command possibly calls a sub-make by using the
- * expressions ${.MAKE}, ${MAKE} or the plain word "make".
- */
-static bool
-MaybeSubMake(const char *cmd)
-{
- const char *start;
-
- for (start = cmd; *start != '\0'; start++) {
- const char *p = start;
- char endc;
-
- /* XXX: What if progname != "make"? */
- if (strncmp(p, "make", 4) == 0)
- if (start == cmd || !ch_isalnum(p[-1]))
- if (!ch_isalnum(p[4]))
- return true;
-
- if (*p != '$')
- continue;
- p++;
-
- if (*p == '{')
- endc = '}';
- else if (*p == '(')
- endc = ')';
- else
- continue;
- p++;
-
- if (*p == '.') /* Accept either ${.MAKE} or ${MAKE}. */
- p++;
-
- if (strncmp(p, "MAKE", 4) == 0 && p[4] == endc)
- return true;
- }
- return false;
-}
-
/* Append the command to the target node. */
static void
GNode_AddCommand(GNode *gn, char *cmd)
@@ -2035,8 +1995,6 @@
/* if target already supplied, ignore commands */
if (!(gn->type & OP_HAS_COMMANDS)) {
Lst_Append(&gn->commands, cmd);
- if (MaybeSubMake(cmd))
- gn->type |= OP_SUBMAKE;
RememberLocation(gn);
} else {
Parse_Error(PARSE_WARNING,
diff -r fbc7b47463d3 bmake/unit-tests/gnode-submake.exp
--- a/bmake/unit-tests/gnode-submake.exp Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/unit-tests/gnode-submake.exp Thu Feb 05 09:10:50 2026 -0800
@@ -1,11 +1,11 @@
#*** Begin input graph for pass 1 in <curdir>:
# all, unmade, type OP_DEPENDS, flags none
# makeinfo, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
-# make-index, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# braces-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# braces-no-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# make-index, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
+# braces-dot, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
+# braces-no-dot, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
# braces-no-dot-modifier, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
-# parentheses-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
-# parentheses-no-dot, unmade, type OP_DEPENDS|OP_SUBMAKE|OP_HAS_COMMANDS, flags none
+# parentheses-dot, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
+# parentheses-no-dot, unmade, type OP_DEPENDS|OP_HAS_COMMANDS, flags none
exit status 0
diff -r fbc7b47463d3 bmake/unit-tests/opt-jobs-internal.exp
--- a/bmake/unit-tests/opt-jobs-internal.exp Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/unit-tests/opt-jobs-internal.exp Thu Feb 05 09:10:50 2026 -0800
@@ -3,12 +3,12 @@
make: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
in make[2] in directory "<curdir>"
direct-open: mode=compat
-make: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
- in make[2] in directory "<curdir>"
+.make[2]: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
+ in .make[2] in directory "<curdir>"
indirect-open: mode=compat
indirect-expr: mode=parallel
-make: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
- in make[2] in directory "<curdir>"
+.make[2]: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
+ in .make[2] in directory "<curdir>"
indirect-comment: mode=compat
indirect-silent-comment: mode=parallel
indirect-expr-empty: mode=parallel
diff -r fbc7b47463d3 bmake/unit-tests/opt-jobs-internal.mk
--- a/bmake/unit-tests/opt-jobs-internal.mk Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/unit-tests/opt-jobs-internal.mk Thu Feb 05 09:10:50 2026 -0800
@@ -33,8 +33,8 @@
@${MAKE} -f ${MAKEFILE} -J 31,32 detect-mode HEADING=${.TARGET}
# expect: indirect-open: mode=compat
-indirect-open: .PHONY
- @${MAKE:U} -f ${MAKEFILE} detect-mode HEADING=${.TARGET}
+indirect-open: .PHONY .make
+ @./.make -f ${MAKEFILE} detect-mode HEADING=${.TARGET}
# When a command in its unexpanded form contains the expression "${MAKE}"
# without any modifiers, the file descriptors get passed around.
@@ -45,9 +45,9 @@
# The "# make" comment starts directly after the leading tab and is thus not
# considered a shell command line. No file descriptors are passed around.
# expect: indirect-comment: mode=compat
-indirect-comment: .PHONY
+indirect-comment: .PHONY .make
# make
- @${MAKE:U} -f ${MAKEFILE} detect-mode HEADING=${.TARGET}
+ @./.make -f ${MAKEFILE} detect-mode HEADING=${.TARGET}
# When the "# make" comment is prefixed with "@", it becomes a shell command.
# As that shell command contains the plain word "make", the file descriptors
@@ -63,3 +63,6 @@
indirect-expr-empty: .PHONY
@${:D make}
@${MAKE:U} -f ${MAKEFILE} detect-mode HEADING=${.TARGET}
+
+.make:
+ @ln -sf ${MAKE} ${.TARGET}
diff -r fbc7b47463d3 bmake/unit-tests/varname-make_stack_trace.exp
--- a/bmake/unit-tests/varname-make_stack_trace.exp Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/unit-tests/varname-make_stack_trace.exp Thu Feb 05 09:10:50 2026 -0800
@@ -37,8 +37,8 @@
*** [enabled-parallel] Error code 2
make: stopped making "enabled-parallel" in unit-tests
-make: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
- in make[5] in directory "<curdir>"
+.make[5]: warning: Invalid internal option "-J" in "<curdir>"; see the manual page
+ in .make[5] in directory "<curdir>"
in target "multi-stage-4" from varname-make_stack_trace.mk:52
in make[4] in directory "<curdir>"
in target "multi-stage-3" from varname-make_stack_trace.mk:50
diff -r fbc7b47463d3 bmake/unit-tests/varname-make_stack_trace.mk
--- a/bmake/unit-tests/varname-make_stack_trace.mk Wed Feb 04 10:57:32 2026 -0800
+++ b/bmake/unit-tests/varname-make_stack_trace.mk Thu Feb 05 09:10:50 2026 -0800
@@ -42,15 +42,18 @@
# expect: in target "multi-stage-1" from varname-make_stack_trace.mk:46
# expect-not-matches: in target "multi%-stage%-4"
# expect-not-matches: in target "multi%-stage%-1"
-multi-stage-1: .PHONY
+multi-stage-1: .PHONY .make
@${MAKE} -f ${MAKEFILE} -j1 multi-stage-2
multi-stage-2: .PHONY
@${MAKE} -f ${MAKEFILE} -j1 multi-stage-3
multi-stage-3: .PHONY
@${MAKE} -f ${MAKEFILE} -j1 multi-stage-4
multi-stage-4: .PHONY
- @${MAKE:U} -f ${MAKEFILE} -j1 multi-stage-5
+ @./.make -f ${MAKEFILE} -j1 multi-stage-5
multi-stage-5: .PHONY
+.make:
+ @ln -sf ${MAKE} ${.TARGET}
+
# for FreeBSD and similar make sure we get the expected errors.
.MAKE.ALWAYS_PASS_JOB_QUEUE= no
Home |
Main Index |
Thread Index |
Old Index