tests.mk 32.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
# Copyright 2012 The Rust Project Developers. See the COPYRIGHT
# 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 18 19
TEST_TARGET_CRATES = $(TARGET_CRATES)
TEST_DOC_CRATES = $(DOC_CRATES)
TEST_HOST_CRATES = $(HOST_CRATES)
20
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
G
Graydon Hoare 已提交
21

22 23 24
######################################################################
# Environment configuration
######################################################################
25

B
Brian Anderson 已提交
26 27 28 29 30
# The arguments to all test runners
ifdef TESTNAME
  TESTARGS += $(TESTNAME)
endif

31
ifdef CHECK_IGNORED
B
Brian Anderson 已提交
32 33 34
  TESTARGS += --ignored
endif

35
TEST_BENCH = --bench
36

B
Brian Anderson 已提交
37 38 39
# Arguments to the cfail/rfail/rpass/bench tests
ifdef CFG_VALGRIND
  CTEST_RUNTOOL = --runtool "$(CFG_VALGRIND)"
40
  TEST_BENCH =
B
Brian Anderson 已提交
41
endif
42

43 44
ifdef NO_BENCH
  TEST_BENCH =
B
Brian Anderson 已提交
45
endif
46

47 48 49 50 51
# Arguments to the perf tests
ifdef CFG_PERF_TOOL
  CTEST_PERF_RUNTOOL = --runtool "$(CFG_PERF_TOOL)"
endif

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

B
Brian Anderson 已提交
54 55 56
ifdef VERBOSE
  CTEST_TESTARGS += --verbose
endif
57

58 59 60 61 62 63 64
# If we're running perf then set this environment variable
# to put the benchmarks into 'hard mode'
ifeq ($(MAKECMDGOALS),perf)
  RUST_BENCH=1
  export RUST_BENCH
endif

65 66
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
67

68 69 70 71 72
TEST_RATCHET_FILE=tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4)-metrics.json
TEST_RATCHET_NOISE_PERCENT=10.0

# Whether to ratchet or merely save benchmarks
ifdef CFG_RATCHET_BENCH
73
CRATE_TEST_EXTRA_ARGS=\
74
  --test $(TEST_BENCH) \
75 76 77
  --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
  --ratchet-noise-percent $(TEST_RATCHET_NOISE_PERCENT)
else
78
CRATE_TEST_EXTRA_ARGS=\
79
  --test $(TEST_BENCH) \
80 81 82
  --save-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4))
endif

83 84 85 86 87 88 89 90
# If we're sharding the testsuite between parallel testers,
# pass this argument along to the compiletest and crate test
# invocations.
ifdef TEST_SHARD
  CTEST_TESTARGS += --test-shard=$(TEST_SHARD)
  CRATE_TEST_EXTRA_ARGS += --test-shard=$(TEST_SHARD)
endif

91 92 93 94 95 96 97
define DEF_TARGET_COMMANDS

ifdef CFG_UNIXY_$(1)
  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),,$$(CFG_VALGRIND) $$(1))
endif

ifdef CFG_WINDOWSY_$(1)
C
Chris Morgan 已提交
98
  CFG_TESTLIB_$(1)=$$(CFG_BUILD_DIR)$$(2)/$$(strip \
99
   $$(if $$(findstring stage0,$$(1)), \
100
       stage0/$$(CFG_LIBDIR_RELATIVE), \
101
      $$(if $$(findstring stage1,$$(1)), \
102
           stage1/$$(CFG_LIBDIR_RELATIVE), \
103
          $$(if $$(findstring stage2,$$(1)), \
104
               stage2/$$(CFG_LIBDIR_RELATIVE), \
105
               $$(if $$(findstring stage3,$$(1)), \
106
                    stage3/$$(CFG_LIBDIR_RELATIVE), \
107
               )))))/rustlib/$$(CFG_BUILD)/lib
108 109 110 111 112
  CFG_RUN_TEST_$(1)=$$(call CFG_RUN_$(1),$$(call CFG_TESTLIB_$(1),$$(1),$$(3)),$$(1))
