1 // Copyright 2016 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.
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.
11 //! Implementation of the test-related targets of the build system.
13 //! This file implements the various regression test suites that we execute on
16 use std::collections::HashSet;
18 use std::ffi::OsString;
21 use std::fs::{self, File};
22 use std::path::{PathBuf, Path};
23 use std::process::Command;
26 use build_helper::{self, output};
30 use util::{self, dylib_path, dylib_path_var};
34 use builder::{Kind, Builder, Compiler, Step};
35 use tool::{self, Tool};
37 const ADB_TEST_DIR: &str = "/data/tmp/work";
39 /// The two modes of the test runner; tests or benchmarks.
40 #[derive(Serialize, Copy, Clone)]
49 // Return the cargo subcommand for this test kind
50 fn subcommand(self) -> &'static str {
52 TestKind::Test => "test",
53 TestKind::Bench => "bench",
58 impl fmt::Display for TestKind {
59 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60 f.write_str(match *self {
61 TestKind::Test => "Testing",
62 TestKind::Bench => "Benchmarking",
67 fn try_run(build: &Build, cmd: &mut Command) {
69 if !build.try_run(cmd) {
70 let failures = build.delayed_failures.get();
71 build.delayed_failures.set(failures + 1);
78 fn try_run_quiet(build: &Build, cmd: &mut Command) {
80 if !build.try_run_quiet(cmd) {
81 let failures = build.delayed_failures.get();
82 build.delayed_failures.set(failures + 1);
89 // rules.test("check-linkchecker", "src/tools/linkchecker")
90 // .dep(|s| s.name("tool-linkchecker").stage(0))
91 // .dep(|s| s.name("default:doc"))
92 // .default(build.config.docs)
94 // .run(move |s| check::linkcheck(build, s.target));
97 pub struct Linkcheck<'a> {
101 impl<'a> Step<'a> for Linkcheck<'a> {
103 const ONLY_HOSTS: bool = true;
104 const DEFAULT: bool = true;
106 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
108 /// This tool in `src/tools` will verify the validity of all our links in the
109 /// documentation to ensure we don't have a bunch of dead ones.
110 fn run(self, builder: &Builder) {
111 let build = builder.build;
112 let host = self.host;
114 println!("Linkcheck ({})", host);
116 builder.default_doc(None);
118 let _time = util::timeit();
119 try_run(build, builder.tool_cmd(Tool::Linkchecker)
120 .arg(build.out.join(host).join("doc")));
123 fn should_run(_builder: &Builder, path: &Path) -> bool {
124 path.ends_with("src/tools/linkchecker")
127 fn make_run(builder: &Builder, path: Option<&Path>, host: &str, _target: &str) {
129 builder.ensure(Linkcheck { host });
131 if builder.build.config.docs {
132 builder.ensure(Linkcheck { host });
138 // rules.test("check-cargotest", "src/tools/cargotest")
139 // .dep(|s| s.name("tool-cargotest").stage(0))
140 // .dep(|s| s.name("librustc"))
142 // .run(move |s| check::cargotest(build, s.stage, s.target));
145 pub struct Cargotest<'a> {
150 impl<'a> Step<'a> for Cargotest<'a> {
152 const ONLY_HOSTS: bool = true;
154 fn should_run(_builder: &Builder, path: &Path) -> bool {
155 path.ends_with("src/tools/cargotest")
158 fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, _target: &str) {
159 builder.ensure(Cargotest {
160 stage: builder.top_stage,
165 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
167 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
168 /// test` to ensure that we don't regress the test suites there.
169 fn run(self, builder: &Builder) {
170 let build = builder.build;
171 let compiler = builder.compiler(self.stage, self.host);
172 builder.ensure(compile::Rustc { compiler, target: compiler.host });
174 // Note that this is a short, cryptic, and not scoped directory name. This
175 // is currently to minimize the length of path on Windows where we otherwise
176 // quickly run into path name limit constraints.
177 let out_dir = build.out.join("ct");
178 t!(fs::create_dir_all(&out_dir));
180 let _time = util::timeit();
181 let mut cmd = builder.tool_cmd(Tool::CargoTest);
182 try_run(build, cmd.arg(&build.initial_cargo)
184 .env("RUSTC", builder.rustc(compiler))
185 .env("RUSTDOC", builder.rustdoc(compiler)));
189 //rules.test("check-cargo", "cargo")
190 // .dep(|s| s.name("tool-cargo"))
192 // .run(move |s| check::cargo(build, s.stage, s.target));
195 pub struct Cargo<'a> {
200 impl<'a> Step<'a> for Cargo<'a> {
202 const ONLY_HOSTS: bool = true;
204 fn should_run(_builder: &Builder, path: &Path) -> bool {
205 path.ends_with("src/tools/cargo")
208 fn make_run(builder: &Builder, _path: Option<&Path>, _host: &str, target: &str) {
209 builder.ensure(Cargotest {
210 stage: builder.top_stage,
215 /// Runs `cargo test` for `cargo` packaged with Rust.
216 fn run(self, builder: &Builder) {
217 let build = builder.build;
218 let compiler = builder.compiler(self.stage, self.host);
220 // Configure PATH to find the right rustc. NB. we have to use PATH
221 // and not RUSTC because the Cargo test suite has tests that will
222 // fail if rustc is not spelled `rustc`.
223 let path = builder.sysroot(compiler).join("bin");
224 let old_path = env::var_os("PATH").unwrap_or_default();
225 let newpath = env::join_paths(
226 iter::once(path).chain(env::split_paths(&old_path))
229 let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
230 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
231 if !build.fail_fast {
232 cargo.arg("--no-fail-fast");
235 let compiler = &Compiler::new(stage, host);
237 let mut cargo = build.cargo(compiler, Mode::Tool, host, "test");
238 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
239 if !build.fail_fast {
240 cargo.arg("--no-fail-fast");
243 // Don't build tests dynamically, just a pain to work with
244 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
246 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
248 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
250 try_run(build, cargo.env("PATH", &path_for_cargo(build, compiler)));
260 impl<'a> Step<'a> for Rls<'a> {
263 /// Runs `cargo test` for the rls.
264 fn run(self, builder: &Builder) {
265 let build = builder.build;
266 let stage = self.stage;
267 let host = self.host;
268 let compiler = &Compiler::new(stage, host);
270 let mut cargo = build.cargo(compiler, Mode::Tool, host, "test");
271 cargo.arg("--manifest-path").arg(build.src.join("src/tools/rls/Cargo.toml"));
273 // Don't build tests dynamically, just a pain to work with
274 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
276 build.add_rustc_lib_path(compiler, &mut cargo);
278 try_run(build, &mut cargo);
282 fn path_for_cargo(build: &Build, compiler: &Compiler) -> OsString {
283 // Configure PATH to find the right rustc. NB. we have to use PATH
284 // and not RUSTC because the Cargo test suite has tests that will
285 // fail if rustc is not spelled `rustc`.
286 let path = build.sysroot(compiler).join("bin");
287 let old_path = env::var_os("PATH").unwrap_or_default();
288 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
289 ||||||| parent of adabe3889e... Move code into Step trait implementations.
290 try_run(build, cargo.env("PATH", newpath));
292 try_run(build, cargo.env("PATH", newpath));
294 >>>>>>> adabe3889e... Move code into Step trait implementations.
297 //rules.test("check-tidy", "src/tools/tidy")
298 // .dep(|s| s.name("tool-tidy").stage(0))
302 // .run(move |s| check::tidy(build, s.target));
305 pub struct Tidy<'a> {
309 impl<'a> Step<'a> for Tidy<'a> {
311 const DEFAULT: bool = true;
312 const ONLY_HOSTS: bool = true;
313 const ONLY_BUILD: bool = true;
315 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
317 /// This tool in `src/tools` checks up on various bits and pieces of style and
318 /// otherwise just implements a few lint-like checks that are specific to the
320 fn run(self, builder: &Builder) {
321 let build = builder.build;
322 let host = self.host;
324 let _folder = build.fold_output(|| "tidy");
325 println!("tidy check ({})", host);
326 let mut cmd = builder.tool_cmd(Tool::Tidy);
327 cmd.arg(build.src.join("src"));
328 if !build.config.vendor {
329 cmd.arg("--no-vendor");
331 if build.config.quiet_tests {
334 try_run(build, &mut cmd);
337 fn should_run(_builder: &Builder, path: &Path) -> bool {
338 path.ends_with("src/tools/tidy")
341 fn make_run(builder: &Builder, _path: Option<&Path>, _host: &str, _target: &str) {
342 builder.ensure(Tidy {
343 host: &builder.build.build,
348 fn testdir(build: &Build, host: &str) -> PathBuf {
349 build.out.join(host).join("test")
352 // // ========================================================================
355 // // Various unit tests and tests suites we can run
357 // let mut suite = |name, path, mode, dir| {
358 // rules.test(name, path)
359 // .dep(|s| s.name("libtest"))
360 // .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
361 // .dep(|s| s.name("test-helpers"))
362 // .dep(|s| s.name("remote-copy-libs"))
363 // .default(mode != "pretty") // pretty tests don't run everywhere
365 // check::compiletest(build, &s.compiler(), s.target, mode, dir)
369 // suite("check-ui", "src/test/ui", "ui", "ui");
370 // suite("check-rpass", "src/test/run-pass", "run-pass", "run-pass");
371 // suite("check-cfail", "src/test/compile-fail", "compile-fail", "compile-fail");
372 // suite("check-pfail", "src/test/parse-fail", "parse-fail", "parse-fail");
373 // suite("check-rfail", "src/test/run-fail", "run-fail", "run-fail");
374 // suite("check-rpass-valgrind", "src/test/run-pass-valgrind",
375 // "run-pass-valgrind", "run-pass-valgrind");
376 // suite("check-mir-opt", "src/test/mir-opt", "mir-opt", "mir-opt");
377 // if build.config.codegen_tests {
378 // suite("check-codegen", "src/test/codegen", "codegen", "codegen");
380 // suite("check-codegen-units", "src/test/codegen-units", "codegen-units",
382 // suite("check-incremental", "src/test/incremental", "incremental",
386 // if build.build.contains("msvc") {
387 // // nothing to do for debuginfo tests
389 // rules.test("check-debuginfo-lldb", "src/test/debuginfo-lldb")
390 // .dep(|s| s.name("libtest"))
391 // .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
392 // .dep(|s| s.name("test-helpers"))
393 // .dep(|s| s.name("debugger-scripts"))
394 // .run(move |s| check::compiletest(build, &s.compiler(), s.target,
395 // "debuginfo-lldb", "debuginfo"));
396 // rules.test("check-debuginfo-gdb", "src/test/debuginfo-gdb")
397 // .dep(|s| s.name("libtest"))
398 // .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
399 // .dep(|s| s.name("test-helpers"))
400 // .dep(|s| s.name("debugger-scripts"))
401 // .dep(|s| s.name("remote-copy-libs"))
402 // .run(move |s| check::compiletest(build, &s.compiler(), s.target,
403 // "debuginfo-gdb", "debuginfo"));
404 // let mut rule = rules.test("check-debuginfo", "src/test/debuginfo");
405 // rule.default(true);
406 // if build.build.contains("apple") {
407 // rule.dep(|s| s.name("check-debuginfo-lldb"));
409 // rule.dep(|s| s.name("check-debuginfo-gdb"));
416 // let mut suite = |name, path, mode, dir| {
417 // rules.test(name, path)
418 // .dep(|s| s.name("librustc"))
419 // .dep(|s| s.name("test-helpers"))
420 // .dep(|s| s.name("tool-compiletest").target(s.host).stage(0))
421 // .default(mode != "pretty")
424 // check::compiletest(build, &s.compiler(), s.target, mode, dir)
428 // suite("check-ui-full", "src/test/ui-fulldeps", "ui", "ui-fulldeps");
429 // suite("check-rpass-full", "src/test/run-pass-fulldeps",
430 // "run-pass", "run-pass-fulldeps");
431 // suite("check-rfail-full", "src/test/run-fail-fulldeps",
432 // "run-fail", "run-fail-fulldeps");
433 // suite("check-cfail-full", "src/test/compile-fail-fulldeps",
434 // "compile-fail", "compile-fail-fulldeps");
435 // suite("check-rmake", "src/test/run-make", "run-make", "run-make");
436 // suite("check-rustdoc", "src/test/rustdoc", "rustdoc", "rustdoc");
437 // suite("check-pretty", "src/test/pretty", "pretty", "pretty");
438 // suite("check-pretty-rpass", "src/test/run-pass/pretty", "pretty",
440 // suite("check-pretty-rfail", "src/test/run-fail/pretty", "pretty",
442 // suite("check-pretty-valgrind", "src/test/run-pass-valgrind/pretty", "pretty",
443 // "run-pass-valgrind");
444 // suite("check-pretty-rpass-full", "src/test/run-pass-fulldeps/pretty",
445 // "pretty", "run-pass-fulldeps");
446 // suite("check-pretty-rfail-full", "src/test/run-fail-fulldeps/pretty",
447 // "pretty", "run-fail-fulldeps");
451 pub struct Compiletest<'a> {
452 compiler: Compiler<'a>,
458 #[derive(Copy, Clone, Debug, PartialEq)]
465 static DEFAULT_COMPILETESTS: &[Test] = &[
466 Test { path: "src/test/ui", mode: "ui", suite: "ui" },
467 Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
468 Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
469 Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
470 Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
472 path: "src/test/run-pass-valgrind",
473 mode: "run-pass-valgrind",
474 suite: "run-pass-valgrind"
476 Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
477 Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
478 Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
479 Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
481 // What this runs varies depending on the native platform being apple
482 Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
485 // Also default, but host-only.
486 static HOST_COMPILETESTS: &[Test] = &[
487 Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
488 Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
489 Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
491 path: "src/test/compile-fail-fulldeps",
492 mode: "compile-fail",
493 suite: "compile-fail-fulldeps",
495 Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
496 Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
498 Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
499 Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
500 Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
501 Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
502 Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
503 Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
506 static COMPILETESTS: &[Test] = &[
507 Test { path: "src/test/debuginfo-lldb", mode: "debuginfo-lldb", suite: "debuginfo" },
508 Test { path: "src/test/debuginfo-gdb", mode: "debuginfo-gdb", suite: "debuginfo" },
511 impl<'a> Step<'a> for Compiletest<'a> {
513 const DEFAULT: bool = true;
515 fn should_run(_builder: &Builder, path: &Path) -> bool {
516 // Note that this is general, while a few more cases are skipped inside
517 // run() itself. This is to avoid duplication across should_run and
519 COMPILETESTS.iter().chain(DEFAULT_COMPILETESTS).chain(HOST_COMPILETESTS).any(|&test| {
520 path.ends_with(test.path)
524 fn make_run(builder: &Builder, path: Option<&Path>, host: &str, target: &str) {
525 let compiler = builder.compiler(builder.top_stage, host);
527 let test = path.map(|path| {
528 COMPILETESTS.iter().chain(DEFAULT_COMPILETESTS).chain(HOST_COMPILETESTS).find(|&&test| {
529 path.ends_with(test.path)
530 }).unwrap_or_else(|| {
531 panic!("make_run in compile test to receive test path, received {:?}", path);
535 if let Some(test) = test { // specific test
536 let target = if HOST_COMPILETESTS.contains(test) {
541 builder.ensure(Compiletest {
542 compiler, target, mode: test.mode, suite: test.suite
544 } else { // default tests
545 for test in DEFAULT_COMPILETESTS {
546 builder.ensure(Compiletest {
553 for test in HOST_COMPILETESTS {
554 if test.mode != "pretty" {
555 builder.ensure(Compiletest {
566 /// Executes the `compiletest` tool to run a suite of tests.
568 /// Compiles all tests with `compiler` for `target` with the specified
569 /// compiletest `mode` and `suite` arguments. For example `mode` can be
570 /// "run-pass" or `suite` can be something like `debuginfo`.
571 fn run(self, builder: &Builder) {
572 let build = builder.build;
573 let compiler = self.compiler;
574 let target = self.target;
575 let mode = self.mode;
576 let suite = self.suite;
578 // Skip codegen tests if they aren't enabled in configuration.
579 if !build.config.codegen_tests && suite == "codegen" {
583 if suite == "debuginfo" {
584 if mode == "debuginfo-XXX" {
585 return if build.build.contains("apple") {
586 builder.ensure(Compiletest {
587 mode: "debuginfo-lldb",
591 builder.ensure(Compiletest {
592 mode: "debuginfo-gdb",
598 // Skip debuginfo tests on MSVC
599 if build.build.contains("msvc") {
603 builder.ensure(dist::DebuggerScripts {
604 sysroot: &builder.sysroot(compiler),
608 if mode == "debuginfo-gdb" {
609 builder.ensure(RemoteCopyLibs { compiler, target });
613 if suite.ends_with("fulldeps") ||
614 // FIXME: Does pretty need librustc compiled? Note that there are
615 // fulldeps test suites with mode = pretty as well.
619 builder.ensure(compile::Rustc { compiler, target });
622 builder.ensure(compile::Test { compiler, target });
623 builder.ensure(native::TestHelpers { target });
624 builder.ensure(RemoteCopyLibs { compiler, target });
626 let _folder = build.fold_output(|| format!("test_{}", suite));
627 println!("Check compiletest suite={} mode={} ({} -> {})",
628 suite, mode, compiler.host, target);
629 let mut cmd = builder.tool_cmd(Tool::Compiletest);
631 // compiletest currently has... a lot of arguments, so let's just pass all
634 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
635 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
636 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
637 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
638 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
639 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
640 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
641 cmd.arg("--mode").arg(mode);
642 cmd.arg("--target").arg(target);
643 cmd.arg("--host").arg(compiler.host);
644 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(&build.build));
646 if let Some(ref nodejs) = build.config.nodejs {
647 cmd.arg("--nodejs").arg(nodejs);
650 let mut flags = vec!["-Crpath".to_string()];
651 if build.config.rust_optimize_tests {
652 flags.push("-O".to_string());
654 if build.config.rust_debuginfo_tests {
655 flags.push("-g".to_string());
658 let mut hostflags = build.rustc_flags(compiler.host);
659 hostflags.extend(flags.clone());
660 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
662 let mut targetflags = build.rustc_flags(&target);
663 targetflags.extend(flags);
664 targetflags.push(format!("-Lnative={}",
665 build.test_helpers_out(target).display()));
666 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
668 cmd.arg("--docck-python").arg(build.python());
670 if build.build.ends_with("apple-darwin") {
671 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
672 // LLDB plugin's compiled module which only works with the system python
673 // (namely not Homebrew-installed python)
674 cmd.arg("--lldb-python").arg("/usr/bin/python");
676 cmd.arg("--lldb-python").arg(build.python());
679 if let Some(ref gdb) = build.config.gdb {
680 cmd.arg("--gdb").arg(gdb);
682 if let Some(ref vers) = build.lldb_version {
683 cmd.arg("--lldb-version").arg(vers);
685 if let Some(ref dir) = build.lldb_python_dir {
686 cmd.arg("--lldb-python-dir").arg(dir);
688 let llvm_config = build.llvm_config(target);
689 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
690 cmd.arg("--llvm-version").arg(llvm_version);
691 if !build.is_rust_llvm(target) {
692 cmd.arg("--system-llvm");
695 cmd.args(&build.flags.cmd.test_args());
697 if build.is_verbose() {
698 cmd.arg("--verbose");
701 if build.config.quiet_tests {
705 // Only pass correct values for these flags for the `run-make` suite as it
706 // requires that a C++ compiler was configured which isn't always the case.
707 if suite == "run-make" {
708 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
709 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
710 cmd.arg("--cc").arg(build.cc(target))
711 .arg("--cxx").arg(build.cxx(target).unwrap())
712 .arg("--cflags").arg(build.cflags(target).join(" "))
713 .arg("--llvm-components").arg(llvm_components.trim())
714 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
716 cmd.arg("--cc").arg("")
717 .arg("--cxx").arg("")
718 .arg("--cflags").arg("")
719 .arg("--llvm-components").arg("")
720 .arg("--llvm-cxxflags").arg("");
723 if build.remote_tested(target) {
724 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
727 // Running a C compiler on MSVC requires a few env vars to be set, to be
728 // sure to set them here.
730 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
731 // rather than stomp over it.
732 if target.contains("msvc") {
733 for &(ref k, ref v) in build.cc[target].0.env() {
739 cmd.env("RUSTC_BOOTSTRAP", "1");
740 build.add_rust_test_threads(&mut cmd);
742 if build.config.sanitizers {
743 cmd.env("SANITIZER_SUPPORT", "1");
746 if build.config.profiler {
747 cmd.env("PROFILER_SUPPORT", "1");
750 cmd.arg("--adb-path").arg("adb");
751 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
752 if target.contains("android") {
753 // Assume that cc for this target comes from the android sysroot
754 cmd.arg("--android-cross-path")
755 .arg(build.cc(target).parent().unwrap().parent().unwrap());
757 cmd.arg("--android-cross-path").arg("");
760 build.ci_env.force_coloring_in_ci(&mut cmd);
762 let _time = util::timeit();
763 try_run(build, &mut cmd);
768 pub struct Docs<'a> {
769 compiler: Compiler<'a>,
772 // rules.test("check-docs", "src/doc")
773 // .dep(|s| s.name("libtest"))
776 // .run(move |s| check::docs(build, &s.compiler()));
777 impl<'a> Step<'a> for Docs<'a> {
779 const DEFAULT: bool = true;
780 const ONLY_HOSTS: bool = true;
782 fn should_run(_builder: &Builder, path: &Path) -> bool {
783 path.ends_with("src/doc")
786 fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, _target: &str) {
787 builder.ensure(Docs {
788 compiler: builder.compiler(builder.top_stage, host),
792 /// Run `rustdoc --test` for all documentation in `src/doc`.
794 /// This will run all tests in our markdown documentation (e.g. the book)
795 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
797 fn run(self, builder: &Builder) {
798 let build = builder.build;
799 let compiler = self.compiler;
801 builder.ensure(compile::Test { compiler, target: compiler.host });
803 // Do a breadth-first traversal of the `src/doc` directory and just run
804 // tests for all files that end in `*.md`
805 let mut stack = vec![build.src.join("src/doc")];
806 let _time = util::timeit();
807 let _folder = build.fold_output(|| "test_docs");
809 while let Some(p) = stack.pop() {
811 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
815 if p.extension().and_then(|s| s.to_str()) != Some("md") {
819 // The nostarch directory in the book is for no starch, and so isn't
820 // guaranteed to build. We don't care if it doesn't build, so skip it.
821 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
825 markdown_test(builder, compiler, &p);
830 //rules.test("check-error-index", "src/tools/error_index_generator")
831 // .dep(|s| s.name("libstd"))
832 // .dep(|s| s.name("tool-error-index").host(s.host).stage(0))
835 // .run(move |s| check::error_index(build, &s.compiler()));
838 pub struct ErrorIndex<'a> {
839 compiler: Compiler<'a>,
842 impl<'a> Step<'a> for ErrorIndex<'a> {
844 const DEFAULT: bool = true;
845 const ONLY_HOSTS: bool = true;
847 fn should_run(_builder: &Builder, path: &Path) -> bool {
848 path.ends_with("src/tools/error_index_generator")
851 fn make_run(builder: &Builder, _path: Option<&Path>, host: &str, _target: &str) {
852 builder.ensure(ErrorIndex {
853 compiler: builder.compiler(builder.top_stage, host),
857 /// Run the error index generator tool to execute the tests located in the error
860 /// The `error_index_generator` tool lives in `src/tools` and is used to
861 /// generate a markdown file from the error indexes of the code base which is
862 /// then passed to `rustdoc --test`.
863 fn run(self, builder: &Builder) {
864 let build = builder.build;
865 let compiler = self.compiler;
867 builder.ensure(compile::Std { compiler, target: compiler.host });
869 let _folder = build.fold_output(|| "test_error_index");
870 println!("Testing error-index stage{}", compiler.stage);
872 let dir = testdir(build, compiler.host);
873 t!(fs::create_dir_all(&dir));
874 let output = dir.join("error-index.md");
876 let _time = util::timeit();
877 build.run(builder.tool_cmd(Tool::ErrorIndex)
880 .env("CFG_BUILD", &build.build));
882 markdown_test(builder, compiler, &output);
886 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
887 let build = builder.build;
888 let mut file = t!(File::open(markdown));
889 let mut contents = String::new();
890 t!(file.read_to_string(&mut contents));
891 if !contents.contains("```") {
895 println!("doc tests for: {}", markdown.display());
896 let mut cmd = Command::new(builder.rustdoc(compiler));
897 builder.add_rustc_lib_path(compiler, &mut cmd);
898 build.add_rust_test_threads(&mut cmd);
901 cmd.env("RUSTC_BOOTSTRAP", "1");
903 let test_args = build.flags.cmd.test_args().join(" ");
904 cmd.arg("--test-args").arg(test_args);
906 if build.config.quiet_tests {
907 try_run_quiet(build, &mut cmd);
909 try_run(build, &mut cmd);
913 // for (krate, path, _default) in krates("rustc-main") {
914 // rules.test(&krate.test_step, path)
915 // .dep(|s| s.name("librustc"))
916 // .dep(|s| s.name("remote-copy-libs"))
918 // .run(move |s| check::krate(build, &s.compiler(), s.target,
919 // Mode::Librustc, TestKind::Test,
920 // Some(&krate.name)));
922 // rules.test("check-rustc-all", "path/to/nowhere")
923 // .dep(|s| s.name("librustc"))
924 // .dep(|s| s.name("remote-copy-libs"))
927 // .run(move |s| check::krate(build, &s.compiler(), s.target,
928 // Mode::Librustc, TestKind::Test, None));
930 pub struct KrateLibrustc<'a> {
931 compiler: Compiler<'a>,
934 krate: Option<&'a str>,
937 impl<'a> Step<'a> for KrateLibrustc<'a> {
939 const DEFAULT: bool = true;
940 const ONLY_HOSTS: bool = true;
942 fn should_run(builder: &Builder, path: &Path) -> bool {
943 builder.crates("rustc-main").into_iter().any(|(_, krate_path)| {
944 path.ends_with(krate_path)
948 fn make_run(builder: &Builder, path: Option<&Path>, host: &str, target: &str) {
949 let compiler = builder.compiler(builder.top_stage, host);
951 let run = |name: Option<&str>| {
952 let test_kind = if builder.kind == Kind::Test {
954 } else if builder.kind == Kind::Bench {
957 panic!("unexpected builder.kind in Krate: {:?}", builder.kind);
960 builder.ensure(KrateLibrustc {
963 test_kind: test_kind,
968 if let Some(path) = path {
969 for (name, krate_path) in builder.crates("rustc-main") {
970 if path.ends_with(krate_path) {
980 fn run(self, builder: &Builder) {
981 builder.ensure(Krate {
982 compiler: self.compiler,
984 mode: Mode::Librustc,
985 test_kind: self.test_kind,
992 // for (krate, path, _default) in krates("std") {
993 // rules.test(&krate.test_step, path)
994 // .dep(|s| s.name("libtest"))
995 // .dep(|s| s.name("remote-copy-libs"))
996 // .run(move |s| check::krate(build, &s.compiler(), s.target,
997 // Mode::Libstd, TestKind::Test,
998 // Some(&krate.name)));
1000 // rules.test("check-std-all", "path/to/nowhere")
1001 // .dep(|s| s.name("libtest"))
1002 // .dep(|s| s.name("remote-copy-libs"))
1004 // .run(move |s| check::krate(build, &s.compiler(), s.target,
1005 // Mode::Libstd, TestKind::Test, None));
1007 // // std benchmarks
1008 // for (krate, path, _default) in krates("std") {
1009 // rules.bench(&krate.bench_step, path)
1010 // .dep(|s| s.name("libtest"))
1011 // .dep(|s| s.name("remote-copy-libs"))
1012 // .run(move |s| check::krate(build, &s.compiler(), s.target,
1013 // Mode::Libstd, TestKind::Bench,
1014 // Some(&krate.name)));
1016 // rules.bench("bench-std-all", "path/to/nowhere")
1017 // .dep(|s| s.name("libtest"))
1018 // .dep(|s| s.name("remote-copy-libs"))
1020 // .run(move |s| check::krate(build, &s.compiler(), s.target,
1021 // Mode::Libstd, TestKind::Bench, None));
1023 // for (krate, path, _default) in krates("test") {
1024 // rules.test(&krate.test_step, path)
1025 // .dep(|s| s.name("libtest"))
1026 // .dep(|s| s.name("remote-copy-libs"))
1027 // .run(move |s| check::krate(build, &s.compiler(), s.target,
1028 // Mode::Libtest, TestKind::Test,
1029 // Some(&krate.name)));
1031 // rules.test("check-test-all", "path/to/nowhere")
1032 // .dep(|s| s.name("libtest"))
1033 // .dep(|s| s.name("remote-copy-libs"))
1035 // .run(move |s| check::krate(build, &s.compiler(), s.target,
1036 // Mode::Libtest, TestKind::Test, None));
1038 #[derive(Serialize)]
1039 pub struct Krate<'a> {
1040 compiler: Compiler<'a>,
1043 test_kind: TestKind,
1044 krate: Option<&'a str>,
1047 impl<'a> Step<'a> for Krate<'a> {
1049 const DEFAULT: bool = true;
1051 fn should_run(builder: &Builder, path: &Path) -> bool {
1052 builder.crates("std").into_iter().any(|(_, krate_path)| {
1053 path.ends_with(krate_path)
1055 builder.crates("test").into_iter().any(|(_, krate_path)| {
1056 path.ends_with(krate_path)
1060 fn make_run(builder: &Builder, path: Option<&Path>, host: &str, target: &str) {
1061 let compiler = builder.compiler(builder.top_stage, host);
1063 let run = |mode: Mode, name: Option<&str>| {
1064 let test_kind = if builder.kind == Kind::Test {
1066 } else if builder.kind == Kind::Bench {
1069 panic!("unexpected builder.kind in Krate: {:?}", builder.kind);
1072 builder.ensure(Krate {
1075 test_kind: test_kind,
1080 if let Some(path) = path {
1081 for (name, krate_path) in builder.crates("std") {
1082 if path.ends_with(krate_path) {
1083 run(Mode::Libstd, Some(name));
1086 for (name, krate_path) in builder.crates("test") {
1087 if path.ends_with(krate_path) {
1088 run(Mode::Libtest, Some(name));
1092 run(Mode::Libstd, None);
1093 run(Mode::Libtest, None);
1097 /// Run all unit tests plus documentation tests for an entire crate DAG defined
1098 /// by a `Cargo.toml`
1100 /// This is what runs tests for crates like the standard library, compiler, etc.
1101 /// It essentially is the driver for running `cargo test`.
1103 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1104 /// arguments, and those arguments are discovered from `cargo metadata`.
1105 fn run(self, builder: &Builder) {
1106 let build = builder.build;
1107 let compiler = self.compiler;
1108 let target = self.target;
1109 let mode = self.mode;
1110 let test_kind = self.test_kind;
1111 let krate = self.krate;
1113 builder.ensure(compile::Test { compiler, target });
1114 builder.ensure(RemoteCopyLibs { compiler, target });
1115 let (name, path, features, root) = match mode {
1117 ("libstd", "src/libstd", build.std_features(), "std")
1120 ("libtest", "src/libtest", String::new(), "test")
1123 builder.ensure(compile::Rustc { compiler, target });
1124 ("librustc", "src/rustc", build.rustc_features(), "rustc-main")
1126 _ => panic!("can only test libraries"),
1128 let _folder = build.fold_output(|| {
1129 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
1131 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
1132 compiler.host, target);
1134 // If we're not doing a full bootstrap but we're testing a stage2 version of
1135 // libstd, then what we're actually testing is the libstd produced in
1136 // stage1. Reflect that here by updating the compiler that we're working
1137 // with automatically.
1138 let compiler = if build.force_use_stage1(compiler, target) {
1139 builder.compiler(1, compiler.host)
1144 // Build up the base `cargo test` command.
1146 // Pass in some standard flags then iterate over the graph we've discovered
1147 // in `cargo metadata` with the maps above and figure out what `-p`
1148 // arguments need to get passed.
1149 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1150 cargo.arg("--manifest-path")
1151 .arg(build.src.join(path).join("Cargo.toml"))
1152 .arg("--features").arg(features);
1153 if test_kind.subcommand() == "test" && !build.fail_fast {
1154 cargo.arg("--no-fail-fast");
1159 cargo.arg("-p").arg(krate);
1162 let mut visited = HashSet::new();
1163 let mut next = vec![root];
1164 while let Some(name) = next.pop() {
1165 // Right now jemalloc is our only target-specific crate in the
1166 // sense that it's not present on all platforms. Custom skip it
1167 // here for now, but if we add more this probably wants to get
1168 // more generalized.
1170 // Also skip `build_helper` as it's not compiled normally for
1171 // target during the bootstrap and it's just meant to be a
1172 // helper crate, not tested. If it leaks through then it ends up
1173 // messing with various mtime calculations and such.
1174 if !name.contains("jemalloc") && name != "build_helper" {
1175 cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1177 for dep in build.crates[name].deps.iter() {
1178 if visited.insert(dep) {
1186 // The tests are going to run with the *target* libraries, so we need to
1187 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1189 // Note that to run the compiler we need to run with the *host* libraries,
1190 // but our wrapper scripts arrange for that to be the case anyway.
1191 let mut dylib_path = dylib_path();
1192 dylib_path.insert(0, builder.sysroot_libdir(compiler, target));
1193 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1195 if target.contains("emscripten") || build.remote_tested(target) {
1196 cargo.arg("--no-run");
1201 if build.config.quiet_tests {
1202 cargo.arg("--quiet");
1205 let _time = util::timeit();
1207 if target.contains("emscripten") {
1208 build.run(&mut cargo);
1209 krate_emscripten(build, compiler, target, mode);
1210 } else if build.remote_tested(target) {
1211 build.run(&mut cargo);
1212 krate_remote(builder, compiler, target, mode);
1214 cargo.args(&build.flags.cmd.test_args());
1215 try_run(build, &mut cargo);
1220 fn krate_emscripten(build: &Build,
1224 let out_dir = build.cargo_out(compiler, mode, target);
1225 let tests = find_tests(&out_dir.join("deps"), target);
1227 let nodejs = build.config.nodejs.as_ref().expect("nodejs not configured");
1229 println!("running {}", test.display());
1230 let mut cmd = Command::new(nodejs);
1232 if build.config.quiet_tests {
1235 try_run(build, &mut cmd);
1239 fn krate_remote(builder: &Builder,
1243 let build = builder.build;
1244 let out_dir = build.cargo_out(compiler, mode, target);
1245 let tests = find_tests(&out_dir.join("deps"), target);
1247 let tool = builder.tool_exe(Tool::RemoteTestClient);
1249 let mut cmd = Command::new(&tool);
1252 if build.config.quiet_tests {
1255 cmd.args(&build.flags.cmd.test_args());
1256 try_run(build, &mut cmd);
1260 fn find_tests(dir: &Path, target: &str) -> Vec<PathBuf> {
1261 let mut dst = Vec::new();
1262 for e in t!(dir.read_dir()).map(|e| t!(e)) {
1263 let file_type = t!(e.file_type());
1264 if !file_type.is_file() {
1267 let filename = e.file_name().into_string().unwrap();
1268 if (target.contains("windows") && filename.ends_with(".exe")) ||
1269 (!target.contains("windows") && !filename.contains(".")) ||
1270 (target.contains("emscripten") &&
1271 filename.ends_with(".js") &&
1272 !filename.ends_with(".asm.js")) {
1279 // rules.test("remote-copy-libs", "path/to/nowhere")
1280 // .dep(|s| s.name("libtest"))
1282 // if build.remote_tested(s.target) {
1283 // s.name("tool-remote-test-client").target(s.host).stage(0)
1289 // if build.remote_tested(s.target) {
1290 // s.name("tool-remote-test-server")
1295 // .run(move |s| check::remote_copy_libs(build, &s.compiler(), s.target));
1298 /// Some test suites are run inside emulators or on remote devices, and most
1299 /// of our test binaries are linked dynamically which means we need to ship
1300 /// the standard library and such to the emulator ahead of time. This step
1301 /// represents this and is a dependency of all test suites.
1303 /// Most of the time this is a noop. For some steps such as shipping data to
1304 /// QEMU we have to build our own tools so we've got conditional dependencies
1305 /// on those programs as well. Note that the remote test client is built for
1306 /// the build target (us) and the server is built for the target.
1307 #[derive(Serialize)]
1308 pub struct RemoteCopyLibs<'a> {
1309 compiler: Compiler<'a>,
1313 impl<'a> Step<'a> for RemoteCopyLibs<'a> {
1316 fn run(self, builder: &Builder) {
1317 let build = builder.build;
1318 let compiler = self.compiler;
1319 let target = self.target;
1320 if !build.remote_tested(target) {
1324 builder.ensure(compile::Test { compiler, target });
1326 println!("REMOTE copy libs to emulator ({})", target);
1327 t!(fs::create_dir_all(build.out.join("tmp")));
1329 let server = builder.ensure(tool::RemoteTestServer { compiler, target }));
1331 // Spawn the emulator and wait for it to come online
1332 let tool = builder.tool_exe(Tool::RemoteTestClient);
1333 let mut cmd = Command::new(&tool);
1334 cmd.arg("spawn-emulator")
1337 .arg(build.out.join("tmp"));
1338 if let Some(rootfs) = build.qemu_rootfs(target) {
1341 build.run(&mut cmd);
1343 // Push all our dylibs to the emulator
1344 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1346 let name = f.file_name().into_string().unwrap();
1347 if util::is_dylib(&name) {
1348 build.run(Command::new(&tool)
1356 //rules.test("check-distcheck", "distcheck")
1357 // .dep(|s| s.name("dist-plain-source-tarball"))
1358 // .dep(|s| s.name("dist-src"))
1359 // .run(move |_| check::distcheck(build));
1361 #[derive(Serialize)]
1362 pub struct Distcheck;
1364 impl<'a> Step<'a> for Distcheck {
1367 /// Run "distcheck", a 'make check' from a tarball
1368 fn run(self, builder: &Builder) {
1369 let build = builder.build;
1371 builder.ensure(dist::PlainSourceTarball);
1372 builder.ensure(dist::Src);
1374 if build.build != "x86_64-unknown-linux-gnu" {
1377 if !build.config.host.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
1380 if !build.config.target.iter().any(|s| s == "x86_64-unknown-linux-gnu") {
1384 println!("Distcheck");
1385 let dir = build.out.join("tmp").join("distcheck");
1386 let _ = fs::remove_dir_all(&dir);
1387 t!(fs::create_dir_all(&dir));
1389 let mut cmd = Command::new("tar");
1391 .arg(dist::rust_src_location(build))
1392 .arg("--strip-components=1")
1394 build.run(&mut cmd);
1395 build.run(Command::new("./configure")
1396 .args(&build.config.configure_args)
1397 .arg("--enable-vendor")
1398 .current_dir(&dir));
1399 build.run(Command::new(build_helper::make(&build.build))
1401 .current_dir(&dir));
1403 // Now make sure that rust-src has all of libstd's dependencies
1404 println!("Distcheck rust-src");
1405 let dir = build.out.join("tmp").join("distcheck-src");
1406 let _ = fs::remove_dir_all(&dir);
1407 t!(fs::create_dir_all(&dir));
1409 let mut cmd = Command::new("tar");
1411 .arg(dist::rust_src_installer(build))
1412 .arg("--strip-components=1")
1414 build.run(&mut cmd);
1416 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1417 build.run(Command::new(&build.initial_cargo)
1418 .arg("generate-lockfile")
1419 .arg("--manifest-path")
1421 .current_dir(&dir));
1425 //rules.test("check-bootstrap", "src/bootstrap")
1428 // .only_build(true)
1429 // .run(move |_| check::bootstrap(build));
1431 #[derive(Serialize)]
1432 pub struct Bootstrap;
1434 impl<'a> Step<'a> for Bootstrap {
1436 const DEFAULT: bool = true;
1437 const ONLY_HOSTS: bool = true;
1438 const ONLY_BUILD: bool = true;
1440 /// Test the build system itself
1441 fn run(self, builder: &Builder) {
1442 let build = builder.build;
1443 let mut cmd = Command::new(&build.initial_cargo);
1445 .current_dir(build.src.join("src/bootstrap"))
1446 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1447 .env("RUSTC_BOOTSTRAP", "1")
1448 .env("RUSTC", &build.initial_rustc);
1449 if !build.fail_fast {
1450 cmd.arg("--no-fail-fast");
1452 cmd.arg("--").args(&build.flags.cmd.test_args());
1453 try_run(build, &mut cmd);
1456 fn should_run(_builder: &Builder, path: &Path) -> bool {
1457 path.ends_with("src/bootstrap")
1460 fn make_run(builder: &Builder, _path: Option<&Path>, _host: &str, _target: &str) {
1461 builder.ensure(Bootstrap);