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