endif

# Run the compiletest runner itself under valgrind
ifdef CTEST_VALGRIND
113 114
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
      $$(call CFG_RUN_TEST_$$(CFG_BUILD),$$(2),$$(3))
115
else
116 117
CFG_RUN_CTEST_$(1)=$$(RPATH_VAR$$(1)_T_$$(3)_H_$$(3)) \
      $$(call CFG_RUN_$$(CFG_BUILD),$$(TLIB$$(1)_T_$$(3)_H_$$(3)),$$(2))
118 119 120 121
endif

endef

H
Heather 已提交
122
$(foreach target,$(CFG_TARGET), \
123 124
  $(eval $(call DEF_TARGET_COMMANDS,$(target))))

D
Daniel Micay 已提交
125
# Target platform specific variables
126
# for arm-linux-androidabi
127 128
define DEF_ADB_DEVICE_STATUS
CFG_ADB_DEVICE_STATUS=$(1)
129 130
endef

H
Heather 已提交
131
$(foreach target,$(CFG_TARGET), \
132 133
  $(if $(findstring $(target),"arm-linux-androideabi"), \
    $(if $(findstring adb,$(CFG_ADB)), \
134
      $(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[:_A-Za-z0-9-]+[[:blank:]]+device')), \
135 136 137 138
        $(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)) \
139
      ), \
140 141
      $(info check: adb not found) \
      $(eval $(call DEF_ADB_DEVICE_STATUS, false)) \
142
    ), \
143 144 145
  ) \
)

146 147
ifeq ($(CFG_ADB_DEVICE_STATUS),true)
CFG_ADB_TEST_DIR=/data/tmp
148

149
$(info check: android device test dir $(CFG_ADB_TEST_DIR) ready \
150 151 152 153 154
 $(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) \
A
Alex Crichton 已提交
155 156 157
 $(foreach crate,$(TARGET_CRATES),\
    $(shell $(CFG_ADB) push $(TLIB2_T_arm-linux-androideabi_H_$(CFG_BUILD))/$(call CFG_LIB_GLOB_arm-linux-androideabi,$(crate)) \
                    $(CFG_ADB_TEST_DIR)))\
158
 )
159 160
else
CFG_ADB_TEST_DIR=
161
endif
162 163


B
Brian Anderson 已提交
164 165 166 167
######################################################################
# Main test targets
######################################################################

H
Huon Wilson 已提交
168 169 170
check: cleantmptestlogs cleantestlibs tidy check-notidy

check-notidy: cleantmptestlogs cleantestlibs all check-stage2
171 172 173
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

