]> git.lizzy.rs Git - rust.git/blob - mk/tests.mk
libgraphviz: deny warnings in doctests
[rust.git] / mk / tests.mk
1 # Copyright 2012-2014 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
18 # libcore/librustc_unicode tests are in a separate crate
19 DEPS_coretest :=
20 $(eval $(call RUST_CRATE,coretest))
21
22 DEPS_collectionstest :=
23 $(eval $(call RUST_CRATE,collectionstest))
24
25 TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \
26                                   alloc_jemalloc,$(TARGET_CRATES)) \
27                         collectionstest coretest
28 TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz
29 TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \
30                                 rustc_trans rustc_lint,\
31                      $(HOST_CRATES))
32 TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
33
34 ######################################################################
35 # Environment configuration
36 ######################################################################
37
38 # The arguments to all test runners
39 ifdef TESTNAME
40   TESTARGS += $(TESTNAME)
41 endif
42
43 ifdef CHECK_IGNORED
44   TESTARGS += --ignored
45 endif
46
47 # Arguments to the cfail/rfail/rpass/bench tests
48 ifdef CFG_VALGRIND
49   CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
50 endif
51
52 # Arguments to the perf tests
53 ifdef CFG_PERF_TOOL
54   CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
55 endif
56
57 CTEST_TESTARGS := $(TESTARGS)
58
59 # --bench is only relevant for crate tests, not for the compile tests
60 ifdef PLEASE_BENCH
61   TESTARGS += --bench
62 endif
63
64 ifdef VERBOSE
65   CTEST_TESTARGS += --verbose
66 endif
67
68 # Setting locale ensures that gdb's output remains consistent.
69 # This prevents tests from failing with some locales (fixes #17423).
70 export LC_ALL=C
71
72 # If we're running perf then set this environment variable
73 # to put the benchmarks into 'hard mode'
74 ifeq ($(MAKECMDGOALS),perf)
75   export RUST_BENCH=1
76 endif
77
78 TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
79 TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
80
81 define DEF_TARGET_COMMANDS
82
83 ifdef CFG_UNIXY_$(1)
84   CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
85           $$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
86 endif
87
88 ifdef CFG_WINDOWSY_$(1)
89   CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
90    $$(if $$(findstring stage0,$$(1)), \
91        stage0/$$(CFG_LIBDIR_RELATIVE), \
92       $$(if $$(findstring stage1,$$(1)), \
93            stage1/$$(CFG_LIBDIR_RELATIVE), \
94           $$(if $$(findstring stage2,$$(1)), \
95                stage2/$$(CFG_LIBDIR_RELATIVE), \
96                $$(if $$(findstring stage3,$$(1)), \
97                     stage3/$$(CFG_LIBDIR_RELATIVE), \
98                )))))/rustlib/$$(CFG_BUILD)/lib
99   CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
100           $$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
101 endif
102
103 # Run the compiletest runner itself under valgrind
104 ifdef CTEST_VALGRIND
105 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
106       $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
107 else
108 CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
109       $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
110 endif
111
112 endef
113
114 $(foreach target,$(CFG_TARGET), \
115   $(eval $(call DEF_TARGET_COMMANDS,$(target))))
116
117 # Target platform specific variables for android
118 define DEF_ADB_DEVICE_STATUS
119 CFG_ADB_DEVICE_STATUS=$(1)
120 endef
121
122 $(foreach target,$(CFG_TARGET), \
123   $(if $(findstring android, $(target)), \
124     $(if $(findstring adb,$(CFG_ADB)), \
125       $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
126         $(info check: android device attached) \
127         $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
128         $(info check: android device not attached) \
129         $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
130       ), \
131       $(info check: adb not found) \
132       $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
133     ), \
134   ) \
135 )
136
137 ifeq ($(CFG_ADB_DEVICE_STATUS),true)
138 CFG_ADB_TEST_DIR=/data/tmp
139
140 $(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
141  $(shell $(CFG_ADB) remount 1>/dev/null) \
142  $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
143  $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
144  $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
145  $(foreach target,$(CFG_TARGET), \
146   $(if $(findstring android, $(target)), \
147    $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/$(target)) \
148    $(foreach crate,$(TARGET_CRATES), \
149     $(shell $(CFG_ADB) push $(TLIB2_T_$(target)_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_$(target),$(crate)) \
150                     $(CFG_ADB_TEST_DIR)/$(target))), \
151  )))
152 else
153 CFG_ADB_TEST_DIR=
154 endif
155
156 # $(1) - name of doc test
157 # $(2) - file of the test
158 define DOCTEST
159 DOC_NAMES := $$(DOC_NAMES) $(1)
160 DOCFILE_$(1) := $(2)
161 endef
162
163 $(foreach doc,$(DOCS), \
164   $(eval $(call DOCTEST,md-$(doc),$(S)src/doc/$(doc).md)))
165 $(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
166   $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/%.md=trpl-%),$(file))))
167 $(foreach file,$(wildcard $(S)src/doc/nomicon/*.md), \
168   $(eval $(call DOCTEST,$(file:$(S)src/doc/nomicon/%.md=nomicon-%),$(file))))
169 ######################################################################
170 # Main test targets
171 ######################################################################
172
173 # The main testing target. Tests lots of stuff.
174 check: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2 tidy
175         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
176
177 # As above but don't bother running tidy.
178 check-notidy: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2
179         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
180
181 # A slightly smaller set of tests for smoke testing.
182 check-lite: check-sanitycheck cleantestlibs cleantmptestlogs \
183         $(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
184         check-stage2-rpass check-stage2-rpass-valgrind \
185         check-stage2-rfail check-stage2-cfail check-stage2-pfail check-stage2-rmake
186         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
187
188 # Only check the 'reference' tests: rpass/cfail/rfail/rmake.
189 check-ref: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-rpass \
190         check-stage2-rpass-valgrind check-stage2-rfail check-stage2-cfail check-stage2-pfail \
191         check-stage2-rmake
192         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
193
194 # Only check the docs.
195 check-docs: check-sanitycheck cleantestlibs cleantmptestlogs check-stage2-docs
196         $(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
197
198 # Some less critical tests that are not prone to breakage.
199 # Not run as part of the normal test suite, but tested by bors on checkin.
200 check-secondary: check-build-compiletest check-build-lexer-verifier check-lexer check-pretty
201
202 .PHONY: check-sanitycheck
203
204 check-sanitycheck:
205         $(Q)$(CFG_PYTHON) $(S)src/etc/check-sanitycheck.py
206
207 # check + check-secondary.
208 #
209 # Issue #17883: build check-secondary first so hidden dependencies in
210 # e.g. building compiletest are exercised (resolve those by adding
211 # deps to rules that need them; not by putting `check` first here).
212 check-all: check-secondary check
213
214 # Pretty-printing tests.
215 check-pretty: check-stage2-T-$(CFG_BUILD)-H-$(CFG_BUILD)-pretty-exec
216
217 define DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE
218 check-stage$(1)-build-compiletest:      $$(HBIN$(1)_H_$(CFG_BUILD))/compiletest$$(X_$(CFG_BUILD))
219 endef
220
221 $(foreach stage,$(STAGES), \
222  $(eval $(call DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE,$(stage))))
223
224 check-build-compiletest: \
225         check-stage1-build-compiletest \
226         check-stage2-build-compiletest
227
228 .PHONY: cleantmptestlogs cleantestlibs
229
230 cleantmptestlogs:
231         $(Q)rm -f tmp/*.log
232
233 cleantestlibs:
234         $(Q)find $(CFG_BUILD)/test \
235          -name '*.[odasS]' -o \
236          -name '*.so' -o \
237          -name '*.dylib' -o \
238          -name '*.dll' -o \
239          -name '*.def' -o \
240          -name '*.bc' -o \
241          -name '*.dSYM' -o \
242          -name '*.libaux' -o \
243          -name '*.out' -o \
244          -name '*.err' -o \
245          -name '*.debugger.script' \
246          | xargs rm -rf
247
248
249 ######################################################################
250 # Tidy
251 ######################################################################
252
253 ifdef CFG_NOTIDY
254 .PHONY: tidy
255 tidy:
256 else
257
258 # Run the tidy script in multiple parts to avoid huge 'echo' commands
259 .PHONY: tidy
260 tidy: tidy-basic tidy-binaries tidy-errors tidy-features
261
262 endif
263
264 .PHONY: tidy-basic
265 tidy-basic:
266                 @$(call E, check: formatting)
267                 $(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
268
269 .PHONY: tidy-binaries
270 tidy-binaries:
271                 @$(call E, check: binaries)
272                 $(Q)find $(S)src -type f \
273                     \( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
274                     -not -name '*.rs' -and -not -name '*.py' \
275                     -and -not -name '*.sh' -and -not -name '*.pp' \
276                 | grep '^$(S)src/jemalloc' -v \
277                 | grep '^$(S)src/libuv' -v \
278                 | grep '^$(S)src/llvm' -v \
279                 | grep '^$(S)src/rt/hoedown' -v \
280                 | grep '^$(S)src/gyp' -v \
281                 | grep '^$(S)src/etc' -v \
282                 | grep '^$(S)src/doc' -v \
283                 | grep '^$(S)src/compiler-rt' -v \
284                 | grep '^$(S)src/libbacktrace' -v \
285                 | grep '^$(S)src/rust-installer' -v \
286                 | grep '^$(S)src/liblibc' -v \
287                 | xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
288
289 .PHONY: tidy-errors
290 tidy-errors:
291                 @$(call E, check: extended errors)
292                 $(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
293
294 .PHONY: tidy-features
295 tidy-features:
296                 @$(call E, check: feature sanity)
297                 $(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
298
299
300 ######################################################################
301 # Sets of tests
302 ######################################################################
303
304 define DEF_TEST_SETS
305
306 check-stage$(1)-T-$(2)-H-$(3)-exec: \
307         check-stage$(1)-T-$(2)-H-$(3)-rpass-exec \
308         check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
309         check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
310         check-stage$(1)-T-$(2)-H-$(3)-pfail-exec \
311     check-stage$(1)-T-$(2)-H-$(3)-rpass-valgrind-exec \
312     check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
313     check-stage$(1)-T-$(2)-H-$(3)-rfail-full-exec \
314         check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
315         check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
316         check-stage$(1)-T-$(2)-H-$(3)-rustdocck-exec \
317         check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
318         check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
319         check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
320         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
321         check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
322         check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
323         check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
324         check-stage$(1)-T-$(2)-H-$(3)-pretty-exec
325
326 # Only test the compiler-dependent crates when the target is
327 # able to build a compiler (when the target triple is in the set of host triples)
328 ifneq ($$(findstring $(2),$$(CFG_HOST)),)
329
330 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
331         $$(foreach crate,$$(TEST_CRATES), \
332            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
333
334 else
335
336 check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
337         $$(foreach crate,$$(TEST_TARGET_CRATES), \
338            check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)
339
340 endif
341
342 check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
343         $$(foreach crate,$$(TEST_DOC_CRATES), \
344            check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
345
346 check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
347         $$(foreach docname,$$(DOC_NAMES), \
348            check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec) \
349
350 check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
351         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
352     check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-valgrind-exec \
353         check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec \
354         check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
355         check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-full-exec \
356         check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
357         check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
358
359 endef
360
361 $(foreach host,$(CFG_HOST), \
362  $(foreach target,$(CFG_TARGET), \
363   $(foreach stage,$(STAGES), \
364     $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))
365
366
367 ######################################################################
368 # Crate testing
369 ######################################################################
370
371 define TEST_RUNNER
372
373 # If NO_REBUILD is set then break the dependencies on everything but
374 # the source files so we can test crates without rebuilding any of the
375 # parent crates.
376 ifeq ($(NO_REBUILD),)
377 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
378                             $$(foreach crate,$$(TARGET_CRATES), \
379                                 $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
380                                 $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
381
382 else
383 TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
384 endif
385
386 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
387 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
388                 $$(CRATEFILE_$(4)) \
389                 $$(TESTDEP_$(1)_$(2)_$(3)_$(4))
390         @$$(call E, rustc: $$@)
391         $(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
392             $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \
393                 -L "$$(RT_OUTPUT_DIR_$(2))" \
394                 $$(LLVM_LIBDIR_RUSTFLAGS_$(2)) \
395                 $$(RUSTFLAGS_$(4))
396
397 endef
398
399 $(foreach host,$(CFG_HOST), \
400  $(eval $(foreach target,$(CFG_TARGET), \
401   $(eval $(foreach stage,$(STAGES), \
402    $(eval $(foreach crate,$(TEST_CRATES), \
403     $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
404
405 define DEF_TEST_CRATE_RULES
406 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
407
408 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
409                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
410         @$$(call E, run: $$<)
411         $$(Q)touch $$@.start_time
412         $$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
413             --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
414             $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
415             && touch -r $$@.start_time $$@ && rm $$@.start_time
416 endef
417
418 define DEF_TEST_CRATE_RULES_android
419 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
420
421 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
422                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
423         @$$(call E, run: $$< via adb)
424         $$(Q)touch $$@.start_time
425         $$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
426         $$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=./$(2) \
427                 ./$$(notdir $$<) \
428                 --logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
429                 $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
430                 > tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
431         $$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
432         $$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
433         $$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
434         $$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
435         @if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
436         then \
437                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
438                 touch -r $$@.start_time $$@ && rm $$@.start_time; \
439         else \
440                 rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
441                 exit 101; \
442         fi
443 endef
444
445 define DEF_TEST_CRATE_RULES_null
446 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
447
448 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
449                 $(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
450         @$$(call E, failing: no device for $$< )
451         false
452 endef
453
454 $(foreach host,$(CFG_HOST), \
455  $(foreach target,$(CFG_TARGET), \
456   $(foreach stage,$(STAGES), \
457    $(foreach crate, $(TEST_CRATES), \
458     $(if $(findstring $(target),$(CFG_BUILD)), \
459      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
460      $(if $(findstring android, $(target)), \
461       $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
462        $(eval $(call DEF_TEST_CRATE_RULES_android,$(stage),$(target),$(host),$(crate))), \
463        $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
464       ), \
465       $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
466      ))))))
467
468 ######################################################################
469 # Rules for the compiletest tests (rpass, rfail, etc.)
470 ######################################################################
471
472 RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
473 RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
474 RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
475 RFAIL_FULL_RS := $(wildcard $(S)src/test/run-fail-fulldeps/*.rs)
476 CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
477 RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
478 CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
479 PFAIL_RS := $(wildcard $(S)src/test/parse-fail/*.rs)
480 BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
481 PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
482 DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
483 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
484 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
485 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
486 RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
487
488 # perf tests are the same as bench tests only they run under
489 # a performance monitor.
490 PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
491
492 RPASS_TESTS := $(RPASS_RS)
493 RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
494 RPASS_FULL_TESTS := $(RPASS_FULL_RS)
495 RFAIL_FULL_TESTS := $(RFAIL_FULL_RS)
496 CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
497 RFAIL_TESTS := $(RFAIL_RS)
498 CFAIL_TESTS := $(CFAIL_RS)
499 PFAIL_TESTS := $(PFAIL_RS)
500 BENCH_TESTS := $(BENCH_RS)
501 PERF_TESTS := $(PERF_RS)
502 PRETTY_TESTS := $(PRETTY_RS)
503 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
504 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
505 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
506 RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
507
508 CTEST_SRC_BASE_rpass = run-pass
509 CTEST_BUILD_BASE_rpass = run-pass
510 CTEST_MODE_rpass = run-pass
511 CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
512
513 CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
514 CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
515 CTEST_MODE_rpass-valgrind = run-pass-valgrind
516 CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)
517
518 CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
519 CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
520 CTEST_MODE_rpass-full = run-pass
521 CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)
522
523 CTEST_SRC_BASE_rfail-full = run-fail-fulldeps
524 CTEST_BUILD_BASE_rfail-full = run-fail-fulldeps
525 CTEST_MODE_rfail-full = run-fail
526 CTEST_RUNTOOL_rfail-full = $(CTEST_RUNTOOL)
527
528 CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
529 CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
530 CTEST_MODE_cfail-full = compile-fail
531 CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)
532
533 CTEST_SRC_BASE_rfail = run-fail
534 CTEST_BUILD_BASE_rfail = run-fail
535 CTEST_MODE_rfail = run-fail
536 CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)
537
538 CTEST_SRC_BASE_cfail = compile-fail
539 CTEST_BUILD_BASE_cfail = compile-fail
540 CTEST_MODE_cfail = compile-fail
541 CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)
542
543 CTEST_SRC_BASE_pfail = parse-fail
544 CTEST_BUILD_BASE_pfail = parse-fail
545 CTEST_MODE_pfail = parse-fail
546 CTEST_RUNTOOL_pfail = $(CTEST_RUNTOOL)
547
548 CTEST_SRC_BASE_bench = bench
549 CTEST_BUILD_BASE_bench = bench
550 CTEST_MODE_bench = run-pass
551 CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)
552
553 CTEST_SRC_BASE_perf = bench
554 CTEST_BUILD_BASE_perf = perf
555 CTEST_MODE_perf = run-pass
556 CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)
557
558 CTEST_SRC_BASE_debuginfo-gdb = debuginfo
559 CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
560 CTEST_MODE_debuginfo-gdb = debuginfo-gdb
561 CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)
562
563 CTEST_SRC_BASE_debuginfo-lldb = debuginfo
564 CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
565 CTEST_MODE_debuginfo-lldb = debuginfo-lldb
566 CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
567
568 CTEST_SRC_BASE_codegen = codegen
569 CTEST_BUILD_BASE_codegen = codegen
570 CTEST_MODE_codegen = codegen
571 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
572
573 CTEST_SRC_BASE_rustdocck = rustdoc
574 CTEST_BUILD_BASE_rustdocck = rustdoc
575 CTEST_MODE_rustdocck = rustdoc
576 CTEST_RUNTOOL_rustdocck = $(CTEST_RUNTOOL)
577
578 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
579 # disabled and the associated message to be printed as a warning
580 # during attempts to run those tests.
581
582 ifeq ($(CFG_GDB),)
583 CTEST_DISABLE_debuginfo-gdb = "no gdb found"
584 endif
585
586 ifeq ($(CFG_LLDB),)
587 CTEST_DISABLE_debuginfo-lldb = "no lldb found"
588 endif
589
590 ifneq ($(CFG_OSTYPE),apple-darwin)
591 CTEST_DISABLE_debuginfo-lldb = "lldb tests are only run on darwin"
592 endif
593
594 ifeq ($(CFG_OSTYPE),apple-darwin)
595 CTEST_DISABLE_debuginfo-gdb = "gdb on darwin needs root"
596 endif
597
598 ifeq ($(findstring android, $(CFG_TARGET)), android)
599 CTEST_DISABLE_debuginfo-gdb =
600 CTEST_DISABLE_debuginfo-lldb = "lldb tests are disabled on android"
601 endif
602
603 ifeq ($(findstring msvc,$(CFG_TARGET)),msvc)
604 CTEST_DISABLE_debuginfo-gdb = "gdb tests are disabled on MSVC"
605 endif
606
607 # CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
608 # test group to be disabled *unless* the target is able to build a
609 # compiler (i.e. when the target triple is in the set of of host
610 # triples).  The associated message will be printed as a warning
611 # during attempts to run those tests.
612
613 define DEF_CTEST_VARS
614
615 # All the per-stage build rules you might want to call from the
616 # command line.
617 #
618 # $(1) is the stage number
619 # $(2) is the target triple to test
620 # $(3) is the host triple to test
621
622 # Prerequisites for compiletest tests
623 TEST_SREQ$(1)_T_$(2)_H_$(3) = \
624         $$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
625         $$(SREQ$(1)_T_$(2)_H_$(3))
626
627 # Rules for the cfail/rfail/rpass/bench/perf test runner
628
629 # The tests select when to use debug configuration on their own;
630 # remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
631 CTEST_RUSTC_FLAGS := $$(subst -C debug-assertions,,$$(subst -C debug-assertions=on,,$$(CFG_RUSTC_FLAGS)))
632
633 # The tests cannot be optimized while the rest of the compiler is optimized, so
634 # filter out the optimization (if any) from rustc and then figure out if we need
635 # to be optimized
636 CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
637 ifndef CFG_DISABLE_OPTIMIZE_TESTS
638 CTEST_RUSTC_FLAGS += -O
639 endif
640
641 # Analogously to the above, whether to pass `-g` when compiling tests
642 # is a separate choice from whether to pass `-g` when building the
643 # compiler and standard library themselves.
644 CTEST_RUSTC_FLAGS := $$(subst -g,,$$(CTEST_RUSTC_FLAGS))
645 ifdef CFG_ENABLE_DEBUGINFO_TESTS
646 CTEST_RUSTC_FLAGS += -g
647 endif
648
649 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
650                 --compile-lib-path $$(HLIB$(1)_H_$(3)) \
651         --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
652         --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
653         --rustdoc-path $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
654         --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
655         --aux-base $$(S)src/test/auxiliary/ \
656         --stage-id stage$(1)-$(2) \
657         --target $(2) \
658         --host $(3) \
659         --python $$(CFG_PYTHON) \
660         --gdb-version="$(CFG_GDB_VERSION)" \
661         --lldb-version="$(CFG_LLDB_VERSION)" \
662         --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
663         --adb-path=$(CFG_ADB) \
664         --adb-test-dir=$(CFG_ADB_TEST_DIR) \
665         --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
666         --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
667         --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
668         $$(CTEST_TESTARGS)
669
670 ifdef CFG_VALGRIND_RPASS
671 ifdef GOOD_VALGRIND_$(2)
672 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
673 endif
674 endif
675
676 ifndef CFG_DISABLE_VALGRIND_RPASS
677 ifdef GOOD_VALGRIND_$(2)
678 CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind
679 endif
680 endif
681
682 CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
683 CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
684 CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
685 CTEST_DEPS_rfail-full_$(1)-T-$(2)-H-$(3) = $$(RFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
686 CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
687 CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
688 CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
689 CTEST_DEPS_pfail_$(1)-T-$(2)-H-$(3) = $$(PFAIL_TESTS)
690 CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
691 CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
692 CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
693 CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
694                                                $(S)src/etc/lldb_batchmode.py \
695                                                $(S)src/etc/lldb_rust_formatters.py
696 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
697 CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
698         $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
699         $(S)src/etc/htmldocck.py
700
701 endef
702
703 $(foreach host,$(CFG_HOST), \
704  $(eval $(foreach target,$(CFG_TARGET), \
705   $(eval $(foreach stage,$(STAGES), \
706    $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
707
708 define DEF_RUN_COMPILETEST
709
710 CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
711         $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
712         --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
713         --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
714         --mode $$(CTEST_MODE_$(4)) \
715         $$(CTEST_RUNTOOL_$(4))
716
717 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
718
719 # CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
720 # Goal: leave this variable as empty string if we should run the test.
721 # Otherwise, set it to the reason we are not running the test.
722 # (Encoded as a separate variable because GNU make does not have a
723 # good way to express OR on ifeq commands)
724
725 ifneq ($$(CTEST_DISABLE_$(4)),)
726 # Test suite is disabled for all configured targets.
727 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
728 else
729 # else, check if non-self-hosted target (i.e. target not-in hosts) ...
730 ifeq ($$(findstring $(2),$$(CFG_HOST)),)
731 # ... if so, then check if this test suite is disabled for non-selfhosts.
732 ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
733 # Test suite is disabled for this target.
734 CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
735 endif
736 endif
737 # Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
738 endif
739
740 ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
741 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
742                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
743                 $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
744         @$$(call E, run $(4) [$(2)]: $$<)
745         $$(Q)touch $$@.start_time
746         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
747                 $$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
748                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
749                 && touch -r $$@.start_time $$@ && rm $$@.start_time
750
751 else
752
753 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
754         @$$(call E, run $(4) [$(2)]: $$<)
755         @$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
756         touch $$@
757
758 endif
759
760 endef
761
762 CTEST_NAMES = rpass rpass-valgrind rpass-full rfail-full cfail-full rfail cfail pfail \
763         bench perf debuginfo-gdb debuginfo-lldb codegen rustdocck
764
765 $(foreach host,$(CFG_HOST), \
766  $(eval $(foreach target,$(CFG_TARGET), \
767   $(eval $(foreach stage,$(STAGES), \
768    $(eval $(foreach name,$(CTEST_NAMES), \
769    $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
770
771 PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail-full pretty-rfail \
772     pretty-bench pretty-pretty
773 PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
774 PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
775 PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
776 PRETTY_DEPS_pretty-rfail-full = $(RFAIL_FULL_TESTS)
777 PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
778 PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
779 PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
780 PRETTY_DIRNAME_pretty-rpass = run-pass
781 PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
782 PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
783 PRETTY_DIRNAME_pretty-rfail-full = run-fail-fulldeps
784 PRETTY_DIRNAME_pretty-rfail = run-fail
785 PRETTY_DIRNAME_pretty-bench = bench
786 PRETTY_DIRNAME_pretty-pretty = pretty
787
788 define DEF_PRETTY_FULLDEPS
789 PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rpass-full = $$(CSREQ$(1)_T_$(3)_H_$(3))
790 PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rfail-full = $$(CSREQ$(1)_T_$(3)_H_$(3))
791 endef
792
793 $(foreach host,$(CFG_HOST), \
794  $(foreach target,$(CFG_TARGET), \
795   $(foreach stage,$(STAGES), \
796    $(eval $(call DEF_PRETTY_FULLDEPS,$(stage),$(target),$(host))))))
797
798 define DEF_RUN_PRETTY_TEST
799
800 PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
801                 $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
802         --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
803         --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
804         --mode pretty
805
806 check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))
807
808 $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
809                 $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
810                 $$(PRETTY_DEPS_$(4)) \
811                 $$(PRETTY_DEPS$(1)_T_$(2)_H_$(3)_$(4))
812         @$$(call E, run pretty-rpass [$(2)]: $$<)
813         $$(Q)touch $$@.start_time
814         $$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
815                 $$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
816                 --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
817                 && touch -r $$@.start_time $$@ && rm $$@.start_time
818
819 endef
820
821 $(foreach host,$(CFG_HOST), \
822  $(foreach target,$(CFG_TARGET), \
823   $(foreach stage,$(STAGES), \
824    $(foreach pretty-name,$(PRETTY_NAMES), \
825     $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
826
827
828 ######################################################################
829 # Crate & freestanding documentation tests
830 ######################################################################
831
832 define DEF_RUSTDOC
833 RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
834 RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
835 endef
836
837 $(foreach host,$(CFG_HOST), \
838  $(foreach target,$(CFG_TARGET), \
839   $(foreach stage,$(STAGES), \
840    $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))
841
842 # Freestanding
843
844 define DEF_DOC_TEST
845
846 check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
847
848 # If NO_REBUILD is set then break the dependencies on everything but
849 # the source files so we can test documentation without rebuilding
850 # rustdoc etc.
851 ifeq ($(NO_REBUILD),)
852 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
853         $$(DOCFILE_$(4)) \
854         $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
855         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
856 else
857 DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(DOCFILE_$(4))
858 endif
859
860 ifeq ($(2),$$(CFG_BUILD))
861 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
862         @$$(call E, run doc-$(4) [$(2)])
863         $$(Q)touch $$@.start_time
864         $$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< \
865                 --test-args "$$(TESTARGS)" && \
866                 touch -r $$@.start_time $$@ && rm $$@.start_time
867 else
868 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
869         touch $$@
870 endif
871 endef
872
873 $(foreach host,$(CFG_HOST), \
874  $(foreach target,$(CFG_TARGET), \
875   $(foreach stage,$(STAGES), \
876    $(foreach docname,$(DOC_NAMES), \
877     $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))
878
879 # Crates
880
881 define DEF_CRATE_DOC_TEST
882
883 # If NO_REBUILD is set then break the dependencies on everything but
884 # the source files so we can test crate documentation without
885 # rebuilding any of the parent crates.
886 ifeq ($(NO_REBUILD),)
887 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
888         $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
889         $$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
890         $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
891 else
892 CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
893 endif
894
895 check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
896         $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
897
898 ifeq ($(2),$$(CFG_BUILD))
899 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
900         @$$(call E, run doc-crate-$(4) [$(2)])
901         $$(Q)touch $$@.start_time
902         $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(2)) \
903             $$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
904                 $$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && \
905                 touch -r $$@.start_time $$@ && rm $$@.start_time
906 else
907 $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
908         touch $$@
909 endif
910
911 endef
912
913 $(foreach host,$(CFG_HOST), \
914  $(foreach target,$(CFG_TARGET), \
915   $(foreach stage,$(STAGES), \
916    $(foreach crate,$(TEST_DOC_CRATES), \
917     $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
918
919 ######################################################################
920 # Shortcut rules
921 ######################################################################
922
923 TEST_GROUPS = \
924         crates \
925         $(foreach crate,$(TEST_CRATES),$(crate)) \
926         $(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
927         rpass \
928     rpass-valgrind \
929         rpass-full \
930         rfail-full \
931         cfail-full \
932         rfail \
933         cfail \
934         pfail \
935         bench \
936         perf \
937         rmake \
938         rustdocck \
939         debuginfo-gdb \
940         debuginfo-lldb \
941         codegen \
942         doc \
943         $(foreach docname,$(DOC_NAMES),doc-$(docname)) \
944         pretty \
945         pretty-rpass \
946     pretty-rpass-valgrind \
947         pretty-rpass-full \
948         pretty-rfail-full \
949         pretty-rfail \
950         pretty-bench \
951         pretty-pretty \
952         $(NULL)
953
954 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
955 check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
956 endef
957
958 $(foreach stage,$(STAGES), \
959  $(foreach target,$(CFG_TARGET), \
960   $(foreach host,$(CFG_HOST), \
961    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
962
963 define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
964 check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
965 endef
966
967 $(foreach stage,$(STAGES), \
968  $(foreach target,$(CFG_TARGET), \
969   $(foreach host,$(CFG_HOST), \
970    $(foreach group,$(TEST_GROUPS), \
971     $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
972
973 define DEF_CHECK_FOR_STAGE
974 check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
975 check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
976                            check-stage$(1)-H-$$(target))
977 endef
978
979 $(foreach stage,$(STAGES), \
980  $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
981
982 define DEF_CHECK_FOR_STAGE_AND_GROUP
983 check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
984 check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
985                                check-stage$(1)-H-$$(target)-$(2))
986 endef
987
988 $(foreach stage,$(STAGES), \
989  $(foreach group,$(TEST_GROUPS), \
990   $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
991
992
993 define DEF_CHECK_FOR_STAGE_AND_HOSTS
994 check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
995                            check-stage$(1)-T-$$(target)-H-$(2))
996 endef
997
998 $(foreach stage,$(STAGES), \
999  $(foreach host,$(CFG_HOST), \
1000   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))
1001
1002 define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
1003 check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
1004                                 check-stage$(1)-T-$$(target)-H-$(2)-$(3))
1005 endef
1006
1007 $(foreach stage,$(STAGES), \
1008  $(foreach host,$(CFG_HOST), \
1009   $(foreach group,$(TEST_GROUPS), \
1010    $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
1011
1012 define DEF_CHECK_DOC_FOR_STAGE
1013 check-stage$(1)-docs: $$(foreach docname,$$(DOC_NAMES), \
1014                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
1015                      $$(foreach crate,$$(TEST_DOC_CRATES), \
1016                        check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
1017 endef
1018
1019 $(foreach stage,$(STAGES), \
1020  $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))
1021
1022 define DEF_CHECK_CRATE
1023 check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
1024 endef
1025
1026 $(foreach crate,$(TEST_CRATES), \
1027  $(eval $(call DEF_CHECK_CRATE,$(crate))))
1028
1029 ######################################################################
1030 # RMAKE rules
1031 ######################################################################
1032
1033 RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
1034 RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
1035
1036 define DEF_RMAKE_FOR_T_H
1037 # $(1) the stage
1038 # $(2) target triple
1039 # $(3) host triple
1040
1041
1042 ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
1043 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
1044                 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
1045
1046 $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
1047                 $$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
1048         @touch $$@
1049
1050 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
1051         export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(3)))
1052 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
1053         export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(3)))
1054 $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
1055                 $(S)src/test/run-make/%/Makefile \
1056                 $$(CSREQ$(1)_T_$(2)_H_$(3))
1057         @rm -rf $(3)/test/run-make/$$*
1058         @mkdir -p $(3)/test/run-make/$$*
1059         $$(Q)touch $$@.start_time
1060         $$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
1061         $$(MAKE) \
1062             $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
1063             $(3)/test/run-make/$$* \
1064             '$$(CC_$(3))' \
1065             "$$(CFG_GCCISH_CFLAGS_$(3))" \
1066             $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
1067             "$$(TESTNAME)" \
1068             $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
1069             "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
1070             "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
1071             $(1) \
1072             $$(S) \
1073             $(3)
1074         @touch -r $$@.start_time $$@ && rm $$@.start_time
1075 else
1076 # FIXME #11094 - The above rule doesn't work right for multiple targets
1077 check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
1078         @true
1079
1080 endif
1081
1082
1083 endef
1084
1085 $(foreach stage,$(STAGES), \
1086  $(foreach target,$(CFG_TARGET), \
1087   $(foreach host,$(CFG_HOST), \
1088    $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))