summaryrefslogtreecommitdiff
path: root/tests/scripts/features/implicit_search
blob: 57782c940092cfc34b9092fa4f434235d15bfaa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
#                                                                    -*-perl-*-

$description = "Test implicit rule search.";

$details = "";

# sv 48643
# Each test has a %.c rule ahead of %.f rule.
# hello.f exists and hello.c is missing.

unlink('hello.c', 'hello.tsk', 'hello.o', 'hello.x');

# Run every test with and without a suffix.
my @suffixes = ('', '.o');
# Run every test with single and double colon rules.
my @rules = ('', ':');

for my $s (@suffixes) {
for my $r (@rules) {
touch('hello.f');

# Test that make finds the intended implicit rule based on existence of a
# prerequisite in the filesystem.
#
# '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen.
run_make_test("
all: hello$s
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");

# Test that make finds the intended implicit rule based on the explicit
# prerequisite of the top goal and despite the existence of a
# prerequisite in the filesystem.
#
# hello.c is an explicit prerequisite of the top target (hello.o or hello).
# hello.c ought to exist.
# hello.c prerequisite causes '%.o: %.c' rule to be chosen.
run_make_test("
hello$s: hello.c
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r',
"#MAKE#: *** No rule to make target 'hello.c', needed by 'hello$s'.  Stop.\n",
512);

# Test that make finds the intended implicit rule when the implicit
# prerequisite matches a target of an unrelated rule and despite the existence
# of a prerequisite of the other rule candidate in the filesystem.
#
# hello.c matches 'hello.c:' rule. This makes hello.c a target and thus ought
# to exist.
# hello.c prerequisite causes '%.o: %.c' rule to be chosen.
run_make_test("
all: hello$s
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
hello.c:; @#HELPER# fail 1
", '-r', "fail 1\n#MAKE#: *** [#MAKEFILE#:5: hello.c] Error 1\n", 512);

# Test that make finds the intended implicit rule based on existence of a
# prerequisite in the filesystem, even when the prerequisite of another
# candidate rule is mentioned explicitly on an unrelated rule.
#
# '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen, even though hello.c
# is mentioned explicitly on 'unrelated: hello.c'.
# ought-to-exist does not apply to hello.c.
run_make_test("
all: hello$s
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
unrelated: hello.c
", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");

# Test that make finds the intended implicit rule based on existence of a
# prerequisite in the filesystem.
#
# '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen.
# Despite '%.o: %.c hello.c' rule having explicit prerequisite hello.c.
# ought-to-exist does not apply to hello.c.
run_make_test("
all: hello$s
%$s:$r %.c hello.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");

# '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen.
# '%.o: %.f hello.f' rule has explicit prerequisite hello.f.
# ought-to-exist does not apply to hello.c.
run_make_test("
all: hello$s
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f hello.f; \$(info hello.f)
", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");

# Rule '%: %.f' is chosen, because '%: %.f' requires no intermediates.
# '%: %.c', on the other hand, requires intemediate hello.c to be built by the
# default rule.
run_make_test("
all: hello$s
%$s:$r %.c; \$(info \$<)
%$s:$r %.f; \$(info \$<)
.DEFAULT:; \$(info \$\@) true
unrelated: hello.c
", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");


# hello.f is missing.
# This time both hello.c and hello.f are missing and both '%: %.c' and '%: %.f'
# require an intermediate.
# The default rule builds intemerdiate hello.c.
# '%: %.c' rule is chosen to build hello.
unlink('hello.f');
run_make_test("
all: hello$s
%$s:$r %.c; \$(info \$<)
%$s:$r %.f; \$(info \$<)
.DEFAULT:; \@\$(info \$\@) #HELPER# fail 1
unrelated: hello.c
", '-r', "hello.c\nfail 1\n#MAKE#: *** [#MAKEFILE#:5: hello.c] Error 1\n", 512);

# hello.f is missing.
# No rule is found, because hello.c is not mentioned explicitly.
run_make_test("
all: hello$s
%$s:$r %.c; \$(info \$<)
%$s:$r %.f; \$(info \$<)
.DEFAULT:; \@\$(info \$\@) #HELPER# fail 1
", '-r', "hello$s\nfail 1\n#MAKE#: *** [#MAKEFILE#:5: hello$s] Error 1\n", 512);

}
}

# Almost the same tests as above, but this time an intermediate is built.

touch('hello.f');
for my $s (@suffixes) {
for my $r (@rules) {

my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'.  Stop.\n";
my $rcode = 512;
if ($s or $r) {
    $result = "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.";
    $rcode = 0;
}

run_make_test("
all: hello.tsk
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r', "$result", $rcode);

run_make_test("
all: hello.tsk
%.tsk: %$s hello$s; \$(info hello.tsk)
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r', $result, $rcode);

run_make_test("
all: hello.tsk
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c hello$s; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r', $result, $rcode);

}
}

for my $r (@rules) {

# Circular dependency hello.o <- hello.tsk is dropped.
run_make_test("
all: hello.tsk
%.tsk: %.o; \$(info hello.tsk)
%.o:$r %.c; \$(info hello.c)
%.o:$r %.f %.tsk; \$(info hello.f)
", '-r',
"#MAKE#: Circular hello.o <- hello.tsk dependency dropped.\nhello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.");

}


for my $s (@suffixes) {
for my $r (@rules) {

run_make_test("
all: hello.tsk
hello$s: hello.c
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
", '-r',
"#MAKE#: *** No rule to make target 'hello.c', needed by 'hello$s'.  Stop.\n",
512);
}
}

for my $s (@suffixes) {
for my $r (@rules) {

my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'.  Stop.\n";
if ($s or $r) {
    $result = "fail 1\n#MAKE#: *** [#MAKEFILE#:6: hello.c] Error 1\n";
}

run_make_test("
all: hello.tsk
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
hello.c:; @#HELPER# fail 1
", '-r', $result, 512);
}
}


for my $s (@suffixes) {
for my $r (@rules) {

run_make_test("
all: hello.tsk
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
unrelated: hello$s
", '-r', "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.");
}
}

for my $s (@suffixes) {
for my $r (@rules) {

my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'.  Stop.\n";
my $rcode = 512;
if ($s or $r) {
    $result = "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.";
    $rcode = 0;
}

run_make_test("
all: hello.tsk
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c; \$(info hello.c)
%$s:$r %.f hello.f; \$(info hello.f)
", '-r', $result, $rcode);
}
}

# One of the implicit rules has two prerequisites, hello.c and hello.x
# hello.c does not qualify as ought to exit.
# hello.x can be made from hello.z.
# This test exercises the break, which prevents making hello.x as an
# intermediate from hello.z during compatibility search.
unlink('hello.f');
touch('hello.z');
for my $s (@suffixes) {
for my $r (@rules) {

run_make_test("
all: hello.tsk
%.tsk: %$s; \$(info hello.tsk)
%$s:$r %.c %.x; \$(info hello.c)
%$s:$r %.f; \$(info hello.f)
unrelated: hello$s
%.x:$r %.z; \$(info hello.z)
", '-r',
"#MAKE#: *** No rule to make target 'hello$s', needed by 'hello.tsk'.  Stop.\n",
512);
}
}

# Test that prerequisite 'hello.x' mentioned explicitly on an unrelated rule is
# not considered intermediate.
touch('hello.tsk');
unlink('hello.x');
run_make_test("
all: hello.tsk
%.tsk: %.x; touch hello.tsk
%.x: ;
unrelated: hello.x
", '-r', "touch hello.tsk\n");
unlink('hello.tsk');

touch ('hello.f');
# Test implicit search of builtin rules.

# %: %.c (and other builtin rules) are skipped.
# %: %.f is chosen.
run_make_test(q!
all: hello
!, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\n");

# %.o: %.c (and other builtin rules) are skipped.
# %.o: %.f is chosen.
run_make_test(q!
all: hello.o
!, 'FC="@echo f77" OUTPUT_OPTION=', "f77 -c hello.f\n");


# %: %.c is chosen.
# hello.c is an explicit prerequisite of the top target hello.
# hello.c ought to exist.
# hello.c prerequisite causes '%: %.c' rule to be chosen.
run_make_test(q!
hello: hello.c
!, 'FC="@echo f77" OUTPUT_OPTION=',
"#MAKE#: *** No rule to make target 'hello.c', needed by 'hello'.  Stop.\n",
512);

# %.o: %.c is chosen.
# hello.c is an explicit prerequisite of the top target hello.o.
# hello.c ought to exist.
# hello.c prerequisite causes '%.o: %.c' rule to be chosen.
run_make_test(q!
hello.o: hello.c
!, 'FC="@echo f77" OUTPUT_OPTION=',
"#MAKE#: *** No rule to make target 'hello.c', needed by 'hello.o'.  Stop.\n",
512);

# %: %.c (and other builtin rules) are skipped.
# %: %.f is chosen.
# ought-to-exist does not apply to hello.c.
run_make_test(q!
all: hello
unrelated: hello.c
!, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\n");

# %.o: %.c (and other builtin rules) are skipped.
# %.o: %.f is chosen.
# ought-to-exist does not apply to hello.c.
run_make_test(q!
all: hello.o
unrelated: hello.c
!, 'FC="@echo f77" OUTPUT_OPTION=', "f77 -c hello.f\n");

# builtin rule %.o: %.f is removed.
# %.o: %.c (and other builtin rules) are skipped, because hello.c is missing.
# ought-to-exist does not apply to hello.c.
# %.o: %.c is chosen as a compatibility rule, because of hello.c.
run_make_test(q!
all: hello.o
unrelated: hello.c
%.o: %.f
!, '',
"#MAKE#: *** No rule to make target 'hello.c', needed by 'hello.o'.  Stop.\n",
512);


# sv 17752.
# In this test the builtin match-anything rule '%: %.f' is used to build
# intermediate hello from hello.f, because hello is mentioned explicitly in
# the makefile.
run_make_test(q!
all: hello.tsk
%.tsk: %; $(info $@ from $<)
unrelated: hello
!, 'FC="@echo f77" OUTPUT_OPTION=',
"f77 hello.f -o hello\nhello.tsk from hello\n");

# In this test the builtin match-anything rule %: %.f cannot be used to build
# intermediate hello from hello.f, because hello is not mentioned explicitly in
# the makefile.
run_make_test(q!
all: hello.tsk
%.tsk: %; $(info $@ from $<)
!, 'FC="@echo f77" OUTPUT_OPTION=',
"#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'.  Stop.\n",
512);

# This is just like the one above, but compatibility rule '%.tsk: % %.x' has 2
# prerequisites, '%' and '%.x'.
# '%' expands to 'hello' and matches the explicit 'hello' on the unrelated rule.
# '%.x' is an intermediate built from 'hello.xx' by rule '%.x: %.xx' during the
# second pass (intermed_ok == 1) of compatibility search.
# This test validates that compatibility search performs both intermed_ok == 0
# and intermed_ok == 1 passes.
unlink('hello.x');
touch('hello.xx');
run_make_test(q!
all: hello.tsk
%.tsk: % %.x; $(info $@ from $^)
unrelated: hello
%.x: %.xx; $(info $@ from $<)
!, 'FC="@echo f77" OUTPUT_OPTION=',
"f77 hello.f -o hello\nhello.x from hello.xx\nhello.tsk from hello hello.x\n");

unlink('bye.o', 'bye.tsk', 'bye.x');
# sv 21670.
# Default recipe is used to build bye.o.
run_make_test(q!
all: bye.tsk
%.tsk: %.o; $(info $@ from $<)
.DEFAULT:; $(info bye.o)
unrelated: bye.o
!, '-r', "bye.o\nbye.tsk from bye.o\n#MAKE#: Nothing to be done for 'all'.");

touch('bye.xx');
# This is just like the one above, but compatibility rule '%.tsk: %.o %.x' has 2
# prerequisites, '%.o' and '%.x'.
# '%.o' expands to 'bye.o' and matches the explicit 'bye.o' on the unrelated rule.
# '%.x' is an intermediate built from 'bye.xx' by rule '%.x: %.xx' during the
# second pass (intermed_ok == 1) of compatibility search.
# This test validates that compatibility search performs both intermed_ok == 0
# and intermed_ok == 1 passes.
run_make_test(q!
all: bye.tsk
%.tsk: %.o %.x; $(info $@ from $^)
.DEFAULT:; $(info bye.o)
unrelated: bye.o
%.x: %.xx; $(info $@ from $<)
!, '-r',
"bye.o\nbye.x from bye.xx\nbye.tsk from bye.o bye.x\n#MAKE#: Nothing to be done for 'all'.");

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
!, '-r', "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
!, '-r', "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
!, '-r', "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
!, '-r', "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
!, '-r', "true good\nhello.tsk\n");

# Intermediate prerequisite 'hello.x' has a target specific variable, a pattern
# specific 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
!, '-r', "true good\nhello.tsk\nbig_hello.tsk\n");


# This tells the test driver that the perl test script executed properly.
1;