check-lite: cleantestlibs cleantmptestlogs \
174 175
	$(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
	check-stage2-rpass \
A
Alex Crichton 已提交
176
	check-stage2-rfail check-stage2-cfail check-stage2-rmake
177 178
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

179 180 181 182
check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass \
	check-stage2-rfail check-stage2-cfail check-stage2-rmake
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

B
Brian Anderson 已提交
183 184 185
check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
	$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

186 187 188
# NOTE: Remove after reprogramming windows bots
check-fast: check-lite

189 190
.PHONY: cleantmptestlogs cleantestlibs

191 192
cleantmptestlogs:
	$(Q)rm -f tmp/*.log
193

194
cleantestlibs:
H
Heather 已提交
195
	$(Q)find $(CFG_BUILD)/test \
196 197 198 199 200 201 202
         -name '*.[odasS]' -o \
         -name '*.so' -o      \
         -name '*.dylib' -o   \
         -name '*.dll' -o     \
         -name '*.def' -o     \
         -name '*.bc' -o      \
         -name '*.dSYM' -o    \
203
         -name '*.libaux' -o      \
204
         -name '*.out' -o     \
B
Brian Leibig 已提交
205 206
         -name '*.err' -o     \
	 -name '*.debugger.script' \
207
         | xargs rm -rf
208

209

210 211 212
######################################################################
# Tidy
######################################################################
B
Brian Anderson 已提交
213

214
ifdef CFG_NOTIDY
B
Brian Anderson 已提交
215
tidy:
216
else
217 218 219 220

ALL_CS := $(wildcard $(S)src/rt/*.cpp \
                     $(S)src/rt/*/*.cpp \
                     $(S)src/rt/*/*/*.cpp \
221
                     $(S)src/rustllvm/*.cpp)
222
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
223 224
		       $(wildcard $(S)src/rt/hoedown/src/*.c) \
		       $(wildcard $(S)src/rt/hoedown/bin/*.c) \
225 226 227 228
	,$(ALL_CS))
ALL_HS := $(wildcard $(S)src/rt/*.h \
                     $(S)src/rt/*/*.h \
                     $(S)src/rt/*/*/*.h \
229
                     $(S)src/rustllvm/*.h)
230 231
ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
                       $(S)src/rt/valgrind/memcheck.h \
232 233 234
                       $(S)src/rt/msvc/typeof.h \
                       $(S)src/rt/msvc/stdint.h \
                       $(S)src/rt/msvc/inttypes.h \
235 236
		       $(wildcard $(S)src/rt/hoedown/src/*.h) \
		       $(wildcard $(S)src/rt/hoedown/bin/*.h) \
237 238
	,$(ALL_HS))

239
# Run the tidy script in multiple parts to avoid huge 'echo' commands
240 241
tidy:
		@$(call E, check: formatting)
242
		$(Q)find $(S)src -name '*.r[sc]' \
D
Daniel Micay 已提交
243
		| grep '^$(S)src/jemalloc' -v \
244 245
		| grep '^$(S)src/libuv' -v \
		| grep '^$(S)src/llvm' -v \
246
		| grep '^$(S)src/gyp' -v \
247
		| grep '^$(S)src/libbacktrace' -v \
248
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
249
		$(Q)find $(S)src/etc -name '*.py' \
250
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
251 252 253 254 255 256 257 258 259 260
		$(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
261
		$(Q)echo $(ALL_CS) \
262
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
263
		$(Q)echo $(ALL_HS) \
264
		| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
265 266 267
		$(Q)find $(S)src -type f -perm +111 \
		    -not -name '*.rs' -and -not -name '*.py' \
		    -and -not -name '*.sh' \
D
Daniel Micay 已提交
268
		| grep '^$(S)src/jemalloc' -v \
269
		| grep '^$(S)src/libuv' -v \
D
Daniel Micay 已提交
270
		| grep '^$(S)src/llvm' -v \
271
		| grep '^$(S)src/rt/hoedown' -v \
272 273
		| grep '^$(S)src/gyp' -v \
		| grep '^$(S)src/etc' -v \
274
		| grep '^$(S)src/doc' -v \
275
		| grep '^$(S)src/compiler-rt' -v \
276
		| grep '^$(S)src/libbacktrace' -v \
277
		| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
278

279
endif
280

281

B
Brian Anderson 已提交
282
######################################################################
283
# Sets of tests
B
Brian Anderson 已提交
284 285
######################################################################

286 287 288 289 290 291 292
define DEF_TEST_SETS

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			\
	check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec			\
293
	check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec			\
A
Alex Crichton 已提交
294 295
	check-stage$(1)-T-$(2)-H-$(3)-rmake-exec			\
        check-stage$(1)-T-$(2)-H-$(3)-crates-exec                       \
296
        check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec                   \
297
	check-stage$(1)-T-$(2)-H-$(3)-bench-exec			\
298 299
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-gdb-exec \
	check-stage$(1)-T-$(2)-H-$(3)-debuginfo-lldb-exec \
300
	check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
301 302 303
	check-stage$(1)-T-$(2)-H-$(3)-doc-exec \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-exec

304 305
# 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 已提交
306
ifneq ($$(findstring $(2),$$(CFG_HOST)),)
307

308 309 310 311
check-stage$(1)-T-$(2)-H-$(3)-crates-exec: \
	$$(foreach crate,$$(TEST_CRATES), \
           check-stage$(1)-T-$(2)-H-$(3)-$$(crate)-exec)

312 313 314 315 316 317 318 319
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

320 321
check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec: \
        $$(foreach crate,$$(TEST_DOC_CRATES), \
322
           check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$$(crate)-exec)
323

324
check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
325
        $$(foreach docname,$$(DOCS), \
326 327 328 329 330 331 332 333
           check-stage$(1)-T-$(2)-H-$(3)-doc-$$(docname)-exec)

check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
	check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec	\
	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	\
	check-stage$(1)-T-$(2)-H-$(3)-pretty-pretty-exec
334

B
Brian Anderson 已提交
335 336
endef

H
Heather 已提交
337 338
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
339 340 341
  $(foreach stage,$(STAGES), \
    $(eval $(call DEF_TEST_SETS,$(stage),$(target),$(host))))))

B
Brian Anderson 已提交
342

343
######################################################################
344
# Crate testing
345 346
######################################################################

347
define TEST_RUNNER
348

349 350 351
# 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.
352
ifeq ($(NO_REBUILD),)
353
TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(SREQ$(1)_T_$(2)_H_$(3)) \
A
Alex Crichton 已提交
354
			    $$(foreach crate,$$(TARGET_CRATES),\
355 356
				$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)) \
				$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))
357 358 359 360 361 362 363 364 365 366

# The regex crate depends on the regex_macros crate during testing, but it
# notably depend on the *host* regex_macros crate, not the target version.
# Additionally, this is not a dependency in stage1, only in stage2.
ifeq ($(4),regex)
ifneq ($(1),1)
TESTDEP_$(1)_$(2)_$(3)_$(4) += $$(TLIB$(1)_T_$(3)_H_$(3))/stamp.regex_macros
endif
endif

367
else
368
TESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
369 370
endif

371
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)): CFG_COMPILER_HOST_TRIPLE = $(2)
372
$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2)):				\
373 374
		$$(CRATEFILE_$(4)) \
		$$(TESTDEP_$(1)_$(2)_$(3)_$(4))
375
	@$$(call E, oxidize: $$@)
376 377 378
	$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test	\
		-L "$$(RT_OUTPUT_DIR_$(2))"		\
		-L "$$(LLVM_LIBDIR_$(2))"
379

380 381
endef

H
Heather 已提交
382 383
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
384
  $(eval $(foreach stage,$(STAGES), \
385 386
   $(eval $(foreach crate,$(TEST_CRATES), \
    $(eval $(call TEST_RUNNER,$(stage),$(target),$(host),$(crate))))))))))
387 388

define DEF_TEST_CRATE_RULES
389 390 391
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 已提交
392
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
393
	@$$(call E, run: $$<)
394 395 396 397
	$$(Q)$$(call CFG_RUN_TEST_$(2),$$<,$(2),$(3)) $$(TESTARGS) \
	    --logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
	    $$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) \
	    && touch $$@
398
endef
399

400 401 402 403
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 已提交
404
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
405
	@$$(call E, run: $$< via adb)
406 407
	$$(Q)$(CFG_ADB) push $$< $(CFG_ADB_TEST_DIR)
	$$(Q)$(CFG_ADB) shell '(cd $(CFG_ADB_TEST_DIR); LD_LIBRARY_PATH=. \
408
		./$$(notdir $$<) \
409
		--logfile $(CFG_ADB_TEST_DIR)/check-stage$(1)-T-$(2)-H-$(3)-$(4).log \
410
		$$(call CRATE_TEST_EXTRA_ARGS,$(1),$(2),$(3),$(4)) $(TESTARGS))' \
411
		> tmp/check-stage$(1)-T-$(2)-H-$(3)-$(4).tmp
412 413 414 415 416
	$$(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
	$$(Q)$(CFG_ADB) pull $(CFG_ADB_TEST_DIR)/$$(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) tmp/
417 418 419 420 421 422 423 424 425 426 427 428 429 430
	@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 已提交
431
		$(3)/stage$(1)/test/$(4)test-$(2)$$(X_$(2))
432 433
	@$$(call E, failing: no device for $$< )
	false
434 435
endef

H
Heather 已提交
436 437
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
438 439
  $(foreach stage,$(STAGES), \
   $(foreach crate, $(TEST_CRATES), \
H
Heather 已提交
440
    $(if $(findstring $(target),$(CFG_BUILD)), \
441 442
     $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))), \
     $(if $(findstring $(target),"arm-linux-androideabi"), \
443
      $(if $(findstring $(CFG_ADB_DEVICE_STATUS),"true"), \
444 445 446
       $(eval $(call DEF_TEST_CRATE_RULES_arm-linux-androideabi,$(stage),$(target),$(host),$(crate))), \
       $(eval $(call DEF_TEST_CRATE_RULES_null,$(stage),$(target),$(host),$(crate))) \
      ), \
447
      $(eval $(call DEF_TEST_CRATE_RULES,$(stage),$(target),$(host),$(crate))) \
D
Daniel Micay 已提交
448
     ))))))
449

450 451 452 453 454 455 456 457
######################################################################
# Rules for the compiletest tests (rpass, rfail, etc.)
######################################################################

RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
458 459
CFAIL_FULL_RC := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rc)
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
460 461 462 463
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
464
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
465
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
466 467
DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
468 469
CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
470

471 472
# perf tests are the same as bench tests only they run under
# a performance monitor.
473
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
474

475 476
RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
477
CFAIL_FULL_TESTS := $(CFAIL_FULL_RC) $(CFAIL_FULL_RS)
478 479 480 481 482
RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
BENCH_TESTS := $(BENCH_RS)
PERF_TESTS := $(PERF_RS)
PRETTY_TESTS := $(PRETTY_RS)
483 484
DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
485
CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
B
Brian Anderson 已提交
486

487 488 489 490
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 已提交
491

492 493
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
494 495 496
CTEST_MODE_rpass-full = run-pass
CTEST_RUNTOOL_rpass-full = $(CTEST_RUNTOOL)

497 498 499 500 501
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)

502 503 504 505 506 507 508 509 510 511
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)

512
CTEST_SRC_BASE_bench = bench
513 514 515 516 517 518 519 520 521
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)

522 523 524 525 526 527 528 529 530
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 已提交
531

532 533 534 535 536
CTEST_SRC_BASE_codegen = codegen
CTEST_BUILD_BASE_codegen = codegen
CTEST_MODE_codegen = codegen
CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)

537 538 539 540
# 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.

541
ifeq ($(CFG_GDB),)
542 543 544 545 546
CTEST_DISABLE_debuginfo-gdb = "no gdb found"
endif

ifeq ($(CFG_LLDB),)
CTEST_DISABLE_debuginfo-lldb = "no lldb found"
547 548
endif

549 550 551
# Completely disable LLDB tests for now
CTEST_DISABLE_debuginfo-lldb = "LLDB tests are not enabled yet"

552 553 554 555
ifeq ($(CFG_CLANG),)
CTEST_DISABLE_codegen = "no clang found"
endif

556
ifeq ($(CFG_OSTYPE),apple-darwin)
557
CTEST_DISABLE_debuginfo-gdb = "gdb on darwing needs root"
558 559
endif

560 561 562 563 564 565
# 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.

566 567 568 569 570 571 572 573 574 575 576
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) = \
577
	$$(HBIN$(1)_H_$(3))/compiletest$$(X_$(3)) \
578
	$$(SREQ$(1)_T_$(2)_H_$(3))
B
Brian Anderson 已提交
579

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

582 583
# The tests select when to use debug configuration on their own;
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
584
CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
585 586 587 588 589 590 591 592

# The tests can not be optimized while the rest of the compiler is optimized, so
# 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
593

N
Niko Matsakis 已提交
594
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) :=						\
N
Niko Matsakis 已提交
595 596
		--compile-lib-path $$(HLIB$(1)_H_$(3))				\
        --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3))			\
597
        --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))			\
598
        --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
H
Heather 已提交
599
        --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
600
        --aux-base $$(S)src/test/auxiliary/                 \
N
Niko Matsakis 已提交
601
        --stage-id stage$(1)-$(2)							\
602
        --target $(2)                                       \
603
        --host $(3)                                       \
604
        --android-cross-path=$(CFG_ANDROID_CROSS_PATH)    \
605
        --adb-path=$(CFG_ADB)                          \
606
        --adb-test-dir=$(CFG_ADB_TEST_DIR)                  \
607
        --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
608
        --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
L
Luqman Aden 已提交
609
        --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
N
Niko Matsakis 已提交
610 611
        $$(CTEST_TESTARGS)

612
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
613
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
614
CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
615 616 617 618
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)
619 620
CTEST_DEPS_debuginfo-gdb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_GDB_TESTS)
CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS)
621
CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
N
Niko Matsakis 已提交
622

623
endef
N
Niko Matsakis 已提交
624

H
Heather 已提交
625 626
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
627 628
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(call DEF_CTEST_VARS,$(stage),$(target),$(host))))))))
N
Niko Matsakis 已提交
629

630
define DEF_RUN_COMPILETEST
631

632 633
CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
        $$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
634
        --src-base $$(S)src/test/$$(CTEST_SRC_BASE_$(4))/ \
635
        --build-base $(3)/test/$$(CTEST_BUILD_BASE_$(4))/ \
636
        --ratchet-metrics $(call TEST_RATCHET_FILE,$(1),$(2),$(3),$(4)) \
637 638
        --mode $$(CTEST_MODE_$(4)) \
	$$(CTEST_RUNTOOL_$(4))
N
Niko Matsakis 已提交
639

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

642 643 644 645 646
# 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)
647

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
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)),)
664
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
665 666
		$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
                $$(CTEST_DEPS_$(4)_$(1)-T-$(2)-H-$(3))
667
	@$$(call E, run $(4) [$(2)]: $$<)
668
	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
669
		$$(CTEST_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
670 671
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
                && touch $$@
N
Niko Matsakis 已提交
672

673 674
else

675
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)):
676
	@$$(call E, run $(4) [$(2)]: $$<)
677
	@$$(call E, warning: tests disabled: $$(CTEST_DONT_RUN_$(1)-T-$(2)-H-$(3)-$(4)))
678 679 680 681
	touch $$@

endif

682
endef
N
Niko Matsakis 已提交
683

684
CTEST_NAMES = rpass rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
685

H
Heather 已提交
686 687
$(foreach host,$(CFG_HOST), \
 $(eval $(foreach target,$(CFG_TARGET), \
688 689 690 691 692 693 694 695 696 697 698
  $(eval $(foreach stage,$(STAGES), \
   $(eval $(foreach name,$(CTEST_NAMES), \
   $(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))

PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
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)
PRETTY_DIRNAME_pretty-rpass = run-pass
699
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
700 701 702 703 704 705 706
PRETTY_DIRNAME_pretty-rfail = run-fail
PRETTY_DIRNAME_pretty-bench = bench
PRETTY_DIRNAME_pretty-pretty = pretty

define DEF_RUN_PRETTY_TEST

PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) :=			\
N
Niko Matsakis 已提交
707
		$$(CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3))	\
708 709
        --src-base $$(S)src/test/$$(PRETTY_DIRNAME_$(4))/ \
        --build-base $(3)/test/$$(PRETTY_DIRNAME_$(4))/ \
N
Niko Matsakis 已提交
710 711
        --mode pretty

712 713 714
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)): \
715 716
	        $$(TEST_SREQ$(1)_T_$(2)_H_$(3))		\
	        $$(PRETTY_DEPS_$(4))
717
	@$$(call E, run pretty-rpass [$(2)]: $$<)
718
	$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \
719
		$$(PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4)) \
720 721
		--logfile $$(call TEST_LOG_FILE,$(1),$(2),$(3),$(4)) \
                && touch $$@
N
Niko Matsakis 已提交
722

723
endef
N
Niko Matsakis 已提交
724

H
Heather 已提交
725 726
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
727 728 729
  $(foreach stage,$(STAGES), \
   $(foreach pretty-name,$(PRETTY_NAMES), \
    $(eval $(call DEF_RUN_PRETTY_TEST,$(stage),$(target),$(host),$(pretty-name)))))))
B
Brian Anderson 已提交
730

731

732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
######################################################################
# 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
749

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

752 753 754 755 756 757 758 759 760 761 762
# 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) = \
	$$(D)/$(4).md \
	$$(TEST_SREQ$(1)_T_$(2)_H_$(3))				\
	$$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
else
DOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(D)/$(4).md
endif
763

764 765 766
ifeq ($(2),$$(CFG_BUILD))
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)): $$(DOCTESTDEP_$(1)_$(2)_$(3)_$(4))
	@$$(call E, run doc-$(4) [$(2)])
767
	$$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --cfg dox --test $$< --test-args "$$(TESTARGS)" && touch $$@
768 769 770 771
else
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-$(4)):
	touch $$@
endif
772
endef
773

H
Heather 已提交
774 775
$(foreach host,$(CFG_HOST), \
 $(foreach target,$(CFG_TARGET), \
776
  $(foreach stage,$(STAGES), \
777 778 779 780
   $(foreach docname,$(DOCS), \
    $(eval $(call DEF_DOC_TEST,$(stage),$(target),$(host),$(docname)))))))

# Crates
781

782 783
define DEF_CRATE_DOC_TEST

784 785 786 787
# 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),)
788
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = \
789 790
	$$(TEST_SREQ$(1)_T_$(2)_H_$(3))				\
	$$(CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4))		\
791
	$$(RUSTDOC_EXE_$(1)_T_$(2)_H_$(3))
792
else
793
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
794 795
endif

796 797
check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
	$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
798

799
ifeq ($(2),$$(CFG_BUILD))
800 801
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
	@$$(call E, run doc-crate-$(4) [$(2)])
802
	$$(Q)$$(RUSTDOC_$(1)_T_$(2)_H_$(3)) --test \
803
	    	$$(CRATEFILE_$(4)) --test-args "$$(TESTARGS)" && touch $$@
804
else
805
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)):
806 807
	touch $$@
endif
808 809 810 811

endef

$(foreach host,$(CFG_HOST), \
812 813 814 815
 $(foreach target,$(CFG_TARGET), \
  $(foreach stage,$(STAGES), \
   $(foreach crate,$(TEST_DOC_CRATES), \
    $(eval $(call DEF_CRATE_DOC_TEST,$(stage),$(target),$(host),$(crate)))))))
816

817 818 819
######################################################################
# Shortcut rules
######################################################################
820

821 822 823
TEST_GROUPS = \
	crates \
	$(foreach crate,$(TEST_CRATES),$(crate)) \
824
	$(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
825 826
	rpass \
	rpass-full \
827
	cfail-full \
828 829 830 831
	rfail \
	cfail \
	bench \
	perf \
A
Alex Crichton 已提交
832
	rmake \
833 834
	debuginfo-gdb \
	debuginfo-lldb \
835
	codegen \
836
	doc \
837
	$(foreach docname,$(DOCS),doc-$(docname)) \
838 839 840 841 842 843 844 845 846 847 848
	pretty \
	pretty-rpass \
	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
849

850
$(foreach stage,$(STAGES), \
H
Heather 已提交
851 852
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
853
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST,$(stage),$(target),$(host))))))
854

855 856 857
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 已提交
858

859
$(foreach stage,$(STAGES), \
H
Heather 已提交
860 861
 $(foreach target,$(CFG_TARGET), \
  $(foreach host,$(CFG_HOST), \
862 863
   $(foreach group,$(TEST_GROUPS), \
    $(eval $(call DEF_CHECK_FOR_STAGE_AND_TARGET_AND_HOST_AND_GROUP,$(stage),$(target),$(host),$(group)))))))
864

865
define DEF_CHECK_FOR_STAGE
H
Heather 已提交
866 867
check-stage$(1): check-stage$(1)-H-$$(CFG_BUILD)
check-stage$(1)-H-all: $$(foreach target,$$(CFG_TARGET), \
868 869
                           check-stage$(1)-H-$$(target))
endef
870

871 872
$(foreach stage,$(STAGES), \
 $(eval $(call DEF_CHECK_FOR_STAGE,$(stage))))
873

874
define DEF_CHECK_FOR_STAGE_AND_GROUP
H
Heather 已提交
875 876
check-stage$(1)-$(2): check-stage$(1)-H-$$(CFG_BUILD)-$(2)
check-stage$(1)-H-all-$(2): $$(foreach target,$$(CFG_TARGET), \
877 878
                               check-stage$(1)-H-$$(target)-$(2))
endef
879

880 881 882
$(foreach stage,$(STAGES), \
 $(foreach group,$(TEST_GROUPS), \
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_GROUP,$(stage),$(group)))))
883

884 885

define DEF_CHECK_FOR_STAGE_AND_HOSTS
H
Heather 已提交
886
check-stage$(1)-H-$(2): $$(foreach target,$$(CFG_TARGET), \
887
                           check-stage$(1)-T-$$(target)-H-$(2))
B
Brian Anderson 已提交
888
endef
889

890
$(foreach stage,$(STAGES), \
H
Heather 已提交
891
 $(foreach host,$(CFG_HOST), \
892 893 894
  $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS,$(stage),$(host)))))

define DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP
H
Heather 已提交
895
check-stage$(1)-H-$(2)-$(3): $$(foreach target,$$(CFG_TARGET), \
896 897 898 899
                                check-stage$(1)-T-$$(target)-H-$(2)-$(3))
endef

$(foreach stage,$(STAGES), \
H
Heather 已提交
900
 $(foreach host,$(CFG_HOST), \
901 902
  $(foreach group,$(TEST_GROUPS), \
   $(eval $(call DEF_CHECK_FOR_STAGE_AND_HOSTS_AND_GROUP,$(stage),$(host),$(group))))))
903

B
Brian Anderson 已提交
904
define DEF_CHECK_DOC_FOR_STAGE
905
check-stage$(1)-docs: $$(foreach docname,$$(DOCS),\
B
Brian Anderson 已提交
906
                       check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-$$(docname)) \
907
                     $$(foreach crate,$$(TEST_DOC_CRATES),\
908
                       check-stage$(1)-T-$$(CFG_BUILD)-H-$$(CFG_BUILD)-doc-crate-$$(crate))
B
Brian Anderson 已提交
909 910 911 912 913 914 915 916 917 918 919 920
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 已提交
921
######################################################################
922
# RMAKE rules
N
Niko Matsakis 已提交
923
######################################################################
924

A
Alex Crichton 已提交
925 926 927 928 929 930 931 932
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

933 934

ifeq ($(2)$(3),$$(CFG_BUILD)$$(CFG_BUILD))
A
Alex Crichton 已提交
935 936 937 938 939 940 941 942 943
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 已提交
944
		$$(CSREQ$(1)_T_$(2)_H_$(3))
A
Alex Crichton 已提交
945 946
	@rm -rf $(3)/test/run-make/$$*
	@mkdir -p $(3)/test/run-make/$$*
947
	$$(Q)$$(CFG_PYTHON) $(S)src/etc/maketest.py $$(dir $$<) \
948
        $$(MAKE) \
A
Alex Crichton 已提交
949
	    $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
A
Alex Crichton 已提交
950
	    $(3)/test/run-make/$$* \
C
Corey Richardson 已提交
951
	    "$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
952
	    $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
953 954
	    "$$(TESTNAME)" \
	    "$$(RPATH_VAR$(1)_T_$(2)_H_$(3))"
A
Alex Crichton 已提交
955
	@touch $$@
956 957 958 959 960 961 962
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 已提交
963 964 965 966 967 968 969

endef

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