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, BuildExpectation};
28 use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
29 use cache::{INTERNER, Interned};
33 use tool::{self, Tool};
34 use util::{self, dylib_path, dylib_path_var};
36 use toolstate::ToolState;
38 const ADB_TEST_DIR: &str = "/data/tmp/work";
40 /// The two modes of the test runner; tests or benchmarks.
41 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
50 // Return the cargo subcommand for this test kind
51 fn subcommand(self) -> &'static str {
53 TestKind::Test => "test",
54 TestKind::Bench => "bench",
59 impl fmt::Display for TestKind {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 f.write_str(match *self {
62 TestKind::Test => "Testing",
63 TestKind::Bench => "Benchmarking",
68 fn try_run_expecting(build: &Build, cmd: &mut Command, expect: BuildExpectation) {
70 if !build.try_run(cmd, expect) {
71 let mut failures = build.delayed_failures.borrow_mut();
72 failures.push(format!("{:?}", cmd));
75 build.run_expecting(cmd, expect);
79 fn try_run(build: &Build, cmd: &mut Command) {
80 try_run_expecting(build, cmd, BuildExpectation::None)
83 fn try_run_quiet(build: &Build, cmd: &mut Command) {
85 if !build.try_run_quiet(cmd) {
86 let mut failures = build.delayed_failures.borrow_mut();
87 failures.push(format!("{:?}", cmd));
94 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
95 pub struct Linkcheck {
96 host: Interned<String>,
99 impl Step for Linkcheck {
101 const ONLY_HOSTS: bool = true;
102 const DEFAULT: bool = true;
104 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
106 /// This tool in `src/tools` will verify the validity of all our links in the
107 /// documentation to ensure we don't have a bunch of dead ones.
108 fn run(self, builder: &Builder) {
109 let build = builder.build;
110 let host = self.host;
112 println!("Linkcheck ({})", host);
114 builder.default_doc(None);
116 let _time = util::timeit();
117 try_run(build, builder.tool_cmd(Tool::Linkchecker)
118 .arg(build.out.join(host).join("doc")));
121 fn should_run(run: ShouldRun) -> ShouldRun {
122 let builder = run.builder;
123 run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
126 fn make_run(run: RunConfig) {
127 run.builder.ensure(Linkcheck { host: run.target });
131 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
132 pub struct Cargotest {
134 host: Interned<String>,
137 impl Step for Cargotest {
139 const ONLY_HOSTS: bool = true;
141 fn should_run(run: ShouldRun) -> ShouldRun {
142 run.path("src/tools/cargotest")
145 fn make_run(run: RunConfig) {
146 run.builder.ensure(Cargotest {
147 stage: run.builder.top_stage,
152 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
154 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
155 /// test` to ensure that we don't regress the test suites there.
156 fn run(self, builder: &Builder) {
157 let build = builder.build;
158 let compiler = builder.compiler(self.stage, self.host);
159 builder.ensure(compile::Rustc { compiler, target: compiler.host });
161 // Note that this is a short, cryptic, and not scoped directory name. This
162 // is currently to minimize the length of path on Windows where we otherwise
163 // quickly run into path name limit constraints.
164 let out_dir = build.out.join("ct");
165 t!(fs::create_dir_all(&out_dir));
167 let _time = util::timeit();
168 let mut cmd = builder.tool_cmd(Tool::CargoTest);
169 try_run(build, cmd.arg(&build.initial_cargo)
171 .env("RUSTC", builder.rustc(compiler))
172 .env("RUSTDOC", builder.rustdoc(compiler.host)));
176 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
179 host: Interned<String>,
182 impl Step for Cargo {
184 const ONLY_HOSTS: bool = true;
186 fn should_run(run: ShouldRun) -> ShouldRun {
187 run.path("src/tools/cargo")
190 fn make_run(run: RunConfig) {
191 run.builder.ensure(Cargo {
192 stage: run.builder.top_stage,
197 /// Runs `cargo test` for `cargo` packaged with Rust.
198 fn run(self, builder: &Builder) {
199 let build = builder.build;
200 let compiler = builder.compiler(self.stage, self.host);
202 builder.ensure(tool::Cargo { compiler, target: self.host });
203 let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
204 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
205 if !build.fail_fast {
206 cargo.arg("--no-fail-fast");
209 // Don't build tests dynamically, just a pain to work with
210 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
212 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
214 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
216 try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
220 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
223 host: Interned<String>,
228 const ONLY_HOSTS: bool = true;
230 fn should_run(run: ShouldRun) -> ShouldRun {
231 run.path("src/tools/rls")
234 fn make_run(run: RunConfig) {
235 run.builder.ensure(Rls {
236 stage: run.builder.top_stage,
241 /// Runs `cargo test` for the rls.
242 fn run(self, builder: &Builder) {
243 let build = builder.build;
244 let stage = self.stage;
245 let host = self.host;
246 let compiler = builder.compiler(stage, host);
248 builder.ensure(tool::Rls { compiler, target: self.host });
249 let mut cargo = tool::prepare_tool_cargo(builder,
255 // Don't build tests dynamically, just a pain to work with
256 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
258 builder.add_rustc_lib_path(compiler, &mut cargo);
263 builder.build.config.toolstate.rls.passes(ToolState::Testing),
268 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
271 host: Interned<String>,
274 impl Step for Rustfmt {
276 const ONLY_HOSTS: bool = true;
278 fn should_run(run: ShouldRun) -> ShouldRun {
279 run.path("src/tools/rustfmt")
282 fn make_run(run: RunConfig) {
283 run.builder.ensure(Rustfmt {
284 stage: run.builder.top_stage,
289 /// Runs `cargo test` for rustfmt.
290 fn run(self, builder: &Builder) {
291 let build = builder.build;
292 let stage = self.stage;
293 let host = self.host;
294 let compiler = builder.compiler(stage, host);
296 builder.ensure(tool::Rustfmt { compiler, target: self.host });
297 let mut cargo = tool::prepare_tool_cargo(builder,
301 "src/tools/rustfmt");
303 // Don't build tests dynamically, just a pain to work with
304 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
306 builder.add_rustc_lib_path(compiler, &mut cargo);
311 builder.build.config.toolstate.rustfmt.passes(ToolState::Testing),
316 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
318 host: Interned<String>,
323 const ONLY_HOSTS: bool = true;
324 const DEFAULT: bool = true;
326 fn should_run(run: ShouldRun) -> ShouldRun {
327 let test_miri = run.builder.build.config.test_miri;
328 run.path("src/tools/miri").default_condition(test_miri)
331 fn make_run(run: RunConfig) {
332 run.builder.ensure(Miri {
337 /// Runs `cargo test` for miri.
338 fn run(self, builder: &Builder) {
339 let build = builder.build;
340 let host = self.host;
341 let compiler = builder.compiler(1, host);
343 if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
344 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
345 cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
347 // Don't build tests dynamically, just a pain to work with
348 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
349 // miri tests need to know about the stage sysroot
350 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
351 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
352 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
353 cargo.env("MIRI_PATH", miri);
355 builder.add_rustc_lib_path(compiler, &mut cargo);
360 builder.build.config.toolstate.miri.passes(ToolState::Testing),
363 eprintln!("failed to test miri: could not build");
368 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
371 host: Interned<String>,
374 impl Step for Clippy {
376 const ONLY_HOSTS: bool = true;
377 const DEFAULT: bool = false;
379 fn should_run(run: ShouldRun) -> ShouldRun {
380 run.path("src/tools/clippy")
383 fn make_run(run: RunConfig) {
384 run.builder.ensure(Clippy {
385 stage: run.builder.top_stage,
390 /// Runs `cargo test` for clippy.
391 fn run(self, builder: &Builder) {
392 let build = builder.build;
393 let stage = self.stage;
394 let host = self.host;
395 let compiler = builder.compiler(stage, host);
397 if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
398 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
399 cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
401 // Don't build tests dynamically, just a pain to work with
402 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
403 // clippy tests need to know about the stage sysroot
404 cargo.env("SYSROOT", builder.sysroot(compiler));
405 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
406 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
407 let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
408 cargo.env("HOST_LIBS", host_libs);
409 // clippy tests need to find the driver
410 cargo.env("CLIPPY_DRIVER_PATH", clippy);
412 builder.add_rustc_lib_path(compiler, &mut cargo);
417 builder.build.config.toolstate.clippy.passes(ToolState::Testing),
420 eprintln!("failed to test clippy: could not build");
425 fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
426 // Configure PATH to find the right rustc. NB. we have to use PATH
427 // and not RUSTC because the Cargo test suite has tests that will
428 // fail if rustc is not spelled `rustc`.
429 let path = builder.sysroot(compiler).join("bin");
430 let old_path = env::var_os("PATH").unwrap_or_default();
431 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
434 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
436 host: Interned<String>,
441 const DEFAULT: bool = true;
442 const ONLY_HOSTS: bool = true;
443 const ONLY_BUILD: bool = true;
445 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
447 /// This tool in `src/tools` checks up on various bits and pieces of style and
448 /// otherwise just implements a few lint-like checks that are specific to the
450 fn run(self, builder: &Builder) {
451 let build = builder.build;
452 let host = self.host;
454 let _folder = build.fold_output(|| "tidy");
455 println!("tidy check ({})", host);
456 let mut cmd = builder.tool_cmd(Tool::Tidy);
457 cmd.arg(build.src.join("src"));
458 if !build.config.vendor {
459 cmd.arg("--no-vendor");
461 if build.config.quiet_tests {
464 try_run(build, &mut cmd);
467 fn should_run(run: ShouldRun) -> ShouldRun {
468 run.path("src/tools/tidy")
471 fn make_run(run: RunConfig) {
472 run.builder.ensure(Tidy {
473 host: run.builder.build.build,
478 fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
479 build.out.join(host).join("test")
482 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
489 static DEFAULT_COMPILETESTS: &[Test] = &[
490 Test { path: "src/test/ui", mode: "ui", suite: "ui" },
491 Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
492 Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
493 Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
494 Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
496 path: "src/test/run-pass-valgrind",
497 mode: "run-pass-valgrind",
498 suite: "run-pass-valgrind"
500 Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
501 Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
502 Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
503 Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
505 // What this runs varies depending on the native platform being apple
506 Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
509 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
510 pub struct DefaultCompiletest {
512 target: Interned<String>,
517 impl Step for DefaultCompiletest {
519 const DEFAULT: bool = true;
521 fn should_run(mut run: ShouldRun) -> ShouldRun {
522 for test in DEFAULT_COMPILETESTS {
523 run = run.path(test.path);
528 fn make_run(run: RunConfig) {
529 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
531 let test = run.path.map(|path| {
532 DEFAULT_COMPILETESTS.iter().find(|&&test| {
533 path.ends_with(test.path)
534 }).unwrap_or_else(|| {
535 panic!("make_run in compile test to receive test path, received {:?}", path);
539 if let Some(test) = test {
540 run.builder.ensure(DefaultCompiletest {
547 for test in DEFAULT_COMPILETESTS {
548 run.builder.ensure(DefaultCompiletest {
558 fn run(self, builder: &Builder) {
559 builder.ensure(Compiletest {
560 compiler: self.compiler,
568 // Also default, but host-only.
569 static HOST_COMPILETESTS: &[Test] = &[
570 Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
571 Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
572 Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
574 path: "src/test/compile-fail-fulldeps",
575 mode: "compile-fail",
576 suite: "compile-fail-fulldeps",
578 Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
579 Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
581 Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
582 Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
583 Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
584 Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
585 Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
586 Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
589 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
590 pub struct HostCompiletest {
592 target: Interned<String>,
597 impl Step for HostCompiletest {
599 const DEFAULT: bool = true;
600 const ONLY_HOSTS: bool = true;
602 fn should_run(mut run: ShouldRun) -> ShouldRun {
603 for test in HOST_COMPILETESTS {
604 run = run.path(test.path);
609 fn make_run(run: RunConfig) {
610 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
612 let test = run.path.map(|path| {
613 HOST_COMPILETESTS.iter().find(|&&test| {
614 path.ends_with(test.path)
615 }).unwrap_or_else(|| {
616 panic!("make_run in compile test to receive test path, received {:?}", path);
620 if let Some(test) = test {
621 run.builder.ensure(HostCompiletest {
628 for test in HOST_COMPILETESTS {
629 if test.mode == "pretty" {
632 run.builder.ensure(HostCompiletest {
642 fn run(self, builder: &Builder) {
643 builder.ensure(Compiletest {
644 compiler: self.compiler,
652 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
655 target: Interned<String>,
660 impl Step for Compiletest {
663 fn should_run(run: ShouldRun) -> ShouldRun {
667 /// Executes the `compiletest` tool to run a suite of tests.
669 /// Compiles all tests with `compiler` for `target` with the specified
670 /// compiletest `mode` and `suite` arguments. For example `mode` can be
671 /// "run-pass" or `suite` can be something like `debuginfo`.
672 fn run(self, builder: &Builder) {
673 let build = builder.build;
674 let compiler = self.compiler;
675 let target = self.target;
676 let mode = self.mode;
677 let suite = self.suite;
679 // Skip codegen tests if they aren't enabled in configuration.
680 if !build.config.codegen_tests && suite == "codegen" {
684 if suite == "debuginfo" {
685 // Skip debuginfo tests on MSVC
686 if build.build.contains("msvc") {
690 if mode == "debuginfo-XXX" {
691 return if build.build.contains("apple") {
692 builder.ensure(Compiletest {
693 mode: "debuginfo-lldb",
697 builder.ensure(Compiletest {
698 mode: "debuginfo-gdb",
704 builder.ensure(dist::DebuggerScripts {
705 sysroot: builder.sysroot(compiler),
710 if suite.ends_with("fulldeps") ||
711 // FIXME: Does pretty need librustc compiled? Note that there are
712 // fulldeps test suites with mode = pretty as well.
716 builder.ensure(compile::Rustc { compiler, target });
719 builder.ensure(compile::Test { compiler, target });
720 builder.ensure(native::TestHelpers { target });
721 builder.ensure(RemoteCopyLibs { compiler, target });
723 let _folder = build.fold_output(|| format!("test_{}", suite));
724 println!("Check compiletest suite={} mode={} ({} -> {})",
725 suite, mode, &compiler.host, target);
726 let mut cmd = builder.tool_cmd(Tool::Compiletest);
728 // compiletest currently has... a lot of arguments, so let's just pass all
731 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
732 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
733 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
735 // Avoid depending on rustdoc when we don't need it.
736 if mode == "rustdoc" || mode == "run-make" {
737 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
740 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
741 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
742 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
743 cmd.arg("--mode").arg(mode);
744 cmd.arg("--target").arg(target);
745 cmd.arg("--host").arg(&*compiler.host);
746 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
748 if let Some(ref nodejs) = build.config.nodejs {
749 cmd.arg("--nodejs").arg(nodejs);
752 let mut flags = vec!["-Crpath".to_string()];
753 if build.config.rust_optimize_tests {
754 flags.push("-O".to_string());
756 if build.config.rust_debuginfo_tests {
757 flags.push("-g".to_string());
760 if let Some(linker) = build.linker(target) {
761 cmd.arg("--linker").arg(linker);
764 let hostflags = flags.clone();
765 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
767 let mut targetflags = flags.clone();
768 targetflags.push(format!("-Lnative={}",
769 build.test_helpers_out(target).display()));
770 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
772 cmd.arg("--docck-python").arg(build.python());
774 if build.build.ends_with("apple-darwin") {
775 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
776 // LLDB plugin's compiled module which only works with the system python
777 // (namely not Homebrew-installed python)
778 cmd.arg("--lldb-python").arg("/usr/bin/python");
780 cmd.arg("--lldb-python").arg(build.python());
783 if let Some(ref gdb) = build.config.gdb {
784 cmd.arg("--gdb").arg(gdb);
786 if let Some(ref vers) = build.lldb_version {
787 cmd.arg("--lldb-version").arg(vers);
789 if let Some(ref dir) = build.lldb_python_dir {
790 cmd.arg("--lldb-python-dir").arg(dir);
793 cmd.args(&build.config.cmd.test_args());
795 if build.is_verbose() {
796 cmd.arg("--verbose");
799 if build.config.quiet_tests {
803 if build.config.llvm_enabled {
804 let llvm_config = build.llvm_config(target);
805 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
806 cmd.arg("--llvm-version").arg(llvm_version);
807 if !build.is_rust_llvm(target) {
808 cmd.arg("--system-llvm");
811 // Only pass correct values for these flags for the `run-make` suite as it
812 // requires that a C++ compiler was configured which isn't always the case.
813 if suite == "run-make" {
814 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
815 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
816 cmd.arg("--cc").arg(build.cc(target))
817 .arg("--cxx").arg(build.cxx(target).unwrap())
818 .arg("--cflags").arg(build.cflags(target).join(" "))
819 .arg("--llvm-components").arg(llvm_components.trim())
820 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
821 if let Some(ar) = build.ar(target) {
822 cmd.arg("--ar").arg(ar);
826 if suite == "run-make" && !build.config.llvm_enabled {
827 println!("Ignoring run-make test suite as they generally dont work without LLVM");
831 if suite != "run-make" {
832 cmd.arg("--cc").arg("")
833 .arg("--cxx").arg("")
834 .arg("--cflags").arg("")
835 .arg("--llvm-components").arg("")
836 .arg("--llvm-cxxflags").arg("");
839 if build.remote_tested(target) {
840 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
843 // Running a C compiler on MSVC requires a few env vars to be set, to be
844 // sure to set them here.
846 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
847 // rather than stomp over it.
848 if target.contains("msvc") {
849 for &(ref k, ref v) in build.cc[&target].env() {
855 cmd.env("RUSTC_BOOTSTRAP", "1");
856 build.add_rust_test_threads(&mut cmd);
858 if build.config.sanitizers {
859 cmd.env("SANITIZER_SUPPORT", "1");
862 if build.config.profiler {
863 cmd.env("PROFILER_SUPPORT", "1");
866 cmd.arg("--adb-path").arg("adb");
867 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
868 if target.contains("android") {
869 // Assume that cc for this target comes from the android sysroot
870 cmd.arg("--android-cross-path")
871 .arg(build.cc(target).parent().unwrap().parent().unwrap());
873 cmd.arg("--android-cross-path").arg("");
876 build.ci_env.force_coloring_in_ci(&mut cmd);
878 let _time = util::timeit();
879 try_run(build, &mut cmd);
883 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
890 const DEFAULT: bool = true;
891 const ONLY_HOSTS: bool = true;
893 fn should_run(run: ShouldRun) -> ShouldRun {
897 fn make_run(run: RunConfig) {
898 run.builder.ensure(Docs {
899 compiler: run.builder.compiler(run.builder.top_stage, run.host),
903 /// Run `rustdoc --test` for all documentation in `src/doc`.
905 /// This will run all tests in our markdown documentation (e.g. the book)
906 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
908 fn run(self, builder: &Builder) {
909 let build = builder.build;
910 let compiler = self.compiler;
912 builder.ensure(compile::Test { compiler, target: compiler.host });
914 // Do a breadth-first traversal of the `src/doc` directory and just run
915 // tests for all files that end in `*.md`
916 let mut stack = vec![build.src.join("src/doc")];
917 let _time = util::timeit();
918 let _folder = build.fold_output(|| "test_docs");
920 while let Some(p) = stack.pop() {
922 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
926 if p.extension().and_then(|s| s.to_str()) != Some("md") {
930 // The nostarch directory in the book is for no starch, and so isn't
931 // guaranteed to build. We don't care if it doesn't build, so skip it.
932 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
936 markdown_test(builder, compiler, &p);
941 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
942 pub struct ErrorIndex {
946 impl Step for ErrorIndex {
948 const DEFAULT: bool = true;
949 const ONLY_HOSTS: bool = true;
951 fn should_run(run: ShouldRun) -> ShouldRun {
952 run.path("src/tools/error_index_generator")
955 fn make_run(run: RunConfig) {
956 run.builder.ensure(ErrorIndex {
957 compiler: run.builder.compiler(run.builder.top_stage, run.host),
961 /// Run the error index generator tool to execute the tests located in the error
964 /// The `error_index_generator` tool lives in `src/tools` and is used to
965 /// generate a markdown file from the error indexes of the code base which is
966 /// then passed to `rustdoc --test`.
967 fn run(self, builder: &Builder) {
968 let build = builder.build;
969 let compiler = self.compiler;
971 builder.ensure(compile::Std { compiler, target: compiler.host });
973 let _folder = build.fold_output(|| "test_error_index");
974 println!("Testing error-index stage{}", compiler.stage);
976 let dir = testdir(build, compiler.host);
977 t!(fs::create_dir_all(&dir));
978 let output = dir.join("error-index.md");
980 let _time = util::timeit();
981 build.run(builder.tool_cmd(Tool::ErrorIndex)
984 .env("CFG_BUILD", &build.build));
986 markdown_test(builder, compiler, &output);
990 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
991 let build = builder.build;
992 let mut file = t!(File::open(markdown));
993 let mut contents = String::new();
994 t!(file.read_to_string(&mut contents));
995 if !contents.contains("```") {
999 println!("doc tests for: {}", markdown.display());
1000 let mut cmd = builder.rustdoc_cmd(compiler.host);
1001 build.add_rust_test_threads(&mut cmd);
1004 cmd.env("RUSTC_BOOTSTRAP", "1");
1006 let test_args = build.config.cmd.test_args().join(" ");
1007 cmd.arg("--test-args").arg(test_args);
1009 if build.config.quiet_tests {
1010 try_run_quiet(build, &mut cmd);
1012 try_run(build, &mut cmd);
1016 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1017 pub struct CrateLibrustc {
1019 target: Interned<String>,
1020 test_kind: TestKind,
1021 krate: Option<Interned<String>>,
1024 impl Step for CrateLibrustc {
1026 const DEFAULT: bool = true;
1027 const ONLY_HOSTS: bool = true;
1029 fn should_run(run: ShouldRun) -> ShouldRun {
1030 run.krate("rustc-main")
1033 fn make_run(run: RunConfig) {
1034 let builder = run.builder;
1035 let compiler = builder.compiler(builder.top_stage, run.host);
1037 let make = |name: Option<Interned<String>>| {
1038 let test_kind = if builder.kind == Kind::Test {
1040 } else if builder.kind == Kind::Bench {
1043 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1046 builder.ensure(CrateLibrustc {
1054 if let Some(path) = run.path {
1055 for (name, krate_path) in builder.crates("rustc-main") {
1056 if path.ends_with(krate_path) {
1066 fn run(self, builder: &Builder) {
1067 builder.ensure(Crate {
1068 compiler: self.compiler,
1069 target: self.target,
1070 mode: Mode::Librustc,
1071 test_kind: self.test_kind,
1077 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1080 target: Interned<String>,
1082 test_kind: TestKind,
1083 krate: Option<Interned<String>>,
1086 impl Step for Crate {
1088 const DEFAULT: bool = true;
1090 fn should_run(run: ShouldRun) -> ShouldRun {
1091 run.krate("std").krate("test")
1094 fn make_run(run: RunConfig) {
1095 let builder = run.builder;
1096 let compiler = builder.compiler(builder.top_stage, run.host);
1098 let make = |mode: Mode, name: Option<Interned<String>>| {
1099 let test_kind = if builder.kind == Kind::Test {
1101 } else if builder.kind == Kind::Bench {
1104 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1107 builder.ensure(Crate {
1116 if let Some(path) = run.path {
1117 for (name, krate_path) in builder.crates("std") {
1118 if path.ends_with(krate_path) {
1119 make(Mode::Libstd, Some(name));
1122 for (name, krate_path) in builder.crates("test") {
1123 if path.ends_with(krate_path) {
1124 make(Mode::Libtest, Some(name));
1128 make(Mode::Libstd, None);
1129 make(Mode::Libtest, None);
1133 /// Run all unit tests plus documentation tests for an entire crate DAG defined
1134 /// by a `Cargo.toml`
1136 /// This is what runs tests for crates like the standard library, compiler, etc.
1137 /// It essentially is the driver for running `cargo test`.
1139 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1140 /// arguments, and those arguments are discovered from `cargo metadata`.
1141 fn run(self, builder: &Builder) {
1142 let build = builder.build;
1143 let compiler = self.compiler;
1144 let target = self.target;
1145 let mode = self.mode;
1146 let test_kind = self.test_kind;
1147 let krate = self.krate;
1149 builder.ensure(compile::Test { compiler, target });
1150 builder.ensure(RemoteCopyLibs { compiler, target });
1152 // If we're not doing a full bootstrap but we're testing a stage2 version of
1153 // libstd, then what we're actually testing is the libstd produced in
1154 // stage1. Reflect that here by updating the compiler that we're working
1155 // with automatically.
1156 let compiler = if build.force_use_stage1(compiler, target) {
1157 builder.compiler(1, compiler.host)
1162 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1163 let (name, root) = match mode {
1165 compile::std_cargo(build, &compiler, target, &mut cargo);
1169 compile::test_cargo(build, &compiler, target, &mut cargo);
1173 builder.ensure(compile::Rustc { compiler, target });
1174 compile::rustc_cargo(build, &compiler, target, &mut cargo);
1175 ("librustc", "rustc-main")
1177 _ => panic!("can only test libraries"),
1179 let root = INTERNER.intern_string(String::from(root));
1180 let _folder = build.fold_output(|| {
1181 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
1183 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
1184 &compiler.host, target);
1186 // Build up the base `cargo test` command.
1188 // Pass in some standard flags then iterate over the graph we've discovered
1189 // in `cargo metadata` with the maps above and figure out what `-p`
1190 // arguments need to get passed.
1191 if test_kind.subcommand() == "test" && !build.fail_fast {
1192 cargo.arg("--no-fail-fast");
1197 cargo.arg("-p").arg(krate);
1200 let mut visited = HashSet::new();
1201 let mut next = vec![root];
1202 while let Some(name) = next.pop() {
1203 // Right now jemalloc and the sanitizer crates are
1204 // target-specific crate in the sense that it's not present
1205 // on all platforms. Custom skip it here for now, but if we
1206 // add more this probably wants to get more generalized.
1208 // Also skip `build_helper` as it's not compiled normally
1209 // for target during the bootstrap and it's just meant to be
1210 // a helper crate, not tested. If it leaks through then it
1211 // ends up messing with various mtime calculations and such.
1212 if !name.contains("jemalloc") &&
1213 *name != *"build_helper" &&
1214 !(name.starts_with("rustc_") && name.ends_with("san")) &&
1215 name != "dlmalloc" {
1216 cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1218 for dep in build.crates[&name].deps.iter() {
1219 if visited.insert(dep) {
1227 // The tests are going to run with the *target* libraries, so we need to
1228 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1230 // Note that to run the compiler we need to run with the *host* libraries,
1231 // but our wrapper scripts arrange for that to be the case anyway.
1232 let mut dylib_path = dylib_path();
1233 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1234 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1237 cargo.args(&build.config.cmd.test_args());
1239 if build.config.quiet_tests {
1240 cargo.arg("--quiet");
1243 let _time = util::timeit();
1245 if target.contains("emscripten") {
1246 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1247 build.config.nodejs.as_ref().expect("nodejs not configured"));
1248 } else if target.starts_with("wasm32") {
1249 // On the wasm32-unknown-unknown target we're using LTO which is
1250 // incompatible with `-C prefer-dynamic`, so disable that here
1251 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1253 let node = build.config.nodejs.as_ref()
1254 .expect("nodejs not configured");
1255 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1257 build.src.display());
1258 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1259 } else if build.remote_tested(target) {
1260 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1262 builder.tool_exe(Tool::RemoteTestClient).display()));
1264 try_run(build, &mut cargo);
1268 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1269 pub struct Rustdoc {
1270 host: Interned<String>,
1271 test_kind: TestKind,
1274 impl Step for Rustdoc {
1276 const DEFAULT: bool = true;
1277 const ONLY_HOSTS: bool = true;
1279 fn should_run(run: ShouldRun) -> ShouldRun {
1280 run.path("src/librustdoc").path("src/tools/rustdoc")
1283 fn make_run(run: RunConfig) {
1284 let builder = run.builder;
1286 let test_kind = if builder.kind == Kind::Test {
1288 } else if builder.kind == Kind::Bench {
1291 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1294 builder.ensure(Rustdoc {
1300 fn run(self, builder: &Builder) {
1301 let build = builder.build;
1302 let test_kind = self.test_kind;
1304 let compiler = builder.compiler(builder.top_stage, self.host);
1305 let target = compiler.host;
1307 let mut cargo = tool::prepare_tool_cargo(builder,
1310 test_kind.subcommand(),
1311 "src/tools/rustdoc");
1312 let _folder = build.fold_output(|| {
1313 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1315 println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1316 &compiler.host, target);
1318 if test_kind.subcommand() == "test" && !build.fail_fast {
1319 cargo.arg("--no-fail-fast");
1322 cargo.arg("-p").arg("rustdoc:0.0.0");
1325 cargo.args(&build.config.cmd.test_args());
1327 if build.config.quiet_tests {
1328 cargo.arg("--quiet");
1331 let _time = util::timeit();
1333 try_run(build, &mut cargo);
1337 fn envify(s: &str) -> String {
1343 }).flat_map(|c| c.to_uppercase()).collect()
1346 /// Some test suites are run inside emulators or on remote devices, and most
1347 /// of our test binaries are linked dynamically which means we need to ship
1348 /// the standard library and such to the emulator ahead of time. This step
1349 /// represents this and is a dependency of all test suites.
1351 /// Most of the time this is a noop. For some steps such as shipping data to
1352 /// QEMU we have to build our own tools so we've got conditional dependencies
1353 /// on those programs as well. Note that the remote test client is built for
1354 /// the build target (us) and the server is built for the target.
1355 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1356 pub struct RemoteCopyLibs {
1358 target: Interned<String>,
1361 impl Step for RemoteCopyLibs {
1364 fn should_run(run: ShouldRun) -> ShouldRun {
1368 fn run(self, builder: &Builder) {
1369 let build = builder.build;
1370 let compiler = self.compiler;
1371 let target = self.target;
1372 if !build.remote_tested(target) {
1376 builder.ensure(compile::Test { compiler, target });
1378 println!("REMOTE copy libs to emulator ({})", target);
1379 t!(fs::create_dir_all(build.out.join("tmp")));
1381 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1383 // Spawn the emulator and wait for it to come online
1384 let tool = builder.tool_exe(Tool::RemoteTestClient);
1385 let mut cmd = Command::new(&tool);
1386 cmd.arg("spawn-emulator")
1389 .arg(build.out.join("tmp"));
1390 if let Some(rootfs) = build.qemu_rootfs(target) {
1393 build.run(&mut cmd);
1395 // Push all our dylibs to the emulator
1396 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1398 let name = f.file_name().into_string().unwrap();
1399 if util::is_dylib(&name) {
1400 build.run(Command::new(&tool)
1408 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1409 pub struct Distcheck;
1411 impl Step for Distcheck {
1413 const ONLY_BUILD: bool = true;
1415 fn should_run(run: ShouldRun) -> ShouldRun {
1416 run.path("distcheck")
1419 fn make_run(run: RunConfig) {
1420 run.builder.ensure(Distcheck);
1423 /// Run "distcheck", a 'make check' from a tarball
1424 fn run(self, builder: &Builder) {
1425 let build = builder.build;
1427 println!("Distcheck");
1428 let dir = build.out.join("tmp").join("distcheck");
1429 let _ = fs::remove_dir_all(&dir);
1430 t!(fs::create_dir_all(&dir));
1432 // Guarantee that these are built before we begin running.
1433 builder.ensure(dist::PlainSourceTarball);
1434 builder.ensure(dist::Src);
1436 let mut cmd = Command::new("tar");
1438 .arg(builder.ensure(dist::PlainSourceTarball))
1439 .arg("--strip-components=1")
1441 build.run(&mut cmd);
1442 build.run(Command::new("./configure")
1443 .args(&build.config.configure_args)
1444 .arg("--enable-vendor")
1445 .current_dir(&dir));
1446 build.run(Command::new(build_helper::make(&build.build))
1448 .current_dir(&dir));
1450 // Now make sure that rust-src has all of libstd's dependencies
1451 println!("Distcheck rust-src");
1452 let dir = build.out.join("tmp").join("distcheck-src");
1453 let _ = fs::remove_dir_all(&dir);
1454 t!(fs::create_dir_all(&dir));
1456 let mut cmd = Command::new("tar");
1458 .arg(builder.ensure(dist::Src))
1459 .arg("--strip-components=1")
1461 build.run(&mut cmd);
1463 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1464 build.run(Command::new(&build.initial_cargo)
1465 .arg("generate-lockfile")
1466 .arg("--manifest-path")
1468 .current_dir(&dir));
1472 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1473 pub struct Bootstrap;
1475 impl Step for Bootstrap {
1477 const DEFAULT: bool = true;
1478 const ONLY_HOSTS: bool = true;
1479 const ONLY_BUILD: bool = true;
1481 /// Test the build system itself
1482 fn run(self, builder: &Builder) {
1483 let build = builder.build;
1484 let mut cmd = Command::new(&build.initial_cargo);
1486 .current_dir(build.src.join("src/bootstrap"))
1487 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1488 .env("RUSTC_BOOTSTRAP", "1")
1489 .env("RUSTC", &build.initial_rustc);
1490 if !build.fail_fast {
1491 cmd.arg("--no-fail-fast");
1493 cmd.arg("--").args(&build.config.cmd.test_args());
1494 try_run(build, &mut cmd);
1497 fn should_run(run: ShouldRun) -> ShouldRun {
1498 run.path("src/bootstrap")
1501 fn make_run(run: RunConfig) {
1502 run.builder.ensure(Bootstrap);