]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 48643] Preserve target-specific variables on intermediate files
authorDmitry Goncharov <dgoncharov@users.sf.net>
Wed, 29 Dec 2021 19:26:40 +0000 (14:26 -0500)
committerPaul Smith <psmith@gnu.org>
Wed, 29 Dec 2021 20:26:56 +0000 (15:26 -0500)
Target-specific variables used to define the target as "ought to
exist" so they could never be intermediate.  Now they can be, so
merge the target-specific variables from the intermediate target
so they're not lost.

* src/implicit.c (pattern_search): Use merge_variable_set_lists
to merge target-specific variables.
* tests/scripts/features/implicit_search: Add tests of target-
specific variable assignments and implicit rules.

src/implicit.c
tests/scripts/features/implicit_search

index 4abd1ce969a79e683766b95ca6db660c0f755d2a..c65aec6632acd56a693bf2992d54b6885c39e5d2 100644 (file)
@@ -975,7 +975,11 @@ pattern_search (struct file *file, int archive,
           f->deps = imf->deps;
           f->cmds = imf->cmds;
           f->stem = imf->stem;
-          f->variables = imf->variables;
+          /* Setting target specific variables for a file causes the file to be
+           * entered to the database as a prerequisite. Implicit search then
+           * treats this file as explicitly mentioned. Preserve target specific
+           * variables of this file.  */
+          merge_variable_set_lists(&f->variables, imf->variables);
           f->pat_variables = imf->pat_variables;
           f->pat_searched = imf->pat_searched;
           f->also_make = imf->also_make;
index 32c9a716ff3bd8fe0a31e1f123bc3e13cc548072..745423d869eb87bc79439cbba65ca62f01abeb3b 100644 (file)
@@ -423,5 +423,68 @@ unrelated: bye.o
 unlink('hello.f', 'hello.z', 'hello.xx', 'bye.xx');
 
 
+# A target specific variable causes the file to be entered to the database as a
+# prerequisite. Implicit search then treats this file as explicitly mentioned.
+# Test that implicit search keeps target specific variables of this file intact.
+# In this series of tests prerequisite 'hello.x' has a target specific variable
+# and is built as an intermediate. Implicit search treats 'hello.x' as
+# explicitly mentioned, but 'hello.x' does not qualify as ought-to-exist.
+unlink('hello.x', 'hello.tsk');
+
+# 'hello.x' is mentioned explicitly on the same implicit rule.
+run_make_test(q!
+all: hello.tsk
+%.tsk: hello.x; $(info $@)
+%.x:; $(flags)
+hello.x: flags:=true
+!, '', "true\nhello.tsk\n");
+
+# Similar to the one above, but this time 'hello.x' is derived from the stem.
+run_make_test(q!
+all: hello.tsk
+%.tsk: %.x; $(info $@)
+%.x:; $(flags)
+hello.x: flags:=true
+!, '', "true\nhello.tsk\n");
+
+# Similar to the one above, this time 'hello.x' is also mentioned explicitly on
+# an unrelated rule.
+run_make_test(q!
+all: hello.tsk
+%.tsk: %.x; $(info $@)
+%.x:; $(flags)
+hello.x: flags:=true
+unrelated: hello.x
+!, '', "true\nhello.tsk\n");
+
+# 'hello.x' has a pattern specific variable.
+run_make_test(q!
+all: hello.tsk
+%.tsk: %.x; $(info $@)
+%.x:; $(flags)
+%.x: flags:=true
+!, '', "true\nhello.tsk\n");
+
+# 'hello.x' has a target specific variable and a pattern specific variable.
+run_make_test(q!
+all: hello.tsk
+%.tsk: %.x; $(info $@)
+%.x:; $(flags)
+hello.x: flags+=good
+%.x: flags:=true
+!, '', "true good\nhello.tsk\n");
+
+# Intermediate prerequisite 'hello.x' has a target specific variable, a pattern
+# specfic variable, matches on both rules '%.tsk: %.x' and 'big_%.tsk: %.x'.
+run_make_test(q!
+all: hello.tsk big_hello.tsk
+%.tsk: %.x; $(info $@)
+big_%.tsk: %.x; $(info $@)
+%.x:; $(flags)
+hello.x: flags+=good
+%.x: flags:=true
+!, '', "true good\nhello.tsk\nbig_hello.tsk\n");
+
+
 # This tells the test driver that the perl test script executed properly.
 1;