]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Use a recursive environment if any command needs it
authorPaul Smith <psmith@gnu.org>
Wed, 22 Feb 2023 01:32:12 +0000 (20:32 -0500)
committerPaul Smith <psmith@gnu.org>
Wed, 22 Feb 2023 01:53:48 +0000 (20:53 -0500)
We only create one target environment for all commands in a recipe.
Ensure it's set for recursive make if ANY command is recursive, not
just the first one.

* src/job.c (start_job_command): Check for any recursive command.
* tests/scripts/features/jobserver: Test recursion on second line.

src/job.c
tests/scripts/features/jobserver

index 94df0197fd2c62bceaa0433ff1d1cb4aa42ecf7f..ea885614a3862ea1a40d2ed12d78985c17d2ceb7 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -1420,9 +1420,16 @@ start_job_command (struct child *child)
   child->deleted = 0;
 
 #ifndef _AMIGA
-  /* Set up the environment for the child.  */
+  /* Set up the environment for the child.
+     It's a slight inaccuracy to set the environment for recursive make even
+     for command lines that aren't recursive, but I don't want to have to
+     recompute the target environment for each command.  Better would be to
+     keep a separate entry for MAKEFLAGS in the environment so it could be
+     replaced on its own.  For now just set it for all lines.
+   */
   if (child->environment == 0)
-    child->environment = target_environment (child->file, child->recursive);
+    child->environment = target_environment (child->file,
+                                             child->file->cmds->any_recurse);
 #endif
 
 #if !defined(__MSDOS__) && !defined(_AMIGA) && !defined(WINDOWS32)
index e12facf0ae4a480ac409c8dd745f3a910225144b..a2f06ee8e2040a2934407059fc16f82c6cd68824 100644 (file)
@@ -132,6 +132,42 @@ all a: ; @echo $@
               '--jobserver-style=foo -j8',
               "#MAKE#: *** unknown jobserver auth style 'foo'.  Stop.", 512);
 
+# Ensure the jobserver is not disabled even if only later commands are recursive
+
+run_make_test(q!
+.RECIPEPREFIX := >
+all:
+> @echo $@ 1
+> @echo $@ 2
+> @$(MAKE) -f #MAKEFILE# recurse
+
+recurse: ; @echo $@
+!,
+              "$np -j8", "all 1\nall 2\nrecurse");
+
+if ($port_type ne 'W32') {
+    run_make_test(undef, "$np --jobserver-style=pipe -j8",
+                  "all 1\nall 2\nrecurse");
+}
+
+# And with + instead of $(MAKE)
+
+run_make_test(q!
+.RECIPEPREFIX := >
+all:
+> @echo $@ 1
+> @echo $@ 2
+> @+#MAKEPATH# -f #MAKEFILE# recurse
+
+recurse: ; @echo $@
+!,
+              "$np -j8", "all 1\nall 2\nrecurse");
+
+if ($port_type ne 'W32') {
+    run_make_test(undef, "$np --jobserver-style=pipe -j8",
+                  "all 1\nall 2\nrecurse");
+}
+
 if (exists $FEATURES{'jobserver-fifo'}) {
   # sv 62908.
   # Test that when mkfifo fails, make switches to pipe and succeeds.