Debian Codegraph @

tests/scripts/features/grouped_targets

raw
1 # -*-perl-*-
2
3 $description = "This test is about grouped multiple targets indicated by &:";
4 $details = "Here we test for requirements like\n"
5 ."- if multiple such targets are updated, the recipe is run once\n"
6 ."- parsing issues related to the &: syntax itself\n";
7
8 # Parsing: &: allowed without any targets.
9 run_make_test(q{
10 .PHONY: all
11 &:;
12 all: ;@printf ''
13 },
14 '', "");
15
16 # Parsing: &: works not preceded by whitespace.
17 run_make_test(q{
18 foo&:;@echo foo
19 },
20 'foo', "foo");
21
22 # Ordinary rule runs recipe four times for t1 t2 t3 t4.
23 # Grouped target rule runs recipe once; others are considered updated.
24 run_make_test(q{
25 .PHONY: t1 t2 t3 t4 g1 g2 g3 g4
26 t1 t2 t3 t4: ; @echo $@
27 g1 g2 g3 g4 &: ; @echo $@
28 },
29 't1 t2 t3 t4 g1 g2 g3 g4',
30 "t1\n"
31 ."t2\n"
32 ."t3\n"
33 ."t4\n"
34 ."g1\n"
35 ."#MAKE#: Nothing to be done for 'g2'.\n"
36 ."#MAKE#: Nothing to be done for 'g3'.\n"
37 ."#MAKE#: Nothing to be done for 'g4'.");
38
39 # Similar to previous test, but targets come from m1 phony
40 # rather than from the command line. We don't see "Nothing to
41 # be done for" messages. Also, note reversed order g4 g3 ...
42 # Thus the auto variable $@ is "g4" when that rule fires.
43 run_make_test(q{
44 .PHONY: m1 t1 t2 t3 t4 g1 g2 g3 g4
45 m1: t1 t2 t3 t4 g4 g3 g2 g1
46 t1 t2 t3 t4: ; @echo $@
47 g1 g2 g3 g4&: ; @echo $@
48 },
49 '',
50 "t1\nt2\nt3\nt4\ng4");
51
52 # Set a grouped target recipe for existing targets
53 run_make_test(q{
54 .PHONY: M a b
55 M: a b
56 a:
57 a b&: ; @echo Y
58 b:
59 },
60 '',
61 "Y");
62
63 # grouped targets require a recipe
64 run_make_test(q{
65 .PHONY: M a b
66 M: a b
67 a b&:
68 },
69 '',
70 "#MAKEFILE#:4: *** grouped targets must provide a recipe. Stop.", 512);
71
72 # Pattern rules use grouped targets anyway so it's a no-op
73 run_make_test(q{
74 .PHONY: M
75 M: a.q b.q
76 a.% b.%&: ; @echo Y
77 },
78 '',
79 "Y");
80
81 # Double-colon grouped target rules.
82 run_make_test(q{
83 .PHONY: M a b c d e f g h
84 M: a b
85 a b c&:: ; @echo X
86 c d e&:: ; @echo Y
87 f g h&:: ; @echo Z
88 },
89 '',
90 "X");
91
92 run_make_test(q{
93 .PHONY: M a b c d e f g h
94 M: c
95 a b c&:: ; @echo X
96 c d e&:: ; @echo Y
97 f g h&:: ; @echo Z
98 },
99 '',
100 "X\nY");
101
102 run_make_test(q{
103 .PHONY: M a b c d e f g h
104 M: a b c d e
105 a b c&:: ; @echo X
106 c d e&:: ; @echo Y
107 f g h&:: ; @echo Z
108 },
109 '',
110 "X\nY");
111
112 run_make_test(q{
113 .PHONY: M a b c d e f g h
114 M: d e
115 a b c&:: ; @echo X
116 c d e&:: ; @echo Y
117 f g h&:: ; @echo Z
118 },
119 '',
120 "Y");
121
122 run_make_test(q{
123 .PHONY: M a b c d e f g h
124 M: f g h
125 a b c&:: ; @echo X
126 c d e&:: ; @echo Y
127 f g h&:: ; @echo Z
128 },
129 '',
130 "Z");
131
132 # sv 60188.
133 # Test that a file explicitly mentioned by the user and made by an implicit
134 # rule is not considered intermediate.
135
136 touch('hello.z');
137 touch('hello.q');
138
139 # subtest 1
140 # hello.x is not explicitly mentioned and thus is an intermediate file.
141 run_make_test(q!
142 all: hello.z
143 %.z %.q: %.x ; touch $*.z $*.q
144 %.x: ;
145 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
146
147 # subtest 2
148 # test.x is explicitly mentioned and thus is not an intermediate file.
149 run_make_test(q!
150 all: hello.z
151 %.z %.q: %.x test.x ; @echo $*.z $*.q
152 %.x: ;
153 !, '', "hello.z hello.q\n");
154
155 # subtest 3
156 # hello.x is explicitly mentioned on an unrelated rule and thus is not an
157 # intermediate file.
158 run_make_test(q!
159 all: hello.z
160 %.z %.q: %.x; @echo $*.z $*.q
161 %.x: ;
162 unrelated: hello.x
163 !, '', "hello.z hello.q\n");
164
165 unlink('hello.z');
166 unlink('hello.q');
167
168 # SV 62809: Missing grouped target peer causes remake regardless of which
169 # target caused the rule to run.
170 touch(qw(gta)); # but not gtb
171 run_make_test(q!
172 gta gtb &: ; touch gta gtb
173 !,
174 'gta', "touch gta gtb\n");
175 unlink(qw(gta gtb));
176
177 # Ensure both goal targets are built if they depend on a grouped prereq
178 touch(qw(gta)); # but not gtb
179 run_make_test(q!
180 x1 x2: ; touch $@
181
182 x1: gta
183 x2: gtb
184
185 gta gtb &: ; touch gta gtb
186 !,
187 'x1 x2', "touch gta gtb\ntouch x1\ntouch x2\n");
188
189 # Now everything should be up to date
190 run_make_test(undef, 'x1 x2',
191 "#MAKE#: 'x1' is up to date.\n#MAKE#: 'x2' is up to date.");
192
193 unlink(qw(x1 x2 gta gtb));
194
195 # If an also-make file is older than a prerequisite build both
196
197 utouch(-20, 'gtb');
198 utouch(-10, 'pre');
199 touch(qw(gta));
200 run_make_test(q!
201 gta gtb &: pre ; touch gta gtb
202 !,
203 'gta', "touch gta gtb\n");
204 unlink(qw(pre gta gtb));
205
206 # This tells the test driver that the perl test script executed properly.
207 1;