tests.mk 34.6 KB
Newer Older
N
Nick Cameron 已提交
1
# Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

11

G
Graydon Hoare 已提交
12
######################################################################
13
# Test variables
G
Graydon Hoare 已提交
14 15
######################################################################

16
# The names of crates that must be tested
17

K
kwantam 已提交
18
# libcore/libunicode tests are in a separate crate
19 20 21
DEPS_coretest :=
$(eval $(call RUST_CRATE,coretest))

K
kwantam 已提交
22
TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) coretest
23
TEST_DOC_CRATES = $(DOC_CRATES)
24 25
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve rustc_trans,\
                     $(HOST_CRATES))
26
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
G
Graydon Hoare 已提交
27

28 29 30
######################################################################
# Environment configuration
######################################################################
31

B
Brian Anderson 已提交
32 33 34 35 36
# The arguments to all test runners
ifdef TESTNAME
  TESTARGS += $(TESTNAME)
endif

37
ifdef CHECK_IGNORED
B
Brian Anderson 已提交
38 39 40
  TESTARGS += --ignored
endif

41
TEST_BENCH =
42

B
Brian Anderson 已提交
43 44 45
# Arguments to the cfail/rfail/rpass/bench tests
ifdef CFG_VALGRIND
  CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
46
  TEST_BENCH =
B
Brian Anderson 已提交
47
endif
48

49 50
ifdef PLEASE_BENCH
  TEST_BENCH = --bench
B
Brian Anderson 已提交
51
endif
52

53 54 55 56 57
# Arguments to the perf tests
ifdef CFG_PERF_TOOL
  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
endif

B
Brian Anderson 已提交
58
CTEST_TESTARGS := $(TESTARGS)
G
Graydon Hoare 已提交
59

B
Brian Anderson 已提交
60 61 62
ifdef VERBOSE
  CTEST_TESTARGS += --verbose
endif
63

64 65 66 67
# Setting locale ensures that gdb's output remains consistent.
# This prevents tests from failing with some locales (fixes #17423).
export LC_ALL=C

68 69 70
# If we're running perf then set this environment variable
# to put the benchmarks into 'hard mode'
ifeq ($(MAKECMDGOALS),perf)
71
  export RUST_BENCH=1
72 73
endif

74 75
TEST_LOG_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
TEST_OK_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).ok
76

77 78 79
define DEF_TARGET_COMMANDS

ifdef CFG_UNIXY_$(1)
A
Alex Crichton 已提交
80 81
  CFG_RUN_TEST_$(1)=$$(TARGET_RPATH_VAR$$(2)_T_$$(3)_H_$$(4)) \
	  $$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
82 83 84
endif

ifdef CFG_WINDOWSY_$(1)
C
Chris Morgan 已提交
85
  CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
86
   $$(if $$(findstring stage0,$$(1)), \
87
       stage0/$$(CFG_LIBDIR_RELATIVE), \
88
      $$(if $$(findstring stage1,$$(1)), \
89
           stage1/$$(CFG_LIBDIR_RELATIVE), \
90
          $$(if $$(findstring stage2,$$(1)), \
91
               stage2/$$(CFG_LIBDIR_RELATIVE), \
92
               $$(if $$(findstring stage3,$$(1)), \
93
                    stage3/$$(CFG_LIBDIR_RELATIVE), \
94
               )))))/rustlib/$$(CFG_BUILD)/lib
A
Alex Crichton 已提交
95
  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(4)),$$(1))
96 97 98 99
endif

# Run the compiletest runner itself under valgrind
ifdef CTEST_VALGRIND
100
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
A
Alex Crichton 已提交
101
      $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(3),$$(4))
102
else
103 104
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
      $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
105 106 107 108
endif

endef

H
Heather 已提交
109
$(foreach target,$(CFG_TARGET), \
110 111
  $(eval $(call DEF_TARGET_COMMANDS,$(target))))

D
Daniel Micay 已提交
112
# Target platform specific variables
113
# for arm-linux-androidabi
114 115
define DEF_ADB_DEVICE_STATUS
CFG_ADB_DEVICE_STATUS=$(1)
116 117
endef

H
Heather 已提交
118
$(foreach target,$(CFG_TARGET), \
119 120
  $(if $(findstring $(target),"arm-linux-androideabi"), \
    $(if $(findstring adb,$(CFG_ADB)), \
121
      $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
122 123 124 125
        $(info check: android device attached) \
        $(eval $(call DEF_ADB_DEVICE_STATUS, true)), \
        $(info check: android device not attached) \
        $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
126
      ), \
127 128
      $(info check: adb not found) \
      $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
129
    ), \
130 131 132
  ) \
)

