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