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
17 use std::ffi::OsString;
20 use std::fs::{self, File};
21 use std::path::{PathBuf, Path};
22 use std::process::Command;
25 use build_helper::{self, output};
27 use builder::{Kind, RunConfig, ShouldRun, Builder, Compiler, Step};
28 use Crate as CargoCrate;
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(build: &Build, cmd: &mut Command) -> bool {
70 if !build.try_run(cmd) {
71 let mut failures = build.delayed_failures.borrow_mut();
72 failures.push(format!("{:?}", cmd));
81 fn try_run_quiet(build: &Build, cmd: &mut Command) -> bool {
83 if !build.try_run_quiet(cmd) {
84 let mut failures = build.delayed_failures.borrow_mut();
85 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);
260 if try_run(build, &mut cargo) {
261 build.save_toolstate("rls", ToolState::TestPass);
266 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
269 host: Interned<String>,
272 impl Step for Rustfmt {
274 const ONLY_HOSTS: bool = true;
276 fn should_run(run: ShouldRun) -> ShouldRun {
277 run.path("src/tools/rustfmt")
280 fn make_run(run: RunConfig) {
281 run.builder.ensure(Rustfmt {
282 stage: run.builder.top_stage,
287 /// Runs `cargo test` for rustfmt.
288 fn run(self, builder: &Builder) {
289 let build = builder.build;
290 let stage = self.stage;
291 let host = self.host;
292 let compiler = builder.compiler(stage, host);
294 builder.ensure(tool::Rustfmt { compiler, target: self.host });
295 let mut cargo = tool::prepare_tool_cargo(builder,
299 "src/tools/rustfmt");
301 // Don't build tests dynamically, just a pain to work with
302 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
304 builder.add_rustc_lib_path(compiler, &mut cargo);
306 if try_run(build, &mut cargo) {
307 build.save_toolstate("rustfmt", ToolState::TestPass);
312 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
315 host: Interned<String>,
320 const ONLY_HOSTS: bool = true;
321 const DEFAULT: bool = true;
323 fn should_run(run: ShouldRun) -> ShouldRun {
324 let test_miri = run.builder.build.config.test_miri;
325 run.path("src/tools/miri").default_condition(test_miri)
328 fn make_run(run: RunConfig) {
329 run.builder.ensure(Miri {
330 stage: run.builder.top_stage,
335 /// Runs `cargo test` for miri.
336 fn run(self, builder: &Builder) {
337 let build = builder.build;
338 let stage = self.stage;
339 let host = self.host;
340 let compiler = builder.compiler(stage, host);
342 if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
343 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
344 cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
346 // Don't build tests dynamically, just a pain to work with
347 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
348 // miri tests need to know about the stage sysroot
349 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
350 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
351 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
352 cargo.env("MIRI_PATH", miri);
354 builder.add_rustc_lib_path(compiler, &mut cargo);
356 if try_run(build, &mut cargo) {
357 build.save_toolstate("miri", ToolState::TestPass);
360 eprintln!("failed to test miri: could not build");
365 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
368 host: Interned<String>,
371 impl Step for Clippy {
373 const ONLY_HOSTS: bool = true;
374 const DEFAULT: bool = false;
376 fn should_run(run: ShouldRun) -> ShouldRun {
377 run.path("src/tools/clippy")
380 fn make_run(run: RunConfig) {
381 run.builder.ensure(Clippy {
382 stage: run.builder.top_stage,
387 /// Runs `cargo test` for clippy.
388 fn run(self, builder: &Builder) {
389 let build = builder.build;
390 let stage = self.stage;
391 let host = self.host;
392 let compiler = builder.compiler(stage, host);
394 if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
395 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
396 cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
398 // Don't build tests dynamically, just a pain to work with
399 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
400 // clippy tests need to know about the stage sysroot
401 cargo.env("SYSROOT", builder.sysroot(compiler));
402 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
403 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
404 let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
405 cargo.env("HOST_LIBS", host_libs);
406 // clippy tests need to find the driver
407 cargo.env("CLIPPY_DRIVER_PATH", clippy);
409 builder.add_rustc_lib_path(compiler, &mut cargo);
411 if try_run(build, &mut cargo) {
412 build.save_toolstate("clippy-driver", ToolState::TestPass);
415 eprintln!("failed to test clippy: could not build");
420 fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
421 // Configure PATH to find the right rustc. NB. we have to use PATH
422 // and not RUSTC because the Cargo test suite has tests that will
423 // fail if rustc is not spelled `rustc`.
424 let path = builder.sysroot(compiler).join("bin");
425 let old_path = env::var_os("PATH").unwrap_or_default();
426 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
429 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
430 pub struct RustdocTheme {
431 pub compiler: Compiler,
434 impl Step for RustdocTheme {
436 const DEFAULT: bool = true;
437 const ONLY_HOSTS: bool = true;
439 fn should_run(run: ShouldRun) -> ShouldRun {
440 run.path("src/tools/rustdoc-themes")
443 fn make_run(run: RunConfig) {
444 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
446 run.builder.ensure(RustdocTheme {
451 fn run(self, builder: &Builder) {
452 let rustdoc = builder.rustdoc(self.compiler.host);
453 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
454 cmd.arg(rustdoc.to_str().unwrap())
455 .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap())
456 .env("RUSTC_STAGE", self.compiler.stage.to_string())
457 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
458 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
459 .env("CFG_RELEASE_CHANNEL", &builder.build.config.channel)
460 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
461 .env("RUSTDOC_CRATE_VERSION", builder.build.rust_version())
462 .env("RUSTC_BOOTSTRAP", "1");
463 if let Some(linker) = builder.build.linker(self.compiler.host) {
464 cmd.env("RUSTC_TARGET_LINKER", linker);
466 try_run(builder.build, &mut cmd);
470 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
471 pub struct RustdocJS {
472 pub host: Interned<String>,
473 pub target: Interned<String>,
476 impl Step for RustdocJS {
478 const DEFAULT: bool = true;
479 const ONLY_HOSTS: bool = true;
481 fn should_run(run: ShouldRun) -> ShouldRun {
482 run.path("src/test/rustdoc-js")
485 fn make_run(run: RunConfig) {
486 run.builder.ensure(RustdocJS {
492 fn run(self, builder: &Builder) {
493 if let Some(ref nodejs) = builder.config.nodejs {
494 let mut command = Command::new(nodejs);
495 command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
496 builder.ensure(::doc::Std {
498 stage: builder.top_stage,
500 builder.run(&mut command);
502 println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
507 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
509 host: Interned<String>,
514 const DEFAULT: bool = true;
515 const ONLY_HOSTS: bool = true;
516 const ONLY_BUILD: bool = true;
518 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
520 /// This tool in `src/tools` checks up on various bits and pieces of style and
521 /// otherwise just implements a few lint-like checks that are specific to the
523 fn run(self, builder: &Builder) {
524 let build = builder.build;
525 let host = self.host;
527 let _folder = build.fold_output(|| "tidy");
528 println!("tidy check ({})", host);
529 let mut cmd = builder.tool_cmd(Tool::Tidy);
530 cmd.arg(build.src.join("src"));
531 if !build.config.vendor {
532 cmd.arg("--no-vendor");
534 if build.config.quiet_tests {
537 try_run(build, &mut cmd);
540 fn should_run(run: ShouldRun) -> ShouldRun {
541 run.path("src/tools/tidy")
544 fn make_run(run: RunConfig) {
545 run.builder.ensure(Tidy {
546 host: run.builder.build.build,
551 fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
552 build.out.join(host).join("test")
555 macro_rules! default_test {
556 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
557 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
561 macro_rules! host_test {
562 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
563 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
572 default: $default:expr,
575 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
577 pub compiler: Compiler,
578 pub target: Interned<String>,
581 impl Step for $name {
583 const DEFAULT: bool = $default;
584 const ONLY_HOSTS: bool = $host;
586 fn should_run(run: ShouldRun) -> ShouldRun {
590 fn make_run(run: RunConfig) {
591 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
593 run.builder.ensure($name {
599 fn run(self, builder: &Builder) {
600 builder.ensure(Compiletest {
601 compiler: self.compiler,
617 default_test!(RunPass {
618 path: "src/test/run-pass",
623 default_test!(CompileFail {
624 path: "src/test/compile-fail",
625 mode: "compile-fail",
626 suite: "compile-fail"
629 default_test!(ParseFail {
630 path: "src/test/parse-fail",
635 default_test!(RunFail {
636 path: "src/test/run-fail",
641 default_test!(RunPassValgrind {
642 path: "src/test/run-pass-valgrind",
643 mode: "run-pass-valgrind",
644 suite: "run-pass-valgrind"
647 default_test!(MirOpt {
648 path: "src/test/mir-opt",
653 default_test!(Codegen {
654 path: "src/test/codegen",
659 default_test!(CodegenUnits {
660 path: "src/test/codegen-units",
661 mode: "codegen-units",
662 suite: "codegen-units"
665 default_test!(Incremental {
666 path: "src/test/incremental",
671 default_test!(Debuginfo {
672 path: "src/test/debuginfo",
673 // What this runs varies depending on the native platform being apple
674 mode: "debuginfo-XXX",
678 host_test!(UiFullDeps {
679 path: "src/test/ui-fulldeps",
684 host_test!(RunPassFullDeps {
685 path: "src/test/run-pass-fulldeps",
687 suite: "run-pass-fulldeps"
690 host_test!(RunFailFullDeps {
691 path: "src/test/run-fail-fulldeps",
693 suite: "run-fail-fulldeps"
696 host_test!(CompileFailFullDeps {
697 path: "src/test/compile-fail-fulldeps",
698 mode: "compile-fail",
699 suite: "compile-fail-fulldeps"
702 host_test!(IncrementalFullDeps {
703 path: "src/test/incremental-fulldeps",
705 suite: "incremental-fulldeps"
709 path: "src/test/rustdoc",
715 path: "src/test/pretty",
721 test!(RunPassPretty {
722 path: "src/test/run-pass/pretty",
728 test!(RunFailPretty {
729 path: "src/test/run-fail/pretty",
735 test!(RunPassValgrindPretty {
736 path: "src/test/run-pass-valgrind/pretty",
738 suite: "run-pass-valgrind",
742 test!(RunPassFullDepsPretty {
743 path: "src/test/run-pass-fulldeps/pretty",
745 suite: "run-pass-fulldeps",
749 test!(RunFailFullDepsPretty {
750 path: "src/test/run-fail-fulldeps/pretty",
752 suite: "run-fail-fulldeps",
758 path: "src/test/run-make",
763 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
766 target: Interned<String>,
771 impl Step for Compiletest {
774 fn should_run(run: ShouldRun) -> ShouldRun {
778 /// Executes the `compiletest` tool to run a suite of tests.
780 /// Compiles all tests with `compiler` for `target` with the specified
781 /// compiletest `mode` and `suite` arguments. For example `mode` can be
782 /// "run-pass" or `suite` can be something like `debuginfo`.
783 fn run(self, builder: &Builder) {
784 let build = builder.build;
785 let compiler = self.compiler;
786 let target = self.target;
787 let mode = self.mode;
788 let suite = self.suite;
790 // Skip codegen tests if they aren't enabled in configuration.
791 if !build.config.codegen_tests && suite == "codegen" {
795 if suite == "debuginfo" {
796 // Skip debuginfo tests on MSVC
797 if build.build.contains("msvc") {
801 if mode == "debuginfo-XXX" {
802 return if build.build.contains("apple") {
803 builder.ensure(Compiletest {
804 mode: "debuginfo-lldb",
808 builder.ensure(Compiletest {
809 mode: "debuginfo-gdb",
815 builder.ensure(dist::DebuggerScripts {
816 sysroot: builder.sysroot(compiler),
821 if suite.ends_with("fulldeps") ||
822 // FIXME: Does pretty need librustc compiled? Note that there are
823 // fulldeps test suites with mode = pretty as well.
827 builder.ensure(compile::Rustc { compiler, target });
830 builder.ensure(compile::Test { compiler, target });
831 builder.ensure(native::TestHelpers { target });
832 builder.ensure(RemoteCopyLibs { compiler, target });
834 let _folder = build.fold_output(|| format!("test_{}", suite));
835 println!("Check compiletest suite={} mode={} ({} -> {})",
836 suite, mode, &compiler.host, target);
837 let mut cmd = builder.tool_cmd(Tool::Compiletest);
839 // compiletest currently has... a lot of arguments, so let's just pass all
842 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
843 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
844 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
846 // Avoid depending on rustdoc when we don't need it.
847 if mode == "rustdoc" || mode == "run-make" {
848 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
851 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
852 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
853 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
854 cmd.arg("--mode").arg(mode);
855 cmd.arg("--target").arg(target);
856 cmd.arg("--host").arg(&*compiler.host);
857 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
859 if let Some(ref nodejs) = build.config.nodejs {
860 cmd.arg("--nodejs").arg(nodejs);
863 let mut flags = vec!["-Crpath".to_string()];
864 if build.config.rust_optimize_tests {
865 flags.push("-O".to_string());
867 if build.config.rust_debuginfo_tests {
868 flags.push("-g".to_string());
870 flags.push("-Zmiri -Zunstable-options".to_string());
871 flags.push(build.config.cmd.rustc_args().join(" "));
873 if let Some(linker) = build.linker(target) {
874 cmd.arg("--linker").arg(linker);
877 let hostflags = flags.clone();
878 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
880 let mut targetflags = flags.clone();
881 targetflags.push(format!("-Lnative={}",
882 build.test_helpers_out(target).display()));
883 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
885 cmd.arg("--docck-python").arg(build.python());
887 if build.build.ends_with("apple-darwin") {
888 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
889 // LLDB plugin's compiled module which only works with the system python
890 // (namely not Homebrew-installed python)
891 cmd.arg("--lldb-python").arg("/usr/bin/python");
893 cmd.arg("--lldb-python").arg(build.python());
896 if let Some(ref gdb) = build.config.gdb {
897 cmd.arg("--gdb").arg(gdb);
899 if let Some(ref vers) = build.lldb_version {
900 cmd.arg("--lldb-version").arg(vers);
902 if let Some(ref dir) = build.lldb_python_dir {
903 cmd.arg("--lldb-python-dir").arg(dir);
906 cmd.args(&build.config.cmd.test_args());
908 if build.is_verbose() {
909 cmd.arg("--verbose");
912 if build.config.quiet_tests {
916 if build.config.llvm_enabled {
917 let llvm_config = build.llvm_config(build.config.build);
918 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
919 cmd.arg("--llvm-version").arg(llvm_version);
920 if !build.is_rust_llvm(target) {
921 cmd.arg("--system-llvm");
924 // Only pass correct values for these flags for the `run-make` suite as it
925 // requires that a C++ compiler was configured which isn't always the case.
926 if suite == "run-make" {
927 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
928 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
929 cmd.arg("--cc").arg(build.cc(target))
930 .arg("--cxx").arg(build.cxx(target).unwrap())
931 .arg("--cflags").arg(build.cflags(target).join(" "))
932 .arg("--llvm-components").arg(llvm_components.trim())
933 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
934 if let Some(ar) = build.ar(target) {
935 cmd.arg("--ar").arg(ar);
939 if suite == "run-make" && !build.config.llvm_enabled {
940 println!("Ignoring run-make test suite as they generally don't work without LLVM");
944 if suite != "run-make" {
945 cmd.arg("--cc").arg("")
946 .arg("--cxx").arg("")
947 .arg("--cflags").arg("")
948 .arg("--llvm-components").arg("")
949 .arg("--llvm-cxxflags").arg("");
952 if build.remote_tested(target) {
953 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
956 // Running a C compiler on MSVC requires a few env vars to be set, to be
957 // sure to set them here.
959 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
960 // rather than stomp over it.
961 if target.contains("msvc") {
962 for &(ref k, ref v) in build.cc[&target].env() {
968 cmd.env("RUSTC_BOOTSTRAP", "1");
969 build.add_rust_test_threads(&mut cmd);
971 if build.config.sanitizers {
972 cmd.env("SANITIZER_SUPPORT", "1");
975 if build.config.profiler {
976 cmd.env("PROFILER_SUPPORT", "1");
979 cmd.env("RUST_TEST_TMPDIR", build.out.join("tmp"));
981 cmd.arg("--adb-path").arg("adb");
982 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
983 if target.contains("android") {
984 // Assume that cc for this target comes from the android sysroot
985 cmd.arg("--android-cross-path")
986 .arg(build.cc(target).parent().unwrap().parent().unwrap());
988 cmd.arg("--android-cross-path").arg("");
991 build.ci_env.force_coloring_in_ci(&mut cmd);
993 let _time = util::timeit();
994 try_run(build, &mut cmd);
998 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1006 impl Step for DocTest {
1008 const ONLY_HOSTS: bool = true;
1010 fn should_run(run: ShouldRun) -> ShouldRun {
1014 /// Run `rustdoc --test` for all documentation in `src/doc`.
1016 /// This will run all tests in our markdown documentation (e.g. the book)
1017 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1019 fn run(self, builder: &Builder) {
1020 let build = builder.build;
1021 let compiler = self.compiler;
1023 builder.ensure(compile::Test { compiler, target: compiler.host });
1025 // Do a breadth-first traversal of the `src/doc` directory and just run
1026 // tests for all files that end in `*.md`
1027 let mut stack = vec![build.src.join(self.path)];
1028 let _time = util::timeit();
1029 let _folder = build.fold_output(|| format!("test_{}", self.name));
1031 while let Some(p) = stack.pop() {
1033 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1037 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1041 // The nostarch directory in the book is for no starch, and so isn't
1042 // guaranteed to build. We don't care if it doesn't build, so skip it.
1043 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1047 let test_result = markdown_test(builder, compiler, &p);
1048 if self.is_ext_doc {
1049 let toolstate = if test_result {
1054 build.save_toolstate(self.name, toolstate);
1060 macro_rules! test_book {
1061 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1063 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1068 impl Step for $name {
1070 const DEFAULT: bool = $default;
1071 const ONLY_HOSTS: bool = true;
1073 fn should_run(run: ShouldRun) -> ShouldRun {
1077 fn make_run(run: RunConfig) {
1078 run.builder.ensure($name {
1079 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1083 fn run(self, builder: &Builder) {
1084 builder.ensure(DocTest {
1085 compiler: self.compiler,
1088 is_ext_doc: !$default,
1097 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1098 Reference, "src/doc/reference", "reference", default=false;
1099 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1100 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1101 TheBook, "src/doc/book", "book", default=false;
1102 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1105 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1106 pub struct ErrorIndex {
1110 impl Step for ErrorIndex {
1112 const DEFAULT: bool = true;
1113 const ONLY_HOSTS: bool = true;
1115 fn should_run(run: ShouldRun) -> ShouldRun {
1116 run.path("src/tools/error_index_generator")
1119 fn make_run(run: RunConfig) {
1120 run.builder.ensure(ErrorIndex {
1121 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1125 /// Run the error index generator tool to execute the tests located in the error
1128 /// The `error_index_generator` tool lives in `src/tools` and is used to
1129 /// generate a markdown file from the error indexes of the code base which is
1130 /// then passed to `rustdoc --test`.
1131 fn run(self, builder: &Builder) {
1132 let build = builder.build;
1133 let compiler = self.compiler;
1135 builder.ensure(compile::Std { compiler, target: compiler.host });
1137 let _folder = build.fold_output(|| "test_error_index");
1138 println!("Testing error-index stage{}", compiler.stage);
1140 let dir = testdir(build, compiler.host);
1141 t!(fs::create_dir_all(&dir));
1142 let output = dir.join("error-index.md");
1144 let _time = util::timeit();
1145 build.run(builder.tool_cmd(Tool::ErrorIndex)
1148 .env("CFG_BUILD", &build.build)
1149 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
1151 markdown_test(builder, compiler, &output);
1155 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
1156 let build = builder.build;
1157 let mut file = t!(File::open(markdown));
1158 let mut contents = String::new();
1159 t!(file.read_to_string(&mut contents));
1160 if !contents.contains("```") {
1164 println!("doc tests for: {}", markdown.display());
1165 let mut cmd = builder.rustdoc_cmd(compiler.host);
1166 build.add_rust_test_threads(&mut cmd);
1169 cmd.env("RUSTC_BOOTSTRAP", "1");
1171 let test_args = build.config.cmd.test_args().join(" ");
1172 cmd.arg("--test-args").arg(test_args);
1174 if build.config.quiet_tests {
1175 try_run_quiet(build, &mut cmd)
1177 try_run(build, &mut cmd)
1181 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1182 pub struct CrateLibrustc {
1184 target: Interned<String>,
1185 test_kind: TestKind,
1186 krate: Interned<String>,
1189 impl Step for CrateLibrustc {
1191 const DEFAULT: bool = true;
1192 const ONLY_HOSTS: bool = true;
1194 fn should_run(run: ShouldRun) -> ShouldRun {
1195 run.krate("rustc-main")
1198 fn make_run(run: RunConfig) {
1199 let builder = run.builder;
1200 let compiler = builder.compiler(builder.top_stage, run.host);
1202 for krate in builder.in_tree_crates("rustc-main") {
1203 if run.path.ends_with(&krate.path) {
1204 let test_kind = if builder.kind == Kind::Test {
1206 } else if builder.kind == Kind::Bench {
1209 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1212 builder.ensure(CrateLibrustc {
1222 fn run(self, builder: &Builder) {
1223 builder.ensure(Crate {
1224 compiler: self.compiler,
1225 target: self.target,
1226 mode: Mode::Librustc,
1227 test_kind: self.test_kind,
1233 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1234 pub struct CrateNotDefault {
1236 target: Interned<String>,
1237 test_kind: TestKind,
1238 krate: &'static str,
1241 impl Step for CrateNotDefault {
1244 fn should_run(run: ShouldRun) -> ShouldRun {
1245 run.path("src/liballoc_jemalloc")
1246 .path("src/librustc_asan")
1247 .path("src/librustc_lsan")
1248 .path("src/librustc_msan")
1249 .path("src/librustc_tsan")
1252 fn make_run(run: RunConfig) {
1253 let builder = run.builder;
1254 let compiler = builder.compiler(builder.top_stage, run.host);
1256 let test_kind = if builder.kind == Kind::Test {
1258 } else if builder.kind == Kind::Bench {
1261 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1264 builder.ensure(CrateNotDefault {
1268 krate: match run.path {
1269 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1270 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1271 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1272 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1273 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1274 _ => panic!("unexpected path {:?}", run.path),
1279 fn run(self, builder: &Builder) {
1280 builder.ensure(Crate {
1281 compiler: self.compiler,
1282 target: self.target,
1284 test_kind: self.test_kind,
1285 krate: INTERNER.intern_str(self.krate),
1291 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1294 target: Interned<String>,
1296 test_kind: TestKind,
1297 krate: Interned<String>,
1300 impl Step for Crate {
1302 const DEFAULT: bool = true;
1304 fn should_run(mut run: ShouldRun) -> ShouldRun {
1305 let builder = run.builder;
1306 run = run.krate("test");
1307 for krate in run.builder.in_tree_crates("std") {
1308 if krate.is_local(&run.builder) &&
1309 !krate.name.contains("jemalloc") &&
1310 !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) &&
1311 krate.name != "dlmalloc" {
1312 run = run.path(krate.local_path(&builder).to_str().unwrap());
1318 fn make_run(run: RunConfig) {
1319 let builder = run.builder;
1320 let compiler = builder.compiler(builder.top_stage, run.host);
1322 let make = |mode: Mode, krate: &CargoCrate| {
1323 let test_kind = if builder.kind == Kind::Test {
1325 } else if builder.kind == Kind::Bench {
1328 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1331 builder.ensure(Crate {
1340 for krate in builder.in_tree_crates("std") {
1341 if run.path.ends_with(&krate.local_path(&builder)) {
1342 make(Mode::Libstd, krate);
1345 for krate in builder.in_tree_crates("test") {
1346 if run.path.ends_with(&krate.local_path(&builder)) {
1347 make(Mode::Libtest, krate);
1352 /// Run all unit tests plus documentation tests for a given crate defined
1353 /// by a `Cargo.toml` (single manifest)
1355 /// This is what runs tests for crates like the standard library, compiler, etc.
1356 /// It essentially is the driver for running `cargo test`.
1358 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1359 /// arguments, and those arguments are discovered from `cargo metadata`.
1360 fn run(self, builder: &Builder) {
1361 let build = builder.build;
1362 let compiler = self.compiler;
1363 let target = self.target;
1364 let mode = self.mode;
1365 let test_kind = self.test_kind;
1366 let krate = self.krate;
1368 builder.ensure(compile::Test { compiler, target });
1369 builder.ensure(RemoteCopyLibs { compiler, target });
1371 // If we're not doing a full bootstrap but we're testing a stage2 version of
1372 // libstd, then what we're actually testing is the libstd produced in
1373 // stage1. Reflect that here by updating the compiler that we're working
1374 // with automatically.
1375 let compiler = if build.force_use_stage1(compiler, target) {
1376 builder.compiler(1, compiler.host)
1381 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1384 compile::std_cargo(build, &compiler, target, &mut cargo);
1387 compile::test_cargo(build, &compiler, target, &mut cargo);
1390 builder.ensure(compile::Rustc { compiler, target });
1391 compile::rustc_cargo(build, &mut cargo);
1393 _ => panic!("can only test libraries"),
1395 let _folder = build.fold_output(|| {
1396 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, krate)
1398 println!("{} {} stage{} ({} -> {})", test_kind, krate, compiler.stage,
1399 &compiler.host, target);
1401 // Build up the base `cargo test` command.
1403 // Pass in some standard flags then iterate over the graph we've discovered
1404 // in `cargo metadata` with the maps above and figure out what `-p`
1405 // arguments need to get passed.
1406 if test_kind.subcommand() == "test" && !build.fail_fast {
1407 cargo.arg("--no-fail-fast");
1409 if build.doc_tests {
1413 cargo.arg("-p").arg(krate);
1415 // The tests are going to run with the *target* libraries, so we need to
1416 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1418 // Note that to run the compiler we need to run with the *host* libraries,
1419 // but our wrapper scripts arrange for that to be the case anyway.
1420 let mut dylib_path = dylib_path();
1421 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1422 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1425 cargo.args(&build.config.cmd.test_args());
1427 if build.config.quiet_tests {
1428 cargo.arg("--quiet");
1431 let _time = util::timeit();
1433 if target.contains("emscripten") {
1434 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1435 build.config.nodejs.as_ref().expect("nodejs not configured"));
1436 } else if target.starts_with("wasm32") {
1437 // Warn about running tests without the `wasm_syscall` feature enabled.
1438 // The javascript shim implements the syscall interface so that test
1439 // output can be correctly reported.
1440 if !build.config.wasm_syscall {
1441 println!("Libstd was built without `wasm_syscall` feature enabled: \
1442 test output may not be visible.");
1445 // On the wasm32-unknown-unknown target we're using LTO which is
1446 // incompatible with `-C prefer-dynamic`, so disable that here
1447 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1449 let node = build.config.nodejs.as_ref()
1450 .expect("nodejs not configured");
1451 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1453 build.src.display());
1454 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1455 } else if build.remote_tested(target) {
1456 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1458 builder.tool_exe(Tool::RemoteTestClient).display()));
1460 try_run(build, &mut cargo);
1464 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1465 pub struct CrateRustdoc {
1466 host: Interned<String>,
1467 test_kind: TestKind,
1470 impl Step for CrateRustdoc {
1472 const DEFAULT: bool = true;
1473 const ONLY_HOSTS: bool = true;
1475 fn should_run(run: ShouldRun) -> ShouldRun {
1476 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1479 fn make_run(run: RunConfig) {
1480 let builder = run.builder;
1482 let test_kind = if builder.kind == Kind::Test {
1484 } else if builder.kind == Kind::Bench {
1487 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1490 builder.ensure(CrateRustdoc {
1496 fn run(self, builder: &Builder) {
1497 let build = builder.build;
1498 let test_kind = self.test_kind;
1500 let compiler = builder.compiler(builder.top_stage, self.host);
1501 let target = compiler.host;
1503 let mut cargo = tool::prepare_tool_cargo(builder,
1506 test_kind.subcommand(),
1507 "src/tools/rustdoc");
1508 let _folder = build.fold_output(|| {
1509 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1511 println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1512 &compiler.host, target);
1514 if test_kind.subcommand() == "test" && !build.fail_fast {
1515 cargo.arg("--no-fail-fast");
1518 cargo.arg("-p").arg("rustdoc:0.0.0");
1521 cargo.args(&build.config.cmd.test_args());
1523 if build.config.quiet_tests {
1524 cargo.arg("--quiet");
1527 let _time = util::timeit();
1529 try_run(build, &mut cargo);
1533 fn envify(s: &str) -> String {
1539 }).flat_map(|c| c.to_uppercase()).collect()
1542 /// Some test suites are run inside emulators or on remote devices, and most
1543 /// of our test binaries are linked dynamically which means we need to ship
1544 /// the standard library and such to the emulator ahead of time. This step
1545 /// represents this and is a dependency of all test suites.
1547 /// Most of the time this is a noop. For some steps such as shipping data to
1548 /// QEMU we have to build our own tools so we've got conditional dependencies
1549 /// on those programs as well. Note that the remote test client is built for
1550 /// the build target (us) and the server is built for the target.
1551 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1552 pub struct RemoteCopyLibs {
1554 target: Interned<String>,
1557 impl Step for RemoteCopyLibs {
1560 fn should_run(run: ShouldRun) -> ShouldRun {
1564 fn run(self, builder: &Builder) {
1565 let build = builder.build;
1566 let compiler = self.compiler;
1567 let target = self.target;
1568 if !build.remote_tested(target) {
1572 builder.ensure(compile::Test { compiler, target });
1574 println!("REMOTE copy libs to emulator ({})", target);
1575 t!(fs::create_dir_all(build.out.join("tmp")));
1577 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1579 // Spawn the emulator and wait for it to come online
1580 let tool = builder.tool_exe(Tool::RemoteTestClient);
1581 let mut cmd = Command::new(&tool);
1582 cmd.arg("spawn-emulator")
1585 .arg(build.out.join("tmp"));
1586 if let Some(rootfs) = build.qemu_rootfs(target) {
1589 build.run(&mut cmd);
1591 // Push all our dylibs to the emulator
1592 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1594 let name = f.file_name().into_string().unwrap();
1595 if util::is_dylib(&name) {
1596 build.run(Command::new(&tool)
1604 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1605 pub struct Distcheck;
1607 impl Step for Distcheck {
1609 const ONLY_BUILD: bool = true;
1611 fn should_run(run: ShouldRun) -> ShouldRun {
1612 run.path("distcheck")
1615 fn make_run(run: RunConfig) {
1616 run.builder.ensure(Distcheck);
1619 /// Run "distcheck", a 'make check' from a tarball
1620 fn run(self, builder: &Builder) {
1621 let build = builder.build;
1623 println!("Distcheck");
1624 let dir = build.out.join("tmp").join("distcheck");
1625 let _ = fs::remove_dir_all(&dir);
1626 t!(fs::create_dir_all(&dir));
1628 // Guarantee that these are built before we begin running.
1629 builder.ensure(dist::PlainSourceTarball);
1630 builder.ensure(dist::Src);
1632 let mut cmd = Command::new("tar");
1634 .arg(builder.ensure(dist::PlainSourceTarball))
1635 .arg("--strip-components=1")
1637 build.run(&mut cmd);
1638 build.run(Command::new("./configure")
1639 .args(&build.config.configure_args)
1640 .arg("--enable-vendor")
1641 .current_dir(&dir));
1642 build.run(Command::new(build_helper::make(&build.build))
1644 .current_dir(&dir));
1646 // Now make sure that rust-src has all of libstd's dependencies
1647 println!("Distcheck rust-src");
1648 let dir = build.out.join("tmp").join("distcheck-src");
1649 let _ = fs::remove_dir_all(&dir);
1650 t!(fs::create_dir_all(&dir));
1652 let mut cmd = Command::new("tar");
1654 .arg(builder.ensure(dist::Src))
1655 .arg("--strip-components=1")
1657 build.run(&mut cmd);
1659 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1660 build.run(Command::new(&build.initial_cargo)
1661 .arg("generate-lockfile")
1662 .arg("--manifest-path")
1664 .current_dir(&dir));
1668 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1669 pub struct Bootstrap;
1671 impl Step for Bootstrap {
1673 const DEFAULT: bool = true;
1674 const ONLY_HOSTS: bool = true;
1675 const ONLY_BUILD: bool = true;
1677 /// Test the build system itself
1678 fn run(self, builder: &Builder) {
1679 let build = builder.build;
1680 let mut cmd = Command::new(&build.initial_cargo);
1682 .current_dir(build.src.join("src/bootstrap"))
1683 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1684 .env("RUSTC_BOOTSTRAP", "1")
1685 .env("RUSTC", &build.initial_rustc);
1686 if !build.fail_fast {
1687 cmd.arg("--no-fail-fast");
1689 cmd.arg("--").args(&build.config.cmd.test_args());
1690 try_run(build, &mut cmd);
1693 fn should_run(run: ShouldRun) -> ShouldRun {
1694 run.path("src/bootstrap")
1697 fn make_run(run: RunConfig) {
1698 run.builder.ensure(Bootstrap);