133 134
ifeq ($(CFG_ADB_DEVICE_STATUS),true)
CFG_ADB_TEST_DIR=/data/tmp
135

136
$(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
137 138 139 140 141
 $(shell $(CFG_ADB) remount 1>/dev/null) \
 $(shell $(CFG_ADB) shell rm -r $(CFG_ADB_TEST_DIR) >/dev/null) \
 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)) \
 $(shell $(CFG_ADB) shell mkdir $(CFG_ADB_TEST_DIR)/tmp) \
 $(shell $(CFG_ADB) push $(S)src/etc/adb_run_wrapper.sh $(CFG_ADB_TEST_DIR) 1>/dev/null) \
142
 $(foreach crate,$(TARGET_CRATES), \
A
Alex Crichton 已提交
143
    $(shell $(CFG_ADB) push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_arm-linux-androideabi,$(crate)) \
144
                    $(CFG_ADB_TEST_DIR))) \
145
 )
146 147
else
CFG_ADB_TEST_DIR=
148
endif
149

S
Steve Klabnik 已提交
150 151 152 153 154 155 156 157 158
# $(1) - name of doc test
# $(2) - file of the test
define DOCTEST
DOC_NAMES := $$(DOC_NAMES) $(1)
DOCFILE_$(1) := $(2)
endef

$(foreach doc,$(DOCS), \
  $(eval $(call DOCTEST,md-$(doc),$(S)src/doc/$(doc).md)))
159 160
$(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
  $(eval $(call DOCTEST,$(file:$(S)src/doc/trpl/%.md=trpl-%),$(file))))
161

B
Brian Anderson 已提交
162 163 164 165
######################################################################
# Main test targets
######################################################################

166
# The main testing target. Tests lots of stuff.
167
check: cleantmptestlogs cleantestlibs check-notidy tidy
H
Huon Wilson 已提交
168

169
# As above but don't bother running tidy.
H
Huon Wilson 已提交
170
check-notidy: cleantmptestlogs cleantestlibs all check-stage2
171 172
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

173
# A slightly smaller set of tests for smoke testing.
174
check-lite: cleantestlibs cleantmptestlogs \
175
	$(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
N
Nick Cameron 已提交
176
	check-stage2-rpass check-stage2-rpass-valgrind \
A
Alex Crichton 已提交
177
	check-stage2-rfail check-stage2-cfail check-stage2-rmake
178 179
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

180
# Only check the 'reference' tests: rpass/cfail/rfail/rmake.
N
Nick Cameron 已提交
181
check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass check-stage2-rpass-valgrind \
182 183 184
	check-stage2-rfail check-stage2-cfail check-stage2-rmake
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

185
# Only check the docs.
B
Brian Anderson 已提交
186 187 188
check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

189 190
# Some less critical tests that are not prone to breakage.
# Not run as part of the normal test suite, but tested by bors on checkin.
191
check-secondary: check-build-compiletest check-build-lexer-verifier check-lexer check-pretty
192

193
# check + check-secondary.
194 195 196 197 198
#
# Issue #17883: build check-secondary first so hidden dependencies in
# e.g. building compiletest are exercised (resolve those by adding
# deps to rules that need them; not by putting `check` first here).
check-all: check-secondary check
199 200

# Pretty-printing tests.
201 202
check-pretty: check-stage2-T-$(CFG_BUILD)-H-$(CFG_BUILD)-pretty-exec

203 204 205 206 207 208 209 210 211 212 213
define DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE
check-stage$(1)-build-compiletest: 	$$(HBIN$(1)_H_$(CFG_BUILD))/compiletest$$(X_$(CFG_BUILD))
endef

$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_BUILD_COMPILETEST_FOR_STAGE,$(stage))))

check-build-compiletest: \
	check-stage1-build-compiletest \
	check-stage2-build-compiletest

214 215
.PHONY: cleantmptestlogs cleantestlibs

216 217
cleantmptestlogs:
	$(Q)rm -f tmp/*.log
218

219
cleantestlibs:
H
Heather 已提交
220
	$(Q)find $(CFG_BUILD)/test \
221
         -name '*.[odasS]' -o \
222 223 224 225 226 227 228 229 230
         -name '*.so' -o \
         -name '*.dylib' -o \
         -name '*.dll' -o \
         -name '*.def' -o \
         -name '*.bc' -o \
         -name '*.dSYM' -o \
         -name '*.libaux' -o \
         -name '*.out' -o \
         -name '*.err' -o \
B
Brian Leibig 已提交
231
	 -name '*.debugger.script' \
232
         | xargs rm -rf
233

234

235 236 237
######################################################################
# Tidy
######################################################################
B
Brian Anderson 已提交
238

239
ifdef CFG_NOTIDY
B
Brian Anderson 已提交
240
tidy:
241
else
242 243 244 245

ALL_CS := $(wildcard $(S)src/rt/*.cpp \
                     $(S)src/rt/*/*.cpp \
                     $(S)src/rt/*/*/*.cpp \
