]> git.lizzy.rs Git - rust.git/blob - mk/tests.mk
Fix --disable-rpath and tests
[rust.git] / mk / tests.mk
1 # Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11
12 ######################################################################
13 # Test variables
14 ######################################################################
15
16 # The names of crates that must be tested
17 TEST_TARGET_CRATES = $(TARGET_CRATES)
18 TEST_DOC_CRATES = $(DOC_CRATES)
19 TEST_HOST_CRATES = $(HOST_CRATES)
20 TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
21
22 ######################################################################
23 # Environment configuration
24 ######################################################################
25
26 # The arguments to all test runners
27 ifdef TESTNAME
28   TESTARGS += $(TESTNAME)
29 endif
30
31 ifdef CHECK_IGNORED
32   TESTARGS += --ignored
33 endif
34
35 TEST_BENCH =
36
37 # Arguments to the cfail/rfail/rpass/bench tests
38 ifdef CFG_VALGRIND
39   CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
40   TEST_BENCH =
41 endif
42
43 ifdef PLEASE_BENCH
44   TEST_BENCH = --bench
45 endif
46
47 # Arguments to the perf tests
48 ifdef CFG_PERF_TOOL
49   CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
50 endif
51
52 CTEST_TESTARGS := $(TESTARGS)
53
54 ifdef VERBOSE
55   CTEST_TESTARGS += --verbose
56 endif
57
58 # If we're running perf then set this environment variable
59 # to put the benchmarks into 'hard mode'
60 ifeq ($(MAKECMDGOALS),perf)
61   RUST_BENCH=1
62   export RUST_BENCH
63 endif
64
65 TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
66 TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
67
68 TEST_RATCHET_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4)-metrics.json
69 TEST_RATCHET_NOISE_PERCENT=10.0
70
71 # Whether to ratchet or merely save benchmarks
72 ifdef CFG_RATCHET_BENCH
73 CRATE_TEST_EXTRA_ARGS=\
74   --test $(TEST_BENCH) \
75   --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
76   --ratchet-noise-percent $(TEST_RATCHET_NOISE_PERCENT)
77 else
78 CRATE_TEST_EXTRA_ARGS=\
79   --test $(TEST_BENCH) \
80   --save-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4))
81 endif
82
83 # If we're sharding the testsuite between parallel testers,
84 # pass this argument along to the compiletest and crate test
85 # invocations.
86 ifdef TEST_SHARD
87   CTEST_TESTARGS += --test-shard=$(TEST_SHARD)
88   CRATE_TEST_EXTRA_ARGS += --test-shard=$(TEST_SHARD)
89 endif
90
91 define DEF_TARGET_COMMANDS
92
93 ifdef CFG_UNIXY_$(1)
94   CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
95           $$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
96 endif
97
98 ifdef CFG_WINDOWSY_$(1)
99   CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
100    $$(if $$(findstring stage0,$$(1)), \
101        stage0/$$(CFG_LIBDIR_RELATIVE), \
102       $$(if $$(findstring stage1,$$(1)), \
103            stage1/$$(CFG_LIBDIR_RELATIVE), \
104           $$(if $$(findstring stage2,$$(1)), \
105                stage2/$$(CFG_LIBDIR_RELATIVE), \
106                $$(if $$(findstring stage3,$$(1)), \
107                     stage3/$$(CFG_LIBDIR_RELATIVE), \
108                )))))/rustlib/$$(CFG_BUILD)/lib
109   CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
110 endif
111
112 # Run the compiletest runner itself under valgrind
113 ifdef CTEST_VALGRIND
114 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
115       $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
116 else
117 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
118       $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
119 endif
120
121 endef
122
123 $(foreach target,$(CFG_TARGET), \
124   $(eval $(call DEF_TARGET_COMMANDS,$(target))))
125
126 # Target platform specific variables
127 # for arm-linux-androidabi
128 define DEF_ADB_DEVICE_STATUS
129 CFG_ADB_DEVICE_STATUS=$(1)
130 endef
131
132 $(foreach target,$(CFG_TARGET), \
133   $(if $(findstring $(target),"arm-linux-androideabi"), \
134     $(if $(findstring adb,$(CFG_ADB)), \
135       $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
136         $(info check: android device attached) \
137         $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
138         $(info check: android device not attached) \
139         $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
140       ), \
141       $(info check: adb not found) \
142       $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
143     ), \
144   ) \
145 )
146
147 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
148 CFG_ADB_TEST_DIR=/data/tmp
149
150 $(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
151  $(shell $(CFG_ADB) remount 1>/dev/null) \
152  $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
153  $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
154  $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/tmp) \
155  $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
156  $(foreach crate,$(TARGET_CRATES),\
157     $(shell $(CFG_ADB) push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_arm-linux-androideabi,$(crate)) \
158                     $(CFG_ADB_TEST_DIR)))\
159  )
160 else
161 CFG_ADB_TEST_DIR=
162 endif
163
164
165 ######################################################################
166 # Main test targets
167 ######################################################################
168
169 check: cleantmptestlogs cleantestlibs tidy check-notidy
170
171 check-notidy: cleantmptestlogs cleantestlibs all check-stage2
172         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
173
174 check-lite: cleantestlibs cleantmptestlogs \
175         $(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
176         check-stage2-rpass \
177         check-stage2-rfail check-stage2-cfail check-stage2-rmake
178         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
179
180 check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass \
181         check-stage2-rfail check-stage2-cfail check-stage2-rmake
182         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
183
184 check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
185         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
186
187 # NOTE: Remove after reprogramming windows bots
188 check-fast: check-lite
189
190 .PHONY: cleantmptestlogs cleantestlibs
191
192 cleantmptestlogs:
193         $(Q)rm -f tmp/*.log
194
195 cleantestlibs:
196         $(Q)find $(CFG_BUILD)/test \
197          -name '*.[odasS]' -o \
198          -name '*.so' -o      \
199          -name '*.dylib' -o   \
200          -name '*.dll' -o     \
201          -name '*.def' -o     \
202          -name '*.bc' -o      \
203          -name '*.dSYM' -o    \
204          -name '*.libaux' -o      \
205          -name '*.out' -o     \
206          -name '*.err' -o     \
207          -name '*.debugger.script' \
208          | xargs rm -rf
209
210
211 ######################################################################
212 # Tidy
213 ######################################################################
214
215 ifdef CFG_NOTIDY
216 tidy:
217 else
218
219 ALL_CS := $(wildcard $(S)src/rt/*.cpp \
220                      $(S)src/rt/*/*.cpp \
221                      $(S)src/rt/*/*/*.cpp \
222                      $(S)src/rustllvm/*.cpp)
223 ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
224                        $(wildcard $(S)src/rt/hoedown/src/*.c) \
225                        $(wildcard $(S)src/rt/hoedown/bin/*.c) \
226         ,$(ALL_CS))
227 ALL_HS := $(wildcard $(S)src/rt/*.h \
228                      $(S)src/rt/*/*.h \
229                      $(S)src/rt/*/*/*.h \
230                      $(S)src/rustllvm/*.h)
231 ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
232                        $(S)src/rt/valgrind/memcheck.h \
233                        $(S)src/rt/msvc/typeof.h \
234                        $(S)src/rt/msvc/stdint.h \
235                        $(S)src/rt/msvc/inttypes.h \
236                        $(wildcard $(S)src/rt/hoedown/src/*.h) \
237                        $(wildcard $(S)src/rt/hoedown/bin/*.h) \
238         ,$(ALL_HS))
239
240 # Run the tidy script in multiple parts to avoid huge 'echo' commands
241 tidy:
242                 @$(call E, check: formatting)
243                 $(Q)find $(S)src -name '*.r[sc]' \
244                 | grep '^$(S)src/jemalloc' -v \
245                 | grep '^$(S)src/libuv' -v \
246                 | grep '^$(S)src/llvm' -v \
247                 | grep '^$(S)src/gyp' -v \
248                 | grep '^$(S)src/libbacktrace' -v \
249                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
250                 $(Q)find $(S)src/etc -name '*.py' \
251                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
252                 $(Q)find $(S)src/doc -name '*.js' \
253                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
254                 $(Q)find $(S)src/etc -name '*.sh' \
255                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
256                 $(Q)find $(S)src/etc -name '*.pl' \
257                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
258                 $(Q)find $(S)src/etc -name '*.c' \
259                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
260                 $(Q)find $(S)src/etc -name '*.h' \
261                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
262                 $(Q)echo $(ALL_CS) \
263                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
264                 $(Q)echo $(ALL_HS) \
265                 | xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
266                 $(Q)find $(S)src -type f -perm +111 \
267                     -not -name '*.rs' -and -not -name '*.py' \
268                     -and -not -name '*.sh' \
269                 | grep '^$(S)src/jemalloc' -v \
270                 | grep '^$(S)src/libuv' -v \
271                 | grep '^$(S)src/llvm' -v \
272                 | grep '^$(S)src/rt/hoedown' -v \
273                 | grep '^$(S)src/gyp' -v \
274                 | grep '^$(S)src/etc' -v \
275                 | grep '^$(S)src/doc' -v \
276                 | grep '^$(S)src/compiler-rt' -v \
277                 | grep '^$(S)src/libbacktrace' -v \
278                 | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
279
280 endif
281
282
283 ######################################################################
284 # Sets of tests
285 ######################################################################
286
287 define DEF_TEST_SETS
288
289 check-stage$(1)-T-$(2)-H-$(3)-exec:                                     \
290         check-stage$(1)-T-$(2)-H-$(3)-rpass-exec                        \
291         check-stage$(1)-T-$(2)-H-$(3)-rfail-exec                        \
292         check-stage$(1)-T-$(2)-H-$(3)-cfail-exec                        \
293         check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec                   \
294         check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec                   \
295         check-stage$(1)-T-$(2)-H-$(3)-rmake-exec                        \
296         check-stage$(1)-T-$(2)-H-$(3)-crates-exec                       \
297         check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec                   \
298         check-stage$(1)-T-$(2)-H-$(3)-bench-exec                        \
299         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
300         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
301         check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
302         check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
303         check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
304
305 # Only test the compiler-dependent crates when the target is
306 # able to build a compiler (when the target triple is in the set of host triples)
307 ifneq ($$(findstring $(2),$$(CFG_HOST)),)
308
309 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
310         $$(foreach crate,$$(TEST_CRATES), \
311            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
312
313 else
314
315 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
316         $$(foreach crate,$$(TEST_TARGET_CRATES), \
317            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
318
319 endif
320
321 check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
322         $$(foreach crate,$$(TEST_DOC_CRATES), \
323            check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
324
325 check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
326         $$(foreach docname,$$(DOCS), \
327            check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)
328
329 check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
330         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
331         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec    \
332         check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
333         check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
334         check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
335
336 endef
337
338 $(foreach host,$(CFG_HOST), \
339  $(foreach target,$(CFG_TARGET), \
340   $(foreach stage,$(STAGES), \
341     $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
342
343
344 ######################################################################
345 # Crate testing
346 ######################################################################
347
348 define TEST_RUNNER
349
350 # If NO_REBUILD is set then break the dependencies on everything but
351 # the source files so we can test crates without rebuilding any of the
352 # parent crates.
353 ifeq ($(NO_REBUILD),)
354 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
355                             $$(foreach crate,$$(TARGET_CRATES),\
356                                 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
357                                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
358
359 # The regex crate depends on the regex_macros crate during testing, but it
360 # notably depend on the *host* regex_macros crate, not the target version.
361 # Additionally, this is not a dependency in stage1, only in stage2.
362 ifeq ($(4),regex)
363 ifneq ($(1),1)
364 TESTDEP_$(1)_$(2)_$(3)_$(4) += $$(TLIB$(1)_T_$(3)_H_$(3))/stamp.regex_macros
365 endif
366 endif
367
368 else
369 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
370 endif
371
372 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
373 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)):                            \
374                 $$(CRATEFILE_$(4)) \
375                 $$(TESTDEP_$(1)_$(2)_$(3)_$(4))
376         @$$(call E, rustc: $$@)
377         $$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test   \
378                 -L "$$(RT_OUTPUT_DIR_$(2))"             \
379                 -L "$$(LLVM_LIBDIR_$(2))"
380
381 endef
382
383 $(foreach host,$(CFG_HOST), \
384  $(eval $(foreach target,$(CFG_TARGET), \
385   $(eval $(foreach stage,$(STAGES), \
386    $(eval $(foreach crate,$(TEST_CRATES), \
387     $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
388
389 define DEF_TEST_CRATE_RULES
390 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
391
392 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
393                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
394         @$$(call E, run: $$<)
395         $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
396             --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
397             $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
398             && touch $$@
399 endef
400
401 define DEF_TEST_CRATE_RULES_arm-linux-androideabi
402 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
403
404 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
405                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
406         @$$(call E, run: $$< via adb)
407         $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
408         $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
409                 ./$$(notdir $$<) \
410                 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
411                 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
412                 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
413         $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
414         $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
415         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
416         $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
417         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/$$(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) tmp/
418         @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
419         then \
420                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
421                 touch $$@; \
422         else \
423                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
424                 exit 101; \
425         fi
426 endef
427
428 define DEF_TEST_CRATE_RULES_null
429 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
430
431 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
432                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
433         @$$(call E, failing: no device for $$< )
434         false
435 endef
436
437 $(foreach host,$(CFG_HOST), \
438  $(foreach target,$(CFG_TARGET), \
439   $(foreach stage,$(STAGES), \
440    $(foreach crate, $(TEST_CRATES), \
441     $(if $(findstring $(target),$(CFG_BUILD)), \
442      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
443      $(if $(findstring $(target),"arm-linux-androideabi"), \
444       $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
445        $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
446        $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
447       ), \
448       $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
449      ))))))
450
451 ######################################################################
452 # Rules for the compiletest tests (rpass, rfail, etc.)
453 ######################################################################
454
455 RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
456 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
457 RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
458 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
459 CFAIL_FULL_RC := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rc)
460 CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
461 RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
462 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
463 CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
464 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
465 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
466 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
467 DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
468 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
469 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
470 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
471
472 # perf tests are the same as bench tests only they run under
473 # a performance monitor.
474 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
475
476 RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
477 RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
478 CFAIL_FULL_TESTS := $(CFAIL_FULL_RC) $(CFAIL_FULL_RS)
479 RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
480 CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
481 BENCH_TESTS := $(BENCH_RS)
482 PERF_TESTS := $(PERF_RS)
483 PRETTY_TESTS := $(PRETTY_RS)
484 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
485 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
486 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
487
488 CTEST_SRC_BASE_rpass = run-pass
489 CTEST_BUILD_BASE_rpass = run-pass
490 CTEST_MODE_rpass = run-pass
491 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
492
493 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
494 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
495 CTEST_MODE_rpass-full = run-pass
496 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
497
498 CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
499 CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
500 CTEST_MODE_cfail-full = compile-fail
501 CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)
502
503 CTEST_SRC_BASE_rfail = run-fail
504 CTEST_BUILD_BASE_rfail = run-fail
505 CTEST_MODE_rfail = run-fail
506 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
507
508 CTEST_SRC_BASE_cfail = compile-fail
509 CTEST_BUILD_BASE_cfail = compile-fail
510 CTEST_MODE_cfail = compile-fail
511 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
512
513 CTEST_SRC_BASE_bench = bench
514 CTEST_BUILD_BASE_bench = bench
515 CTEST_MODE_bench = run-pass
516 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
517
518 CTEST_SRC_BASE_perf = bench
519 CTEST_BUILD_BASE_perf = perf
520 CTEST_MODE_perf = run-pass
521 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
522
523 CTEST_SRC_BASE_debuginfo-gdb = debuginfo
524 CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
525 CTEST_MODE_debuginfo-gdb = debuginfo-gdb
526 CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)
527
528 CTEST_SRC_BASE_debuginfo-lldb = debuginfo
529 CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
530 CTEST_MODE_debuginfo-lldb = debuginfo-lldb
531 CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
532
533 CTEST_SRC_BASE_codegen = codegen
534 CTEST_BUILD_BASE_codegen = codegen
535 CTEST_MODE_codegen = codegen
536 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
537
538 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
539 # disabled and the associated message to be printed as a warning
540 # during attempts to run those tests.
541
542 ifeq ($(CFG_GDB),)
543 CTEST_DISABLE_debuginfo-gdb = "no gdb found"
544 endif
545
546 ifeq ($(CFG_LLDB),)
547 CTEST_DISABLE_debuginfo-lldb = "no lldb found"
548 endif
549
550 # Completely disable LLDB tests for now
551 CTEST_DISABLE_debuginfo-lldb = "LLDB tests are not enabled yet"
552
553 ifeq ($(CFG_CLANG),)
554 CTEST_DISABLE_codegen = "no clang found"
555 endif
556
557 ifeq ($(CFG_OSTYPE),apple-darwin)
558 CTEST_DISABLE_debuginfo-gdb = "gdb on darwing needs root"
559 endif
560
561 # CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
562 # test group to be disabled *unless* the target is able to build a
563 # compiler (i.e. when the target triple is in the set of of host
564 # triples).  The associated message will be printed as a warning
565 # during attempts to run those tests.
566
567 define DEF_CTEST_VARS
568
569 # All the per-stage build rules you might want to call from the
570 # command line.
571 #
572 # $(1) is the stage number
573 # $(2) is the target triple to test
574 # $(3) is the host triple to test
575
576 # Prerequisites for compiletest tests
577 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
578         $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
579         $$(SREQ$(1)_T_$(2)_H_$(3))
580
581 # Rules for the cfail/rfail/rpass/bench/perf test runner
582
583 # The tests select when to use debug configuration on their own;
584 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
585 CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
586
587 # The tests can not be optimized while the rest of the compiler is optimized, so
588 # filter out the optimization (if any) from rustc and then figure out if we need
589 # to be optimized
590 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
591 ifndef CFG_DISABLE_OPTIMIZE_TESTS
592 CTEST_RUSTC_FLAGS += -O
593 endif
594
595 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) :=                                          \
596                 --compile-lib-path $$(HLIB$(1)_H_$(3))                          \
597         --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3))                       \
598         --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))                        \
599         --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
600         --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
601         --aux-base $$(S)src/test/auxiliary/                 \
602         --stage-id stage$(1)-$(2)                                                       \
603         --target $(2)                                       \
604         --host $(3)                                       \
605         --android-cross-path=$(CFG_ANDROID_CROSS_PATH)    \
606         --adb-path=$(CFG_ADB)                          \
607         --adb-test-dir=$(CFG_ADB_TEST_DIR)                  \
608         --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
609         --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
610         --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
611         $$(CTEST_TESTARGS)
612
613 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
614 CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
615 CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
616 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
617 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
618 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
619 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
620 CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
621 CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS)
622 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
623
624 endef
625
626 $(foreach host,$(CFG_HOST), \
627  $(eval $(foreach target,$(CFG_TARGET), \
628   $(eval $(foreach stage,$(STAGES), \
629    $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
630
631 define DEF_RUN_COMPILETEST
632
633 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
634         $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
635         --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
636         --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
637         --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
638         --mode $$(CTEST_MODE_$(4)) \
639         $$(CTEST_RUNTOOL_$(4))
640
641 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
642
643 # CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
644 # Goal: leave this variable as empty string if we should run the test.
645 # Otherwise, set it to the reason we are not running the test.
646 # (Encoded as a separate variable because GNU make does not have a
647 # good way to express OR on ifeq commands)
648
649 ifneq ($$(CTEST_DISABLE_$(4)),)
650 # Test suite is disabled for all configured targets.
651 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
652 else
653 # else, check if non-self-hosted target (i.e. target not-in hosts) ...
654 ifeq ($$(findstring $(2),$$(CFG_HOST)),)
655 # ... if so, then check if this test suite is disabled for non-selfhosts.
656 ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
657 # Test suite is disabled for this target.
658 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
659 endif
660 endif
661 # Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
662 endif
663
664 ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
665 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
666                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
667                 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
668         @$$(call E, run $(4) [$(2)]: $$<)
669         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
670                 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
671                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
672                 && touch $$@
673
674 else
675
676 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
677         @$$(call E, run $(4) [$(2)]: $$<)
678         @$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
679         touch $$@
680
681 endif
682
683 endef
684
685 CTEST_NAMES = rpass rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
686
687 $(foreach host,$(CFG_HOST), \
688  $(eval $(foreach target,$(CFG_TARGET), \
689   $(eval $(foreach stage,$(STAGES), \
690    $(eval $(foreach name,$(CTEST_NAMES), \
691    $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
692
693 PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
694 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
695 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
696 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
697 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
698 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
699 PRETTY_DIRNAME_pretty-rpass = run-pass
700 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
701 PRETTY_DIRNAME_pretty-rfail = run-fail
702 PRETTY_DIRNAME_pretty-bench = bench
703 PRETTY_DIRNAME_pretty-pretty = pretty
704
705 define DEF_RUN_PRETTY_TEST
706
707 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) :=                   \
708                 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
709         --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
710         --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
711         --mode pretty
712
713 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
714
715 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
716                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3))         \
717                 $$(PRETTY_DEPS_$(4))
718         @$$(call E, run pretty-rpass [$(2)]: $$<)
719         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
720                 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
721                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
722                 && touch $$@
723
724 endef
725
726 $(foreach host,$(CFG_HOST), \
727  $(foreach target,$(CFG_TARGET), \
728   $(foreach stage,$(STAGES), \
729    $(foreach pretty-name,$(PRETTY_NAMES), \
730     $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
731
732
733 ######################################################################
734 # Crate & freestanding documentation tests
735 ######################################################################
736
737 define DEF_RUSTDOC
738 RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
739 RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
740 endef
741
742 $(foreach host,$(CFG_HOST), \
743  $(foreach target,$(CFG_TARGET), \
744   $(foreach stage,$(STAGES), \
745    $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))
746
747 # Freestanding
748
749 define DEF_DOC_TEST
750
751 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
752
753 # If NO_REBUILD is set then break the dependencies on everything but
754 # the source files so we can test documentation without rebuilding
755 # rustdoc etc.
756 ifeq ($(NO_REBUILD),)
757 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
758         $$(D)/$(4).md \
759         $$(TEST_SREQ$(1)_T_$(2)_H_$(3))                         \
760         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
761 else
762 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(D)/$(4).md
763 endif
764
765 ifeq ($(2),$$(CFG_BUILD))
766 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
767         @$$(call E, run doc-$(4) [$(2)])
768         $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< --test-args "$$(TESTARGS)" && touch $$@
769 else
770 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
771         touch $$@
772 endif
773 endef
774
775 $(foreach host,$(CFG_HOST), \
776  $(foreach target,$(CFG_TARGET), \
777   $(foreach stage,$(STAGES), \
778    $(foreach docname,$(DOCS), \
779     $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
780
781 # Crates
782
783 define DEF_CRATE_DOC_TEST
784
785 # If NO_REBUILD is set then break the dependencies on everything but
786 # the source files so we can test crate documentation without
787 # rebuilding any of the parent crates.
788 ifeq ($(NO_REBUILD),)
789 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
790         $$(TEST_SREQ$(1)_T_$(2)_H_$(3))                         \
791         $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))              \
792         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
793 else
794 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
795 endif
796
797 # (Issues #13732, #13983, #14000) The doc for the regex crate includes
798 # uses of the `regex!` macro from the regex_macros crate.  There is
799 # normally a dependence injected that makes the target's regex depend
800 # upon the host's regex_macros (see #13845), but that dependency
801 # injection is currently skipped for stage1 as a special case.
802 #
803 # Therefore, as a further special case, this conditional skips
804 # attempting to run the doc tests for the regex crate atop stage1,
805 # (since there is no regex_macros crate for the stage1 rustc to load).
806 #
807 # (Another approach for solving this would be to inject the desired
808 # dependence for stage1 as well, by setting things up to generate a
809 # regex_macros crate that was compatible with the stage1 rustc and
810 # thus re-enable our ability to run this test.)
811 ifeq (stage$(1)-crate-$(4),stage1-crate-regex)
812 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec:
813         @$$(call E, skipping doc-crate-$(4) as it uses macros and cannot run at stage$(1))
814 else
815 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
816         $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
817 endif
818
819 ifeq ($(2),$$(CFG_BUILD))
820 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
821         @$$(call E, run doc-crate-$(4) [$(2)])
822         $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
823                 $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
824 else
825 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
826         touch $$@
827 endif
828
829 endef
830
831 $(foreach host,$(CFG_HOST), \
832  $(foreach target,$(CFG_TARGET), \
833   $(foreach stage,$(STAGES), \
834    $(foreach crate,$(TEST_DOC_CRATES), \
835     $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
836
837 ######################################################################
838 # Shortcut rules
839 ######################################################################
840
841 TEST_GROUPS = \
842         crates \
843         $(foreach crate,$(TEST_CRATES),$(crate)) \
844         $(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
845         rpass \
846         rpass-full \
847         cfail-full \
848         rfail \
849         cfail \
850         bench \
851         perf \
852         rmake \
853         debuginfo-gdb \
854         debuginfo-lldb \
855         codegen \
856         doc \
857         $(foreach docname,$(DOCS),doc-$(docname)) \
858         pretty \
859         pretty-rpass \
860         pretty-rpass-full \
861         pretty-rfail \
862         pretty-bench \
863         pretty-pretty \
864         $(NULL)
865
866 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
867 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
868 endef
869
870 $(foreach stage,$(STAGES), \
871  $(foreach target,$(CFG_TARGET), \
872   $(foreach host,$(CFG_HOST), \
873    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
874
875 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
876 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
877 endef
878
879 $(foreach stage,$(STAGES), \
880  $(foreach target,$(CFG_TARGET), \
881   $(foreach host,$(CFG_HOST), \
882    $(foreach group,$(TEST_GROUPS), \
883     $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
884
885 define DEF_CHECK_FOR_STAGE
886 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
887 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
888                            check-stage$(1)-H-$$(target))
889 endef
890
891 $(foreach stage,$(STAGES), \
892  $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
893
894 define DEF_CHECK_FOR_STAGE_AND_GROUP
895 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
896 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
897                                check-stage$(1)-H-$$(target)-$(2))
898 endef
899
900 $(foreach stage,$(STAGES), \
901  $(foreach group,$(TEST_GROUPS), \
902   $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
903
904
905 define DEF_CHECK_FOR_STAGE_AND_HOSTS
906 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
907                            check-stage$(1)-T-$$(target)-H-$(2))
908 endef
909
910 $(foreach stage,$(STAGES), \
911  $(foreach host,$(CFG_HOST), \
912   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
913
914 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
915 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
916                                 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
917 endef
918
919 $(foreach stage,$(STAGES), \
920  $(foreach host,$(CFG_HOST), \
921   $(foreach group,$(TEST_GROUPS), \
922    $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
923
924 define DEF_CHECK_DOC_FOR_STAGE
925 check-stage$(1)-docs: $$(foreach docname,$$(DOCS),\
926                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
927                      $$(foreach crate,$$(TEST_DOC_CRATES),\
928                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
929 endef
930
931 $(foreach stage,$(STAGES), \
932  $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))
933
934 define DEF_CHECK_CRATE
935 check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
936 endef
937
938 $(foreach crate,$(TEST_CRATES), \
939  $(eval $(call DEF_CHECK_CRATE,$(crate))))
940
941 ######################################################################
942 # RMAKE rules
943 ######################################################################
944
945 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
946 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
947
948 define DEF_RMAKE_FOR_T_H
949 # $(1) the stage
950 # $(2) target triple
951 # $(3) host triple
952
953
954 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
955 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
956                 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
957
958 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
959                 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
960         @touch $$@
961
962 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
963                 $(S)src/test/run-make/%/Makefile \
964                 $$(CSREQ$(1)_T_$(2)_H_$(3))
965         @rm -rf $(3)/test/run-make/$$*
966         @mkdir -p $(3)/test/run-make/$$*
967         $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
968         $$(MAKE) \
969             $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
970             $(3)/test/run-make/$$* \
971             "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
972             $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
973             "$$(TESTNAME)" \
974             $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
975             "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
976             "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
977             $(1)
978         @touch $$@
979 else
980 # FIXME #11094 - The above rule doesn't work right for multiple targets
981 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
982         @true
983
984 endif
985
986
987 endef
988
989 $(foreach stage,$(STAGES), \
990  $(foreach target,$(CFG_TARGET), \
991   $(foreach host,$(CFG_HOST), \
992    $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))