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)]
512 const DEFAULT: bool = true;
513 const ONLY_HOSTS: bool = true;
515 /// Runs the `tidy` tool.
517 /// This tool in `src/tools` checks up on various bits and pieces of style and
518 /// otherwise just implements a few lint-like checks that are specific to the
520 fn run(self, builder: &Builder) {
521 let build = builder.build;
523 let _folder = build.fold_output(|| "tidy");
524 println!("tidy check");
525 let mut cmd = builder.tool_cmd(Tool::Tidy);
526 cmd.arg(build.src.join("src"));
527 cmd.arg(&build.initial_cargo);
528 if !build.config.vendor {
529 cmd.arg("--no-vendor");
531 if build.config.quiet_tests {
534 try_run(build, &mut cmd);
537 fn should_run(run: ShouldRun) -> ShouldRun {
538 run.path("src/tools/tidy")
541 fn make_run(run: RunConfig) {
542 run.builder.ensure(Tidy);
546 fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
547 build.out.join(host).join("test")
550 macro_rules! default_test {
551 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
552 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
556 macro_rules! host_test {
557 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
558 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
567 default: $default:expr,
570 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
572 pub compiler: Compiler,
573 pub target: Interned<String>,
576 impl Step for $name {
578 const DEFAULT: bool = $default;
579 const ONLY_HOSTS: bool = $host;
581 fn should_run(run: ShouldRun) -> ShouldRun {
585 fn make_run(run: RunConfig) {
586 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
588 run.builder.ensure($name {
594 fn run(self, builder: &Builder) {
595 builder.ensure(Compiletest {
596 compiler: self.compiler,
612 default_test!(RunPass {
613 path: "src/test/run-pass",
618 default_test!(CompileFail {
619 path: "src/test/compile-fail",
620 mode: "compile-fail",
621 suite: "compile-fail"
624 default_test!(ParseFail {
625 path: "src/test/parse-fail",
630 default_test!(RunFail {
631 path: "src/test/run-fail",
636 default_test!(RunPassValgrind {
637 path: "src/test/run-pass-valgrind",
638 mode: "run-pass-valgrind",
639 suite: "run-pass-valgrind"
642 default_test!(MirOpt {
643 path: "src/test/mir-opt",
648 default_test!(Codegen {
649 path: "src/test/codegen",
654 default_test!(CodegenUnits {
655 path: "src/test/codegen-units",
656 mode: "codegen-units",
657 suite: "codegen-units"
660 default_test!(Incremental {
661 path: "src/test/incremental",
666 default_test!(Debuginfo {
667 path: "src/test/debuginfo",
668 // What this runs varies depending on the native platform being apple
669 mode: "debuginfo-XXX",
673 host_test!(UiFullDeps {
674 path: "src/test/ui-fulldeps",
679 host_test!(RunPassFullDeps {
680 path: "src/test/run-pass-fulldeps",
682 suite: "run-pass-fulldeps"
685 host_test!(RunFailFullDeps {
686 path: "src/test/run-fail-fulldeps",
688 suite: "run-fail-fulldeps"
691 host_test!(CompileFailFullDeps {
692 path: "src/test/compile-fail-fulldeps",
693 mode: "compile-fail",
694 suite: "compile-fail-fulldeps"
697 host_test!(IncrementalFullDeps {
698 path: "src/test/incremental-fulldeps",
700 suite: "incremental-fulldeps"
704 path: "src/test/rustdoc",
710 path: "src/test/pretty",
716 test!(RunPassPretty {
717 path: "src/test/run-pass/pretty",
723 test!(RunFailPretty {
724 path: "src/test/run-fail/pretty",
730 test!(RunPassValgrindPretty {
731 path: "src/test/run-pass-valgrind/pretty",
733 suite: "run-pass-valgrind",
737 test!(RunPassFullDepsPretty {
738 path: "src/test/run-pass-fulldeps/pretty",
740 suite: "run-pass-fulldeps",
744 test!(RunFailFullDepsPretty {
745 path: "src/test/run-fail-fulldeps/pretty",
747 suite: "run-fail-fulldeps",
753 path: "src/test/run-make",
758 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
761 target: Interned<String>,
766 impl Step for Compiletest {
769 fn should_run(run: ShouldRun) -> ShouldRun {
773 /// Executes the `compiletest` tool to run a suite of tests.
775 /// Compiles all tests with `compiler` for `target` with the specified
776 /// compiletest `mode` and `suite` arguments. For example `mode` can be
777 /// "run-pass" or `suite` can be something like `debuginfo`.
778 fn run(self, builder: &Builder) {
779 let build = builder.build;
780 let compiler = self.compiler;
781 let target = self.target;
782 let mode = self.mode;
783 let suite = self.suite;
785 // Skip codegen tests if they aren't enabled in configuration.
786 if !build.config.codegen_tests && suite == "codegen" {
790 if suite == "debuginfo" {
791 // Skip debuginfo tests on MSVC
792 if build.build.contains("msvc") {
796 if mode == "debuginfo-XXX" {
797 return if build.build.contains("apple") {
798 builder.ensure(Compiletest {
799 mode: "debuginfo-lldb",
803 builder.ensure(Compiletest {
804 mode: "debuginfo-gdb",
810 builder.ensure(dist::DebuggerScripts {
811 sysroot: builder.sysroot(compiler),
816 if suite.ends_with("fulldeps") ||
817 // FIXME: Does pretty need librustc compiled? Note that there are
818 // fulldeps test suites with mode = pretty as well.
822 builder.ensure(compile::Rustc { compiler, target });
825 builder.ensure(compile::Test { compiler, target });
826 builder.ensure(native::TestHelpers { target });
827 builder.ensure(RemoteCopyLibs { compiler, target });
829 let _folder = build.fold_output(|| format!("test_{}", suite));
830 println!("Check compiletest suite={} mode={} ({} -> {})",
831 suite, mode, &compiler.host, target);
832 let mut cmd = builder.tool_cmd(Tool::Compiletest);
834 // compiletest currently has... a lot of arguments, so let's just pass all
837 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
838 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
839 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
841 // Avoid depending on rustdoc when we don't need it.
842 if mode == "rustdoc" || mode == "run-make" {
843 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
846 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
847 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
848 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
849 cmd.arg("--mode").arg(mode);
850 cmd.arg("--target").arg(target);
851 cmd.arg("--host").arg(&*compiler.host);
852 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
854 if let Some(ref nodejs) = build.config.nodejs {
855 cmd.arg("--nodejs").arg(nodejs);
858 let mut flags = vec!["-Crpath".to_string()];
859 if build.config.rust_optimize_tests {
860 flags.push("-O".to_string());
862 if build.config.rust_debuginfo_tests {
863 flags.push("-g".to_string());
865 flags.push("-Zmiri -Zunstable-options".to_string());
866 flags.push(build.config.cmd.rustc_args().join(" "));
868 if let Some(linker) = build.linker(target) {
869 cmd.arg("--linker").arg(linker);
872 let hostflags = flags.clone();
873 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
875 let mut targetflags = flags.clone();
876 targetflags.push(format!("-Lnative={}",
877 build.test_helpers_out(target).display()));
878 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
880 cmd.arg("--docck-python").arg(build.python());
882 if build.build.ends_with("apple-darwin") {
883 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
884 // LLDB plugin's compiled module which only works with the system python
885 // (namely not Homebrew-installed python)
886 cmd.arg("--lldb-python").arg("/usr/bin/python");
888 cmd.arg("--lldb-python").arg(build.python());
891 if let Some(ref gdb) = build.config.gdb {
892 cmd.arg("--gdb").arg(gdb);
894 if let Some(ref vers) = build.lldb_version {
895 cmd.arg("--lldb-version").arg(vers);
897 if let Some(ref dir) = build.lldb_python_dir {
898 cmd.arg("--lldb-python-dir").arg(dir);
901 cmd.args(&build.config.cmd.test_args());
903 if build.is_verbose() {
904 cmd.arg("--verbose");
907 if build.config.quiet_tests {
911 if build.config.llvm_enabled {
912 let llvm_config = build.llvm_config(build.config.build);
913 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
914 cmd.arg("--llvm-version").arg(llvm_version);
915 if !build.is_rust_llvm(target) {
916 cmd.arg("--system-llvm");
919 // Only pass correct values for these flags for the `run-make` suite as it
920 // requires that a C++ compiler was configured which isn't always the case.
921 if suite == "run-make" {
922 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
923 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
924 cmd.arg("--cc").arg(build.cc(target))
925 .arg("--cxx").arg(build.cxx(target).unwrap())
926 .arg("--cflags").arg(build.cflags(target).join(" "))
927 .arg("--llvm-components").arg(llvm_components.trim())
928 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
929 if let Some(ar) = build.ar(target) {
930 cmd.arg("--ar").arg(ar);
934 if suite == "run-make" && !build.config.llvm_enabled {
935 println!("Ignoring run-make test suite as they generally don't work without LLVM");
939 if suite != "run-make" {
940 cmd.arg("--cc").arg("")
941 .arg("--cxx").arg("")
942 .arg("--cflags").arg("")
943 .arg("--llvm-components").arg("")
944 .arg("--llvm-cxxflags").arg("");
947 if build.remote_tested(target) {
948 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
951 // Running a C compiler on MSVC requires a few env vars to be set, to be
952 // sure to set them here.
954 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
955 // rather than stomp over it.
956 if target.contains("msvc") {
957 for &(ref k, ref v) in build.cc[&target].env() {
963 cmd.env("RUSTC_BOOTSTRAP", "1");
964 build.add_rust_test_threads(&mut cmd);
966 if build.config.sanitizers {
967 cmd.env("SANITIZER_SUPPORT", "1");
970 if build.config.profiler {
971 cmd.env("PROFILER_SUPPORT", "1");
974 cmd.env("RUST_TEST_TMPDIR", build.out.join("tmp"));
976 cmd.arg("--adb-path").arg("adb");
977 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
978 if target.contains("android") {
979 // Assume that cc for this target comes from the android sysroot
980 cmd.arg("--android-cross-path")
981 .arg(build.cc(target).parent().unwrap().parent().unwrap());
983 cmd.arg("--android-cross-path").arg("");
986 build.ci_env.force_coloring_in_ci(&mut cmd);
988 let _time = util::timeit();
989 try_run(build, &mut cmd);
993 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1001 impl Step for DocTest {
1003 const ONLY_HOSTS: bool = true;
1005 fn should_run(run: ShouldRun) -> ShouldRun {
1009 /// Run `rustdoc --test` for all documentation in `src/doc`.
1011 /// This will run all tests in our markdown documentation (e.g. the book)
1012 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1014 fn run(self, builder: &Builder) {
1015 let build = builder.build;
1016 let compiler = self.compiler;
1018 builder.ensure(compile::Test { compiler, target: compiler.host });
1020 // Do a breadth-first traversal of the `src/doc` directory and just run
1021 // tests for all files that end in `*.md`
1022 let mut stack = vec![build.src.join(self.path)];
1023 let _time = util::timeit();
1024 let _folder = build.fold_output(|| format!("test_{}", self.name));
1026 while let Some(p) = stack.pop() {
1028 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1032 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1036 // The nostarch directory in the book is for no starch, and so isn't
1037 // guaranteed to build. We don't care if it doesn't build, so skip it.
1038 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1042 let test_result = markdown_test(builder, compiler, &p);
1043 if self.is_ext_doc {
1044 let toolstate = if test_result {
1049 build.save_toolstate(self.name, toolstate);
1055 macro_rules! test_book {
1056 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1058 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1063 impl Step for $name {
1065 const DEFAULT: bool = $default;
1066 const ONLY_HOSTS: bool = true;
1068 fn should_run(run: ShouldRun) -> ShouldRun {
1072 fn make_run(run: RunConfig) {
1073 run.builder.ensure($name {
1074 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1078 fn run(self, builder: &Builder) {
1079 builder.ensure(DocTest {
1080 compiler: self.compiler,
1083 is_ext_doc: !$default,
1092 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1093 Reference, "src/doc/reference", "reference", default=false;
1094 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1095 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1096 TheBook, "src/doc/book", "book", default=false;
1097 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1100 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1101 pub struct ErrorIndex {
1105 impl Step for ErrorIndex {
1107 const DEFAULT: bool = true;
1108 const ONLY_HOSTS: bool = true;
1110 fn should_run(run: ShouldRun) -> ShouldRun {
1111 run.path("src/tools/error_index_generator")
1114 fn make_run(run: RunConfig) {
1115 run.builder.ensure(ErrorIndex {
1116 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1120 /// Run the error index generator tool to execute the tests located in the error
1123 /// The `error_index_generator` tool lives in `src/tools` and is used to
1124 /// generate a markdown file from the error indexes of the code base which is
1125 /// then passed to `rustdoc --test`.
1126 fn run(self, builder: &Builder) {
1127 let build = builder.build;
1128 let compiler = self.compiler;
1130 builder.ensure(compile::Std { compiler, target: compiler.host });
1132 let _folder = build.fold_output(|| "test_error_index");
1133 println!("Testing error-index stage{}", compiler.stage);
1135 let dir = testdir(build, compiler.host);
1136 t!(fs::create_dir_all(&dir));
1137 let output = dir.join("error-index.md");
1139 let _time = util::timeit();
1140 build.run(builder.tool_cmd(Tool::ErrorIndex)
1143 .env("CFG_BUILD", &build.build)
1144 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
1146 markdown_test(builder, compiler, &output);
1150 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
1151 let build = builder.build;
1152 let mut file = t!(File::open(markdown));
1153 let mut contents = String::new();
1154 t!(file.read_to_string(&mut contents));
1155 if !contents.contains("```") {
1159 println!("doc tests for: {}", markdown.display());
1160 let mut cmd = builder.rustdoc_cmd(compiler.host);
1161 build.add_rust_test_threads(&mut cmd);
1164 cmd.env("RUSTC_BOOTSTRAP", "1");
1166 let test_args = build.config.cmd.test_args().join(" ");
1167 cmd.arg("--test-args").arg(test_args);
1169 if build.config.quiet_tests {
1170 try_run_quiet(build, &mut cmd)
1172 try_run(build, &mut cmd)
1176 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1177 pub struct CrateLibrustc {
1179 target: Interned<String>,
1180 test_kind: TestKind,
1181 krate: Interned<String>,
1184 impl Step for CrateLibrustc {
1186 const DEFAULT: bool = true;
1187 const ONLY_HOSTS: bool = true;
1189 fn should_run(run: ShouldRun) -> ShouldRun {
1190 run.krate("rustc-main")
1193 fn make_run(run: RunConfig) {
1194 let builder = run.builder;
1195 let compiler = builder.compiler(builder.top_stage, run.host);
1197 for krate in builder.in_tree_crates("rustc-main") {
1198 if run.path.ends_with(&krate.path) {
1199 let test_kind = if builder.kind == Kind::Test {
1201 } else if builder.kind == Kind::Bench {
1204 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1207 builder.ensure(CrateLibrustc {
1217 fn run(self, builder: &Builder) {
1218 builder.ensure(Crate {
1219 compiler: self.compiler,
1220 target: self.target,
1221 mode: Mode::Librustc,
1222 test_kind: self.test_kind,
1228 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1229 pub struct CrateNotDefault {
1231 target: Interned<String>,
1232 test_kind: TestKind,
1233 krate: &'static str,
1236 impl Step for CrateNotDefault {
1239 fn should_run(run: ShouldRun) -> ShouldRun {
1240 run.path("src/liballoc_jemalloc")
1241 .path("src/librustc_asan")
1242 .path("src/librustc_lsan")
1243 .path("src/librustc_msan")
1244 .path("src/librustc_tsan")
1247 fn make_run(run: RunConfig) {
1248 let builder = run.builder;
1249 let compiler = builder.compiler(builder.top_stage, run.host);
1251 let test_kind = if builder.kind == Kind::Test {
1253 } else if builder.kind == Kind::Bench {
1256 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1259 builder.ensure(CrateNotDefault {
1263 krate: match run.path {
1264 _ if run.path.ends_with("src/liballoc_jemalloc") => "alloc_jemalloc",
1265 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1266 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1267 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1268 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1269 _ => panic!("unexpected path {:?}", run.path),
1274 fn run(self, builder: &Builder) {
1275 builder.ensure(Crate {
1276 compiler: self.compiler,
1277 target: self.target,
1279 test_kind: self.test_kind,
1280 krate: INTERNER.intern_str(self.krate),
1286 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1289 target: Interned<String>,
1291 test_kind: TestKind,
1292 krate: Interned<String>,
1295 impl Step for Crate {
1297 const DEFAULT: bool = true;
1299 fn should_run(mut run: ShouldRun) -> ShouldRun {
1300 let builder = run.builder;
1301 run = run.krate("test");
1302 for krate in run.builder.in_tree_crates("std") {
1303 if krate.is_local(&run.builder) &&
1304 !krate.name.contains("jemalloc") &&
1305 !(krate.name.starts_with("rustc_") && krate.name.ends_with("san")) &&
1306 krate.name != "dlmalloc" {
1307 run = run.path(krate.local_path(&builder).to_str().unwrap());
1313 fn make_run(run: RunConfig) {
1314 let builder = run.builder;
1315 let compiler = builder.compiler(builder.top_stage, run.host);
1317 let make = |mode: Mode, krate: &CargoCrate| {
1318 let test_kind = if builder.kind == Kind::Test {
1320 } else if builder.kind == Kind::Bench {
1323 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1326 builder.ensure(Crate {
1335 for krate in builder.in_tree_crates("std") {
1336 if run.path.ends_with(&krate.local_path(&builder)) {
1337 make(Mode::Libstd, krate);
1340 for krate in builder.in_tree_crates("test") {
1341 if run.path.ends_with(&krate.local_path(&builder)) {
1342 make(Mode::Libtest, krate);
1347 /// Run all unit tests plus documentation tests for a given crate defined
1348 /// by a `Cargo.toml` (single manifest)
1350 /// This is what runs tests for crates like the standard library, compiler, etc.
1351 /// It essentially is the driver for running `cargo test`.
1353 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1354 /// arguments, and those arguments are discovered from `cargo metadata`.
1355 fn run(self, builder: &Builder) {
1356 let build = builder.build;
1357 let compiler = self.compiler;
1358 let target = self.target;
1359 let mode = self.mode;
1360 let test_kind = self.test_kind;
1361 let krate = self.krate;
1363 builder.ensure(compile::Test { compiler, target });
1364 builder.ensure(RemoteCopyLibs { compiler, target });
1366 // If we're not doing a full bootstrap but we're testing a stage2 version of
1367 // libstd, then what we're actually testing is the libstd produced in
1368 // stage1. Reflect that here by updating the compiler that we're working
1369 // with automatically.
1370 let compiler = if build.force_use_stage1(compiler, target) {
1371 builder.compiler(1, compiler.host)
1376 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1379 compile::std_cargo(build, &compiler, target, &mut cargo);
1382 compile::test_cargo(build, &compiler, target, &mut cargo);
1385 builder.ensure(compile::Rustc { compiler, target });
1386 compile::rustc_cargo(build, &mut cargo);
1388 _ => panic!("can only test libraries"),
1390 let _folder = build.fold_output(|| {
1391 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, krate)
1393 println!("{} {} stage{} ({} -> {})", test_kind, krate, compiler.stage,
1394 &compiler.host, target);
1396 // Build up the base `cargo test` command.
1398 // Pass in some standard flags then iterate over the graph we've discovered
1399 // in `cargo metadata` with the maps above and figure out what `-p`
1400 // arguments need to get passed.
1401 if test_kind.subcommand() == "test" && !build.fail_fast {
1402 cargo.arg("--no-fail-fast");
1404 if build.doc_tests {
1408 cargo.arg("-p").arg(krate);
1410 // The tests are going to run with the *target* libraries, so we need to
1411 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1413 // Note that to run the compiler we need to run with the *host* libraries,
1414 // but our wrapper scripts arrange for that to be the case anyway.
1415 let mut dylib_path = dylib_path();
1416 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1417 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1420 cargo.args(&build.config.cmd.test_args());
1422 if build.config.quiet_tests {
1423 cargo.arg("--quiet");
1426 let _time = util::timeit();
1428 if target.contains("emscripten") {
1429 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1430 build.config.nodejs.as_ref().expect("nodejs not configured"));
1431 } else if target.starts_with("wasm32") {
1432 // Warn about running tests without the `wasm_syscall` feature enabled.
1433 // The javascript shim implements the syscall interface so that test
1434 // output can be correctly reported.
1435 if !build.config.wasm_syscall {
1436 println!("Libstd was built without `wasm_syscall` feature enabled: \
1437 test output may not be visible.");
1440 // On the wasm32-unknown-unknown target we're using LTO which is
1441 // incompatible with `-C prefer-dynamic`, so disable that here
1442 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1444 let node = build.config.nodejs.as_ref()
1445 .expect("nodejs not configured");
1446 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1448 build.src.display());
1449 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1450 } else if build.remote_tested(target) {
1451 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1453 builder.tool_exe(Tool::RemoteTestClient).display()));
1455 try_run(build, &mut cargo);
1459 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1460 pub struct CrateRustdoc {
1461 host: Interned<String>,
1462 test_kind: TestKind,
1465 impl Step for CrateRustdoc {
1467 const DEFAULT: bool = true;
1468 const ONLY_HOSTS: bool = true;
1470 fn should_run(run: ShouldRun) -> ShouldRun {
1471 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1474 fn make_run(run: RunConfig) {
1475 let builder = run.builder;
1477 let test_kind = if builder.kind == Kind::Test {
1479 } else if builder.kind == Kind::Bench {
1482 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1485 builder.ensure(CrateRustdoc {
1491 fn run(self, builder: &Builder) {
1492 let build = builder.build;
1493 let test_kind = self.test_kind;
1495 let compiler = builder.compiler(builder.top_stage, self.host);
1496 let target = compiler.host;
1498 let mut cargo = tool::prepare_tool_cargo(builder,
1501 test_kind.subcommand(),
1502 "src/tools/rustdoc");
1503 let _folder = build.fold_output(|| {
1504 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1506 println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1507 &compiler.host, target);
1509 if test_kind.subcommand() == "test" && !build.fail_fast {
1510 cargo.arg("--no-fail-fast");
1513 cargo.arg("-p").arg("rustdoc:0.0.0");
1516 cargo.args(&build.config.cmd.test_args());
1518 if build.config.quiet_tests {
1519 cargo.arg("--quiet");
1522 let _time = util::timeit();
1524 try_run(build, &mut cargo);
1528 fn envify(s: &str) -> String {
1534 }).flat_map(|c| c.to_uppercase()).collect()
1537 /// Some test suites are run inside emulators or on remote devices, and most
1538 /// of our test binaries are linked dynamically which means we need to ship
1539 /// the standard library and such to the emulator ahead of time. This step
1540 /// represents this and is a dependency of all test suites.
1542 /// Most of the time this is a noop. For some steps such as shipping data to
1543 /// QEMU we have to build our own tools so we've got conditional dependencies
1544 /// on those programs as well. Note that the remote test client is built for
1545 /// the build target (us) and the server is built for the target.
1546 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1547 pub struct RemoteCopyLibs {
1549 target: Interned<String>,
1552 impl Step for RemoteCopyLibs {
1555 fn should_run(run: ShouldRun) -> ShouldRun {
1559 fn run(self, builder: &Builder) {
1560 let build = builder.build;
1561 let compiler = self.compiler;
1562 let target = self.target;
1563 if !build.remote_tested(target) {
1567 builder.ensure(compile::Test { compiler, target });
1569 println!("REMOTE copy libs to emulator ({})", target);
1570 t!(fs::create_dir_all(build.out.join("tmp")));
1572 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1574 // Spawn the emulator and wait for it to come online
1575 let tool = builder.tool_exe(Tool::RemoteTestClient);
1576 let mut cmd = Command::new(&tool);
1577 cmd.arg("spawn-emulator")
1580 .arg(build.out.join("tmp"));
1581 if let Some(rootfs) = build.qemu_rootfs(target) {
1584 build.run(&mut cmd);
1586 // Push all our dylibs to the emulator
1587 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1589 let name = f.file_name().into_string().unwrap();
1590 if util::is_dylib(&name) {
1591 build.run(Command::new(&tool)
1599 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1600 pub struct Distcheck;
1602 impl Step for Distcheck {
1605 fn should_run(run: ShouldRun) -> ShouldRun {
1606 run.path("distcheck")
1609 fn make_run(run: RunConfig) {
1610 run.builder.ensure(Distcheck);
1613 /// Run "distcheck", a 'make check' from a tarball
1614 fn run(self, builder: &Builder) {
1615 let build = builder.build;
1617 println!("Distcheck");
1618 let dir = build.out.join("tmp").join("distcheck");
1619 let _ = fs::remove_dir_all(&dir);
1620 t!(fs::create_dir_all(&dir));
1622 // Guarantee that these are built before we begin running.
1623 builder.ensure(dist::PlainSourceTarball);
1624 builder.ensure(dist::Src);
1626 let mut cmd = Command::new("tar");
1628 .arg(builder.ensure(dist::PlainSourceTarball))
1629 .arg("--strip-components=1")
1631 build.run(&mut cmd);
1632 build.run(Command::new("./configure")
1633 .args(&build.config.configure_args)
1634 .arg("--enable-vendor")
1635 .current_dir(&dir));
1636 build.run(Command::new(build_helper::make(&build.build))
1638 .current_dir(&dir));
1640 // Now make sure that rust-src has all of libstd's dependencies
1641 println!("Distcheck rust-src");
1642 let dir = build.out.join("tmp").join("distcheck-src");
1643 let _ = fs::remove_dir_all(&dir);
1644 t!(fs::create_dir_all(&dir));
1646 let mut cmd = Command::new("tar");
1648 .arg(builder.ensure(dist::Src))
1649 .arg("--strip-components=1")
1651 build.run(&mut cmd);
1653 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1654 build.run(Command::new(&build.initial_cargo)
1655 .arg("generate-lockfile")
1656 .arg("--manifest-path")
1658 .current_dir(&dir));
1662 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1663 pub struct Bootstrap;
1665 impl Step for Bootstrap {
1667 const DEFAULT: bool = true;
1668 const ONLY_HOSTS: bool = true;
1670 /// Test the build system itself
1671 fn run(self, builder: &Builder) {
1672 let build = builder.build;
1673 let mut cmd = Command::new(&build.initial_cargo);
1675 .current_dir(build.src.join("src/bootstrap"))
1676 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1677 .env("RUSTC_BOOTSTRAP", "1")
1678 .env("RUSTC", &build.initial_rustc);
1679 if !build.fail_fast {
1680 cmd.arg("--no-fail-fast");
1682 cmd.arg("--").args(&build.config.cmd.test_args());
1683 try_run(build, &mut cmd);
1686 fn should_run(run: ShouldRun) -> ShouldRun {
1687 run.path("src/bootstrap")
1690 fn make_run(run: RunConfig) {
1691 run.builder.ensure(Bootstrap);