246
                     $(S)src/rustllvm/*.cpp)
247
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
248 249
		       $(wildcard $(S)src/rt/hoedown/src/*.c) \
		       $(wildcard $(S)src/rt/hoedown/bin/*.c) \
250 251 252 253
	,$(ALL_CS))
ALL_HS := $(wildcard $(S)src/rt/*.h \
                     $(S)src/rt/*/*.h \
                     $(S)src/rt/*/*/*.h \
254
                     $(S)src/rustllvm/*.h)
255 256
ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
                       $(S)src/rt/valgrind/memcheck.h \
257 258 259
                       $(S)src/rt/msvc/typeof.h \
                       $(S)src/rt/msvc/stdint.h \
                       $(S)src/rt/msvc/inttypes.h \
260 261
		       $(wildcard $(S)src/rt/hoedown/src/*.h) \
		       $(wildcard $(S)src/rt/hoedown/bin/*.h) \
262 263
	,$(ALL_HS))

264
# Run the tidy script in multiple parts to avoid huge 'echo' commands
265 266
tidy:
		@$(call E, check: formatting)
267
		$(Q)find $(S)src -name '*.r[sc]' \
268 269 270 271 272 273 274
		    -and -not -regex '^$(S)src/jemalloc.*' \
		    -and -not -regex '^$(S)src/libuv.*' \
		    -and -not -regex '^$(S)src/llvm.*' \
		    -and -not -regex '^$(S)src/gyp.*' \
		    -and -not -regex '^$(S)src/libbacktrace.*' \
		    -print0 \
		| xargs -0 -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
275
		$(Q)find $(S)src/etc -name '*.py' \
276
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
277 278 279 280 281 282 283 284 285 286
		$(Q)find $(S)src/doc -name '*.js' \
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
		$(Q)find $(S)src/etc -name '*.sh' \
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
		$(Q)find $(S)src/etc -name '*.pl' \
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
		$(Q)find $(S)src/etc -name '*.c' \
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
		$(Q)find $(S)src/etc -name '*.h' \
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
287
		$(Q)echo $(ALL_CS) \
288
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
289
		$(Q)echo $(ALL_HS) \
290
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
A
Alex Crichton 已提交
291
		$(Q)find $(S)src -type f -perm +a+x \
292 293
		    -not -name '*.rs' -and -not -name '*.py' \
		    -and -not -name '*.sh' \
D
Daniel Micay 已提交
294
		| grep '^$(S)src/jemalloc' -v \
295
		| grep '^$(S)src/libuv' -v \
D
Daniel Micay 已提交
296
		| grep '^$(S)src/llvm' -v \
297
		| grep '^$(S)src/rt/hoedown' -v \
298 299
		| grep '^$(S)src/gyp' -v \
		| grep '^$(S)src/etc' -v \
300
		| grep '^$(S)src/doc' -v \
301
		| grep '^$(S)src/compiler-rt' -v \
302
		| grep '^$(S)src/libbacktrace' -v \
B
Brian Anderson 已提交
303
		| grep '^$(S)src/rust-installer' -v \
304
		| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
305

S
Steve Klabnik 已提交
306

307
endif
308

309

B
Brian Anderson 已提交
310
######################################################################
311
# Sets of tests
B
Brian Anderson 已提交
312 313
######################################################################

314 315
define DEF_TEST_SETS

316 317 318 319
check-stage$(1)-T-$(2)-H-$(3)-exec: \
	check-stage$(1)-T-$(2)-H-$(3)-rpass-exec \
	check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
	check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
320 321
    check-stage$(1)-T-$(2)-H-$(3)-rpass-valgrind-exec \
    check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
322 323 324 325 326
	check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
	check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
        check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
        check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
	check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
327 328
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
329
	check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
330 331 332
	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-exec

333 334
# Only test the compiler-dependent crates when the target is
# able to build a compiler (when the target triple is in the set of host triples)
H
Heather 已提交
335
ifneq ($$(findstring $(2),$$(CFG_HOST)),)
336

337 338 339 340
check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
	$$(foreach crate,$$(TEST_CRATES), \
           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)

341 342 343 344 345 346 347 348
else

check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
	$$(foreach crate,$$(TEST_TARGET_CRATES), \
           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)

endif

349 350
check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
        $$(foreach crate,$$(TEST_DOC_CRATES), \
351
           check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
352

353
check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
S
Steve Klabnik 已提交
354 355
        $$(foreach docname,$$(DOC_NAMES), \
           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec) \
356 357

check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
358
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
359
    check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-valgrind-exec \
360 361 362
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
363
	check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
364

B
Brian Anderson 已提交
365 366
endef

H
Heather 已提交
367 368
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
369 370 371
  $(foreach stage,$(STAGES), \
    $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))

B
Brian Anderson 已提交
372

373
######################################################################
374
# Crate testing
375 376
######################################################################

377
define TEST_RUNNER
378

379 380 381
# If NO_REBUILD is set then break the dependencies on everything but
# the source files so we can test crates without rebuilding any of the
# parent crates.
382
ifeq ($(NO_REBUILD),)
383
TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
384
			    $$(foreach crate,$$(TARGET_CRATES), \
385 386
				$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
				$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
387

388
else
389
TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
390 391
endif

392
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
393
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): \
394 395
		$$(CRATEFILE_$(4)) \
		$$(TESTDEP_$(1)_$(2)_$(3)_$(4))
396
	@$$(call E, rustc: $$@)
397
	$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(3)) \
R
Richard Diamond 已提交
398
	    $$(subst @,,$$(STAGE$(1)_T_$(2)_H_$(3))) -o $$@ $$< --test \
399 400
		-L "$$(RT_OUTPUT_DIR_$(2))" \
		-L "$$(LLVM_LIBDIR_$(2))" \
A
Alex Crichton 已提交
401
		$$(RUSTFLAGS_$(4))
402

403 404
endef

H
Heather 已提交
405 406
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
407
  $(eval $(foreach stage,$(STAGES), \
408 409
   $(eval $(foreach crate,$(TEST_CRATES), \
    $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
410 411

define DEF_TEST_CRATE_RULES
412 413 414
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
A
Alex Crichton 已提交
415
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
416
	@$$(call E, run: $$<)
A
Alex Crichton 已提交
417
	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(1),$(2),$(3)) $$(TESTARGS) \
418 419 420
	    --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
	    $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
	    && touch $$@
421
endef
422

423 424 425 426
define DEF_TEST_CRATE_RULES_arm-linux-androideabi
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
A
Alex Crichton 已提交
427
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
428
	@$$(call E, run: $$< via adb)
429 430
	$$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
	$$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
431
		./$$(notdir $$<) \
432
		--logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
433
		$$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
434
		> tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
435 436 437 438
	$$(Q)cat tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
	$$(Q)touch tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
	$$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log tmp/
	$$(Q)$(CFG_ADB) shell rm $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log
439 440 441 442 443 444 445 446 447 448 449 450 451 452
	@if grep -q "result: ok" tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
	then \
		rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
		touch $$@; \
	else \
		rm tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp; \
		exit 101; \
	fi
endef

define DEF_TEST_CRATE_RULES_null
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
A
Alex Crichton 已提交
453
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
454 455
	@$$(call E, failing: no device for $$< )
	false
456 457
endef

H
Heather 已提交
458 459
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
460 461
  $(foreach stage,$(STAGES), \
   $(foreach crate, $(TEST_CRATES), \
H
Heather 已提交
462
    $(if $(findstring $(target),$(CFG_BUILD)), \
463 464
     $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
     $(if $(findstring $(target),"arm-linux-androideabi"), \
465
      $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
466 467 468
       $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
       $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
      ), \
469
      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
D
Daniel Micay 已提交
470
     ))))))
471

472 473 474 475 476
######################################################################
# Rules for the compiletest tests (rpass, rfail, etc.)
######################################################################

RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
N
Nick Cameron 已提交
477
RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
478
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
479
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
480 481
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
482
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
483
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
484 485
DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
486 487
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
488

489 490
# perf tests are the same as bench tests only they run under
# a performance monitor.
491
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
492

493 494 495 496 497 498
RPASS_TESTS := $(RPASS_RS)
RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
RPASS_FULL_TESTS := $(RPASS_FULL_RS)
CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
RFAIL_TESTS := $(RFAIL_RS)
CFAIL_TESTS := $(CFAIL_RS)
499 500 501
BENCH_TESTS := $(BENCH_RS)
PERF_TESTS := $(PERF_RS)
PRETTY_TESTS := $(PRETTY_RS)
502 503
DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
504
CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
B
Brian Anderson 已提交
505

506 507 508 509
CTEST_SRC_BASE_rpass = run-pass
CTEST_BUILD_BASE_rpass = run-pass
CTEST_MODE_rpass = run-pass
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
B
Brian Anderson 已提交
510

N
Nick Cameron 已提交
511 512 513 514 515
CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
CTEST_MODE_rpass-valgrind = run-pass-valgrind
CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)

516 517
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
518 519 520
CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)

521 522 523 524 525
CTEST_SRC_BASE_cfail-full = compile-fail-fulldeps
CTEST_BUILD_BASE_cfail-full = compile-fail-fulldeps
CTEST_MODE_cfail-full = compile-fail
CTEST_RUNTOOL_cfail-full = $(CTEST_RUNTOOL)

526 527 528 529 530 531 532 533 534 535
CTEST_SRC_BASE_rfail = run-fail
CTEST_BUILD_BASE_rfail = run-fail
CTEST_MODE_rfail = run-fail
CTEST_RUNTOOL_rfail = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_cfail = compile-fail
CTEST_BUILD_BASE_cfail = compile-fail
CTEST_MODE_cfail = compile-fail
CTEST_RUNTOOL_cfail = $(CTEST_RUNTOOL)

536
CTEST_SRC_BASE_bench = bench
537 538 539 540 541 542 543 544 545
CTEST_BUILD_BASE_bench = bench
CTEST_MODE_bench = run-pass
CTEST_RUNTOOL_bench = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_perf = bench
CTEST_BUILD_BASE_perf = perf
CTEST_MODE_perf = run-pass
CTEST_RUNTOOL_perf = $(CTEST_PERF_RUNTOOL)

546 547 548 549 550 551 552 553 554
CTEST_SRC_BASE_debuginfo-gdb = debuginfo
CTEST_BUILD_BASE_debuginfo-gdb = debuginfo-gdb
CTEST_MODE_debuginfo-gdb = debuginfo-gdb
CTEST_RUNTOOL_debuginfo-gdb = $(CTEST_RUNTOOL)

CTEST_SRC_BASE_debuginfo-lldb = debuginfo
CTEST_BUILD_BASE_debuginfo-lldb = debuginfo-lldb
CTEST_MODE_debuginfo-lldb = debuginfo-lldb
CTEST_RUNTOOL_debuginfo-lldb = $(CTEST_RUNTOOL)
B
Brian Leibig 已提交
555

556 557 558 559 560
CTEST_SRC_BASE_codegen = codegen
CTEST_BUILD_BASE_codegen = codegen
CTEST_MODE_codegen = codegen
CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)

561 562 563 564
# CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
# disabled and the associated message to be printed as a warning
# during attempts to run those tests.

565
ifeq ($(CFG_GDB),)
566 567 568 569 570
CTEST_DISABLE_debuginfo-gdb = "no gdb found"
endif

ifeq ($(CFG_LLDB),)
CTEST_DISABLE_debuginfo-lldb = "no lldb found"
571 572
endif

573 574 575 576
ifeq ($(CFG_CLANG),)
CTEST_DISABLE_codegen = "no clang found"
endif

577 578 579 580
ifneq ($(CFG_OSTYPE),apple-darwin)
CTEST_DISABLE_debuginfo-lldb = "lldb tests are only run on darwin"
endif

581
ifeq ($(CFG_OSTYPE),apple-darwin)
C
Corey Farwell 已提交
582
CTEST_DISABLE_debuginfo-gdb = "gdb on darwin needs root"
583 584
endif

585 586 587 588 589 590
# CTEST_DISABLE_NONSELFHOST_$(TEST_GROUP), if set, will cause that
# test group to be disabled *unless* the target is able to build a
# compiler (i.e. when the target triple is in the set of of host
# triples).  The associated message will be printed as a warning
# during attempts to run those tests.

591 592 593 594 595 596 597 598 599 600 601
define DEF_CTEST_VARS

# All the per-stage build rules you might want to call from the
# command line.
#
# $(1) is the stage number
# $(2) is the target triple to test
# $(3) is the host triple to test

# Prerequisites for compiletest tests
TEST_SREQ$(1)_T_$(2)_H_$(3) = \
602
	$$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
603
	$$(SREQ$(1)_T_$(2)_H_$(3))
B
Brian Anderson 已提交
604

B
Brian Anderson 已提交
605
# Rules for the cfail/rfail/rpass/bench/perf test runner
606

607 608
# The tests select when to use debug configuration on their own;
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
609
CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
610

N
Nick Cameron 已提交
611
# The tests cannot be optimized while the rest of the compiler is optimized, so
612 613 614 615 616 617
# filter out the optimization (if any) from rustc and then figure out if we need
# to be optimized
CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
ifndef CFG_DISABLE_OPTIMIZE_TESTS
CTEST_RUSTC_FLAGS += -O
endif
618

N
Nick Cameron 已提交
619

620 621 622 623
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
		--compile-lib-path $$(HLIB$(1)_H_$(3)) \
        --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
        --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
624
        --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
H
Heather 已提交
625
        --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
626 627 628 629
        --aux-base $$(S)src/test/auxiliary/ \
        --stage-id stage$(1)-$(2) \
        --target $(2) \
        --host $(3) \
630
        --gdb-version="$(CFG_GDB_VERSION)" \
631
        --lldb-version="$(CFG_LLDB_VERSION)" \
632 633 634
        --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
        --adb-path=$(CFG_ADB) \
        --adb-test-dir=$(CFG_ADB_TEST_DIR) \
635
        --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
636
        --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
L
Luqman Aden 已提交
637
        --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
N
Niko Matsakis 已提交
638 639
        $$(CTEST_TESTARGS)

640 641 642 643 644 645 646 647 648 649 650 651 652
ifdef CFG_VALGRIND_RPASS
ifdef GOOD_VALGRIND_$(2)
$(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS))
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
endif
endif

ifndef CFG_DISABLE_VALGRIND_RPASS
ifdef GOOD_VALGRIND_$(2)
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind
endif
endif

653
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
N
Nick Cameron 已提交
654
CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
655
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
656
CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
657 658 659 660
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
CTEST_DEPS_cfail_$(1)-T-$(2)-H-$(3) = $$(CFAIL_TESTS)
CTEST_DEPS_bench_$(1)-T-$(2)-H-$(3) = $$(BENCH_TESTS)
CTEST_DEPS_perf_$(1)-T-$(2)-H-$(3) = $$(PERF_TESTS)
661
CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
662 663 664
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
                                               $(S)src/etc/lldb_batchmode.py \
                                               $(S)src/etc/lldb_rust_formatters.py
665
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
N
Niko Matsakis 已提交
666

667
endef
N
Niko Matsakis 已提交
668

H
Heather 已提交
669 670
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
671 672
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
N
Niko Matsakis 已提交
673

674
define DEF_RUN_COMPILETEST
675

676
CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
677
        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
678
        --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
679 680 681
        --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
        --mode $$(CTEST_MODE_$(4)) \
	$$(CTEST_RUNTOOL_$(4))
N
Niko Matsakis 已提交
682

683 684
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

685 686 687 688 689
# CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)
# Goal: leave this variable as empty string if we should run the test.
# Otherwise, set it to the reason we are not running the test.
# (Encoded as a separate variable because GNU make does not have a
# good way to express OR on ifeq commands)
690

691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
ifneq ($$(CTEST_DISABLE_$(4)),)
# Test suite is disabled for all configured targets.
CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_$(4))
else
# else, check if non-self-hosted target (i.e. target not-in hosts) ...
ifeq ($$(findstring $(2),$$(CFG_HOST)),)
# ... if so, then check if this test suite is disabled for non-selfhosts.
ifneq ($$(CTEST_DISABLE_NONSELFHOST_$(4)),)
# Test suite is disabled for this target.
CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4) := $$(CTEST_DISABLE_NONSELFHOST_$(4))
endif
endif
# Neither DISABLE nor DISABLE_NONSELFHOST is set ==> okay, run the test.
endif

ifeq ($$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)),)
707
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
708 709
		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
710
	@$$(call E, run $(4) [$(2)]: $$<)
711
	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
712
		$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
713 714
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
                && touch $$@
N
Niko Matsakis 已提交
715

716 717
else

718
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
719
	@$$(call E, run $(4) [$(2)]: $$<)
720
	@$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
721 722 723 724
	touch $$@

endif

725
endef
N
Niko Matsakis 已提交
726

N
Nick Cameron 已提交
727
CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
728

H
Heather 已提交
729 730
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
731 732 733 734
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(foreach name,$(CTEST_NAMES), \
   $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))

735
PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
736
PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
737
PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
738 739 740 741
PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
742 743 744 745 746 747 748
# The stage- and host-specific dependencies are for e.g. macro_crate_test which pulls in
# external crates.
PRETTY_DEPS$(1)_H_$(3)_pretty-rpass =
PRETTY_DEPS$(1)_H_$(3)_pretty-rpass-full = $$(HLIB$(1)_H_$(3))/stamp.syntax $$(HLIB$(1)_H_$(3))/stamp.rustc
PRETTY_DEPS$(1)_H_$(3)_pretty-rfail =
PRETTY_DEPS$(1)_H_$(3)_pretty-bench =
PRETTY_DEPS$(1)_H_$(3)_pretty-pretty =
749
PRETTY_DIRNAME_pretty-rpass = run-pass
750
PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
751
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
752 753 754 755 756 757
PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty

define DEF_RUN_PRETTY_TEST

758 759
PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
		$$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3)) \
760 761
        --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
        --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
N
Niko Matsakis 已提交
762 763
        --mode pretty

764 765 766
check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4))

$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
767
	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
768 769
	        $$(PRETTY_DEPS_$(4)) \
	        $$(PRETTY_DEPS$(1)_H_$(3)_$(4))
770
	@$$(call E, run pretty-rpass [$(2)]: $$<)
771
	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
772
		$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
773 774
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
                && touch $$@
N
Niko Matsakis 已提交
775

776
endef
N
Niko Matsakis 已提交
777

H
Heather 已提交
778 779
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
780 781 782
  $(foreach stage,$(STAGES), \
   $(foreach pretty-name,$(PRETTY_NAMES), \
    $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
B
Brian Anderson 已提交
783

784

785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
######################################################################
# Crate & freestanding documentation tests
######################################################################

define DEF_RUSTDOC
RUSTDOC_EXE_$(1)_T_$(2)_H_$(3) := $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3))
RUSTDOC_$(1)_T_$(2)_H_$(3) := $$(RPATH_VAR$(1)_T_$(2)_H_$(3)) $$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
endef

$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
  $(foreach stage,$(STAGES), \
   $(eval $(call DEF_RUSTDOC,$(stage),$(target),$(host))))))

# Freestanding

define DEF_DOC_TEST
802

803
check-stage$(1)-T-$(2)-H-$(3)-doc-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4))
804

805 806 807 808 809
# If NO_REBUILD is set then break the dependencies on everything but
# the source files so we can test documentation without rebuilding
# rustdoc etc.
ifeq ($(NO_REBUILD),)
DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
S
Steve Klabnik 已提交
810
	$$(DOCFILE_$(4)) \
811
	$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
812 813
	$$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
else
S
Steve Klabnik 已提交
814
DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(DOCFILE_$(4))
815
endif
816

817 818 819
ifeq ($(2),$$(CFG_BUILD))
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
	@$$(call E, run doc-$(4) [$(2)])
S
Steve Klabnik 已提交
820 821
	$$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< \
		--test-args "$$(TESTARGS)" && touch $$@
822 823 824 825
else
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
	touch $$@
endif
826
endef
827

H
Heather 已提交
828 829
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
830
  $(foreach stage,$(STAGES), \
S
Steve Klabnik 已提交
831
   $(foreach docname,$(DOC_NAMES), \
832 833 834
    $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))

# Crates
835

836 837
define DEF_CRATE_DOC_TEST

838 839 840 841
# If NO_REBUILD is set then break the dependencies on everything but
# the source files so we can test crate documentation without
# rebuilding any of the parent crates.
ifeq ($(NO_REBUILD),)
842
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
843 844
	$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
	$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4)) \
845
	$$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
846
else
847
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
848 849
endif

850 851
check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
	$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
852

853
ifeq ($(2),$$(CFG_BUILD))
854 855
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
	@$$(call E, run doc-crate-$(4) [$(2)])
856
	$$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(3)) \
R
Richard Diamond 已提交
857
	    $$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test --cfg dox \
858
	    	$$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
859
else
860
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
861 862
	touch $$@
endif
863 864 865 866

endef

$(foreach host,$(CFG_HOST), \
867 868 869 870
 $(foreach target,$(CFG_TARGET), \
  $(foreach stage,$(STAGES), \
   $(foreach crate,$(TEST_DOC_CRATES), \
    $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
871

872 873 874
######################################################################
# Shortcut rules
######################################################################
875

876 877 878
TEST_GROUPS = \
	crates \
	$(foreach crate,$(TEST_CRATES),$(crate)) \
879
	$(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
880
	rpass \
N
Nick Cameron 已提交
881
    rpass-valgrind \
882
	rpass-full \
883
	cfail-full \
884 885 886 887
	rfail \
	cfail \
	bench \
	perf \
A
Alex Crichton 已提交
888
	rmake \
889 890
	debuginfo-gdb \
	debuginfo-lldb \
891
	codegen \
892
	doc \
S
Steve Klabnik 已提交
893
	$(foreach docname,$(DOC_NAMES),doc-$(docname)) \
894 895
	pretty \
	pretty-rpass \
896
    pretty-rpass-valgrind \
897 898 899 900 901 902 903 904 905
	pretty-rpass-full \
	pretty-rfail \
	pretty-bench \
	pretty-pretty \
	$(NULL)

define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST
check-stage$(1)-T-$(2)-H-$(3): check-stage$(1)-T-$(2)-H-$(3)-exec
endef
906

907
$(foreach stage,$(STAGES), \
H
Heather 已提交
908 909
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
910
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
911

912 913 914
define DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP
check-stage$(1)-T-$(2)-H-$(3)-$(4): check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec
endef
B
Brian Anderson 已提交
915

916
$(foreach stage,$(STAGES), \
H
Heather 已提交
917 918
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
919 920
   $(foreach group,$(TEST_GROUPS), \
    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
921

922
define DEF_CHECK_FOR_STAGE
H
Heather 已提交
923 924
check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
925 926
                           check-stage$(1)-H-$$(target))
endef
927

928 929
$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
930

931
define DEF_CHECK_FOR_STAGE_AND_GROUP
H
Heather 已提交
932 933
check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
934 935
                               check-stage$(1)-H-$$(target)-$(2))
endef
936

937 938 939
$(foreach stage,$(STAGES), \
 $(foreach group,$(TEST_GROUPS), \
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
940

941 942

define DEF_CHECK_FOR_STAGE_AND_HOSTS
H
Heather 已提交
943
check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
944
                           check-stage$(1)-T-$$(target)-H-$(2))
B
Brian Anderson 已提交
945
endef
946

947
$(foreach stage,$(STAGES), \
H
Heather 已提交
948
 $(foreach host,$(CFG_HOST), \
949 950 951
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))

define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
H
Heather 已提交
952
check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
953 954 955 956
                                check-stage$(1)-T-$$(target)-H-$(2)-$(3))
endef

$(foreach stage,$(STAGES), \
H
Heather 已提交
957
 $(foreach host,$(CFG_HOST), \
958 959
  $(foreach group,$(TEST_GROUPS), \
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
960

B
Brian Anderson 已提交
961
define DEF_CHECK_DOC_FOR_STAGE
S
Steve Klabnik 已提交
962
check-stage$(1)-docs: $$(foreach docname,$$(DOC_NAMES), \
B
Brian Anderson 已提交
963
                       check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
964
                     $$(foreach crate,$$(TEST_DOC_CRATES), \
965
                       check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
B
Brian Anderson 已提交
966 967 968 969 970 971 972 973 974 975 976 977
endef

$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_DOC_FOR_STAGE,$(stage))))

define DEF_CHECK_CRATE
check-$(1): check-stage2-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-$(1)-exec
endef

$(foreach crate,$(TEST_CRATES), \
 $(eval $(call DEF_CHECK_CRATE,$(crate))))

N
Niko Matsakis 已提交
978
######################################################################
979
# RMAKE rules
N
Niko Matsakis 已提交
980
######################################################################
981

A
Alex Crichton 已提交
982 983 984 985 986 987 988 989
RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)

define DEF_RMAKE_FOR_T_H
# $(1) the stage
# $(2) target triple
# $(3) host triple

990 991

ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
A
Alex Crichton 已提交
992 993 994 995 996 997 998 999 1000
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
		$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)

$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
		$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
	@touch $$@

$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
		$(S)src/test/run-make/%/Makefile \
C
Corey Richardson 已提交
1001
		$$(CSREQ$(1)_T_$(2)_H_$(3))
A
Alex Crichton 已提交
1002 1003
	@rm -rf $(3)/test/run-make/$$*
	@mkdir -p $(3)/test/run-make/$$*
1004
	$$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
1005
        $$(MAKE) \
A
Alex Crichton 已提交
1006
	    $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
A
Alex Crichton 已提交
1007
	    $(3)/test/run-make/$$* \
C
Corey Richardson 已提交
1008
	    "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
1009
	    $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
1010
	    "$$(TESTNAME)" \
1011 1012 1013 1014
	    $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
	    "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
	    "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
	    $(1)
A
Alex Crichton 已提交
1015
	@touch $$@
1016 1017 1018 1019 1020 1021 1022
else
# FIXME #11094 - The above rule doesn't work right for multiple targets
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec:
	@true

endif

A
Alex Crichton 已提交
1023 1024 1025 1026 1027 1028 1029

endef

$(foreach stage,$(STAGES), \
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
   $(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))