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};
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(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) {
83 if !build.try_run_quiet(cmd) {
84 let mut failures = build.delayed_failures.borrow_mut();
85 failures.push(format!("{:?}", cmd));
92 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
93 pub struct Linkcheck {
94 host: Interned<String>,
97 impl Step for Linkcheck {
99 const ONLY_HOSTS: bool = true;
100 const DEFAULT: bool = true;
102 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
104 /// This tool in `src/tools` will verify the validity of all our links in the
105 /// documentation to ensure we don't have a bunch of dead ones.
106 fn run(self, builder: &Builder) {
107 let build = builder.build;
108 let host = self.host;
110 println!("Linkcheck ({})", host);
112 builder.default_doc(None);
114 let _time = util::timeit();
115 try_run(build, builder.tool_cmd(Tool::Linkchecker)
116 .arg(build.out.join(host).join("doc")));
119 fn should_run(run: ShouldRun) -> ShouldRun {
120 let builder = run.builder;
121 run.path("src/tools/linkchecker").default_condition(builder.build.config.docs)
124 fn make_run(run: RunConfig) {
125 run.builder.ensure(Linkcheck { host: run.target });
129 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
130 pub struct Cargotest {
132 host: Interned<String>,
135 impl Step for Cargotest {
137 const ONLY_HOSTS: bool = true;
139 fn should_run(run: ShouldRun) -> ShouldRun {
140 run.path("src/tools/cargotest")
143 fn make_run(run: RunConfig) {
144 run.builder.ensure(Cargotest {
145 stage: run.builder.top_stage,
150 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
152 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
153 /// test` to ensure that we don't regress the test suites there.
154 fn run(self, builder: &Builder) {
155 let build = builder.build;
156 let compiler = builder.compiler(self.stage, self.host);
157 builder.ensure(compile::Rustc { compiler, target: compiler.host });
159 // Note that this is a short, cryptic, and not scoped directory name. This
160 // is currently to minimize the length of path on Windows where we otherwise
161 // quickly run into path name limit constraints.
162 let out_dir = build.out.join("ct");
163 t!(fs::create_dir_all(&out_dir));
165 let _time = util::timeit();
166 let mut cmd = builder.tool_cmd(Tool::CargoTest);
167 try_run(build, cmd.arg(&build.initial_cargo)
169 .env("RUSTC", builder.rustc(compiler))
170 .env("RUSTDOC", builder.rustdoc(compiler.host)));
174 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
177 host: Interned<String>,
180 impl Step for Cargo {
182 const ONLY_HOSTS: bool = true;
184 fn should_run(run: ShouldRun) -> ShouldRun {
185 run.path("src/tools/cargo")
188 fn make_run(run: RunConfig) {
189 run.builder.ensure(Cargo {
190 stage: run.builder.top_stage,
195 /// Runs `cargo test` for `cargo` packaged with Rust.
196 fn run(self, builder: &Builder) {
197 let build = builder.build;
198 let compiler = builder.compiler(self.stage, self.host);
200 builder.ensure(tool::Cargo { compiler, target: self.host });
201 let mut cargo = builder.cargo(compiler, Mode::Tool, self.host, "test");
202 cargo.arg("--manifest-path").arg(build.src.join("src/tools/cargo/Cargo.toml"));
203 if !build.fail_fast {
204 cargo.arg("--no-fail-fast");
207 // Don't build tests dynamically, just a pain to work with
208 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
210 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
212 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
214 try_run(build, cargo.env("PATH", &path_for_cargo(builder, compiler)));
218 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
221 host: Interned<String>,
226 const ONLY_HOSTS: bool = true;
228 fn should_run(run: ShouldRun) -> ShouldRun {
229 run.path("src/tools/rls")
232 fn make_run(run: RunConfig) {
233 run.builder.ensure(Rls {
234 stage: run.builder.top_stage,
239 /// Runs `cargo test` for the rls.
240 fn run(self, builder: &Builder) {
241 let build = builder.build;
242 let stage = self.stage;
243 let host = self.host;
244 let compiler = builder.compiler(stage, host);
246 builder.ensure(tool::Rls { compiler, target: self.host });
247 let mut cargo = tool::prepare_tool_cargo(builder,
253 // Don't build tests dynamically, just a pain to work with
254 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
256 builder.add_rustc_lib_path(compiler, &mut cargo);
258 if try_run(build, &mut cargo) {
259 build.save_toolstate("rls", ToolState::TestPass);
264 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
267 host: Interned<String>,
270 impl Step for Rustfmt {
272 const ONLY_HOSTS: bool = true;
274 fn should_run(run: ShouldRun) -> ShouldRun {
275 run.path("src/tools/rustfmt")
278 fn make_run(run: RunConfig) {
279 run.builder.ensure(Rustfmt {
280 stage: run.builder.top_stage,
285 /// Runs `cargo test` for rustfmt.
286 fn run(self, builder: &Builder) {
287 let build = builder.build;
288 let stage = self.stage;
289 let host = self.host;
290 let compiler = builder.compiler(stage, host);
292 builder.ensure(tool::Rustfmt { compiler, target: self.host });
293 let mut cargo = tool::prepare_tool_cargo(builder,
297 "src/tools/rustfmt");
299 // Don't build tests dynamically, just a pain to work with
300 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
302 builder.add_rustc_lib_path(compiler, &mut cargo);
304 if try_run(build, &mut cargo) {
305 build.save_toolstate("rustfmt", ToolState::TestPass);
310 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
313 host: Interned<String>,
318 const ONLY_HOSTS: bool = true;
319 const DEFAULT: bool = true;
321 fn should_run(run: ShouldRun) -> ShouldRun {
322 let test_miri = run.builder.build.config.test_miri;
323 run.path("src/tools/miri").default_condition(test_miri)
326 fn make_run(run: RunConfig) {
327 run.builder.ensure(Miri {
328 stage: run.builder.top_stage,
333 /// Runs `cargo test` for miri.
334 fn run(self, builder: &Builder) {
335 let build = builder.build;
336 let stage = self.stage;
337 let host = self.host;
338 let compiler = builder.compiler(stage, host);
340 if let Some(miri) = builder.ensure(tool::Miri { compiler, target: self.host }) {
341 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
342 cargo.arg("--manifest-path").arg(build.src.join("src/tools/miri/Cargo.toml"));
344 // Don't build tests dynamically, just a pain to work with
345 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
346 // miri tests need to know about the stage sysroot
347 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
348 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
349 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
350 cargo.env("MIRI_PATH", miri);
352 builder.add_rustc_lib_path(compiler, &mut cargo);
354 if try_run(build, &mut cargo) {
355 build.save_toolstate("miri", ToolState::TestPass);
358 eprintln!("failed to test miri: could not build");
363 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
366 host: Interned<String>,
369 impl Step for Clippy {
371 const ONLY_HOSTS: bool = true;
372 const DEFAULT: bool = false;
374 fn should_run(run: ShouldRun) -> ShouldRun {
375 run.path("src/tools/clippy")
378 fn make_run(run: RunConfig) {
379 run.builder.ensure(Clippy {
380 stage: run.builder.top_stage,
385 /// Runs `cargo test` for clippy.
386 fn run(self, builder: &Builder) {
387 let build = builder.build;
388 let stage = self.stage;
389 let host = self.host;
390 let compiler = builder.compiler(stage, host);
392 if let Some(clippy) = builder.ensure(tool::Clippy { compiler, target: self.host }) {
393 let mut cargo = builder.cargo(compiler, Mode::Tool, host, "test");
394 cargo.arg("--manifest-path").arg(build.src.join("src/tools/clippy/Cargo.toml"));
396 // Don't build tests dynamically, just a pain to work with
397 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
398 // clippy tests need to know about the stage sysroot
399 cargo.env("SYSROOT", builder.sysroot(compiler));
400 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
401 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
402 let host_libs = builder.stage_out(compiler, Mode::Tool).join(builder.cargo_dir());
403 cargo.env("HOST_LIBS", host_libs);
404 // clippy tests need to find the driver
405 cargo.env("CLIPPY_DRIVER_PATH", clippy);
407 builder.add_rustc_lib_path(compiler, &mut cargo);
409 if try_run(build, &mut cargo) {
410 build.save_toolstate("clippy-driver", ToolState::TestPass);
413 eprintln!("failed to test clippy: could not build");
418 fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
419 // Configure PATH to find the right rustc. NB. we have to use PATH
420 // and not RUSTC because the Cargo test suite has tests that will
421 // fail if rustc is not spelled `rustc`.
422 let path = builder.sysroot(compiler).join("bin");
423 let old_path = env::var_os("PATH").unwrap_or_default();
424 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
427 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
428 pub struct RustdocJS {
429 pub host: Interned<String>,
430 pub target: Interned<String>,
433 impl Step for RustdocJS {
435 const DEFAULT: bool = true;
436 const ONLY_HOSTS: bool = true;
438 fn should_run(run: ShouldRun) -> ShouldRun {
439 run.path("src/test/rustdoc-js")
442 fn make_run(run: RunConfig) {
443 run.builder.ensure(RustdocJS {
449 fn run(self, builder: &Builder) {
450 if let Some(ref nodejs) = builder.config.nodejs {
451 let mut command = Command::new(nodejs);
452 command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
453 builder.ensure(::doc::Std {
455 stage: builder.top_stage,
457 builder.run(&mut command);
459 println!("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
464 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
466 host: Interned<String>,
471 const DEFAULT: bool = true;
472 const ONLY_HOSTS: bool = true;
473 const ONLY_BUILD: bool = true;
475 /// Runs the `tidy` tool as compiled in `stage` by the `host` compiler.
477 /// This tool in `src/tools` checks up on various bits and pieces of style and
478 /// otherwise just implements a few lint-like checks that are specific to the
480 fn run(self, builder: &Builder) {
481 let build = builder.build;
482 let host = self.host;
484 let _folder = build.fold_output(|| "tidy");
485 println!("tidy check ({})", host);
486 let mut cmd = builder.tool_cmd(Tool::Tidy);
487 cmd.arg(build.src.join("src"));
488 if !build.config.vendor {
489 cmd.arg("--no-vendor");
491 if build.config.quiet_tests {
494 try_run(build, &mut cmd);
497 fn should_run(run: ShouldRun) -> ShouldRun {
498 run.path("src/tools/tidy")
501 fn make_run(run: RunConfig) {
502 run.builder.ensure(Tidy {
503 host: run.builder.build.build,
508 fn testdir(build: &Build, host: Interned<String>) -> PathBuf {
509 build.out.join(host).join("test")
512 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
519 static DEFAULT_COMPILETESTS: &[Test] = &[
520 Test { path: "src/test/ui", mode: "ui", suite: "ui" },
521 Test { path: "src/test/run-pass", mode: "run-pass", suite: "run-pass" },
522 Test { path: "src/test/compile-fail", mode: "compile-fail", suite: "compile-fail" },
523 Test { path: "src/test/parse-fail", mode: "parse-fail", suite: "parse-fail" },
524 Test { path: "src/test/run-fail", mode: "run-fail", suite: "run-fail" },
526 path: "src/test/run-pass-valgrind",
527 mode: "run-pass-valgrind",
528 suite: "run-pass-valgrind"
530 Test { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" },
531 Test { path: "src/test/codegen", mode: "codegen", suite: "codegen" },
532 Test { path: "src/test/codegen-units", mode: "codegen-units", suite: "codegen-units" },
533 Test { path: "src/test/incremental", mode: "incremental", suite: "incremental" },
535 // What this runs varies depending on the native platform being apple
536 Test { path: "src/test/debuginfo", mode: "debuginfo-XXX", suite: "debuginfo" },
539 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
540 pub struct DefaultCompiletest {
542 target: Interned<String>,
547 impl Step for DefaultCompiletest {
549 const DEFAULT: bool = true;
551 fn should_run(mut run: ShouldRun) -> ShouldRun {
552 for test in DEFAULT_COMPILETESTS {
553 run = run.path(test.path);
558 fn make_run(run: RunConfig) {
559 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
561 let test = run.path.map(|path| {
562 DEFAULT_COMPILETESTS.iter().find(|&&test| {
563 path.ends_with(test.path)
564 }).unwrap_or_else(|| {
565 panic!("make_run in compile test to receive test path, received {:?}", path);
569 if let Some(test) = test {
570 run.builder.ensure(DefaultCompiletest {
577 for test in DEFAULT_COMPILETESTS {
578 run.builder.ensure(DefaultCompiletest {
588 fn run(self, builder: &Builder) {
589 builder.ensure(Compiletest {
590 compiler: self.compiler,
598 // Also default, but host-only.
599 static HOST_COMPILETESTS: &[Test] = &[
600 Test { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" },
601 Test { path: "src/test/run-pass-fulldeps", mode: "run-pass", suite: "run-pass-fulldeps" },
602 Test { path: "src/test/run-fail-fulldeps", mode: "run-fail", suite: "run-fail-fulldeps" },
604 path: "src/test/compile-fail-fulldeps",
605 mode: "compile-fail",
606 suite: "compile-fail-fulldeps",
609 path: "src/test/incremental-fulldeps",
611 suite: "incremental-fulldeps",
613 Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
614 Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
616 Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
617 Test { path: "src/test/run-pass/pretty", mode: "pretty", suite: "run-pass" },
618 Test { path: "src/test/run-fail/pretty", mode: "pretty", suite: "run-fail" },
619 Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
620 Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
621 Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
624 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
625 pub struct HostCompiletest {
627 target: Interned<String>,
632 impl Step for HostCompiletest {
634 const DEFAULT: bool = true;
635 const ONLY_HOSTS: bool = true;
637 fn should_run(mut run: ShouldRun) -> ShouldRun {
638 for test in HOST_COMPILETESTS {
639 run = run.path(test.path);
644 fn make_run(run: RunConfig) {
645 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
647 let test = run.path.map(|path| {
648 HOST_COMPILETESTS.iter().find(|&&test| {
649 path.ends_with(test.path)
650 }).unwrap_or_else(|| {
651 panic!("make_run in compile test to receive test path, received {:?}", path);
655 if let Some(test) = test {
656 run.builder.ensure(HostCompiletest {
663 for test in HOST_COMPILETESTS {
664 if test.mode == "pretty" {
667 run.builder.ensure(HostCompiletest {
677 fn run(self, builder: &Builder) {
678 builder.ensure(Compiletest {
679 compiler: self.compiler,
687 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
690 target: Interned<String>,
695 impl Step for Compiletest {
698 fn should_run(run: ShouldRun) -> ShouldRun {
702 /// Executes the `compiletest` tool to run a suite of tests.
704 /// Compiles all tests with `compiler` for `target` with the specified
705 /// compiletest `mode` and `suite` arguments. For example `mode` can be
706 /// "run-pass" or `suite` can be something like `debuginfo`.
707 fn run(self, builder: &Builder) {
708 let build = builder.build;
709 let compiler = self.compiler;
710 let target = self.target;
711 let mode = self.mode;
712 let suite = self.suite;
714 // Skip codegen tests if they aren't enabled in configuration.
715 if !build.config.codegen_tests && suite == "codegen" {
719 if suite == "debuginfo" {
720 // Skip debuginfo tests on MSVC
721 if build.build.contains("msvc") {
725 if mode == "debuginfo-XXX" {
726 return if build.build.contains("apple") {
727 builder.ensure(Compiletest {
728 mode: "debuginfo-lldb",
732 builder.ensure(Compiletest {
733 mode: "debuginfo-gdb",
739 builder.ensure(dist::DebuggerScripts {
740 sysroot: builder.sysroot(compiler),
745 if suite.ends_with("fulldeps") ||
746 // FIXME: Does pretty need librustc compiled? Note that there are
747 // fulldeps test suites with mode = pretty as well.
751 builder.ensure(compile::Rustc { compiler, target });
754 builder.ensure(compile::Test { compiler, target });
755 builder.ensure(native::TestHelpers { target });
756 builder.ensure(RemoteCopyLibs { compiler, target });
758 let _folder = build.fold_output(|| format!("test_{}", suite));
759 println!("Check compiletest suite={} mode={} ({} -> {})",
760 suite, mode, &compiler.host, target);
761 let mut cmd = builder.tool_cmd(Tool::Compiletest);
763 // compiletest currently has... a lot of arguments, so let's just pass all
766 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
767 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
768 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
770 // Avoid depending on rustdoc when we don't need it.
771 if mode == "rustdoc" || mode == "run-make" {
772 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler.host));
775 cmd.arg("--src-base").arg(build.src.join("src/test").join(suite));
776 cmd.arg("--build-base").arg(testdir(build, compiler.host).join(suite));
777 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
778 cmd.arg("--mode").arg(mode);
779 cmd.arg("--target").arg(target);
780 cmd.arg("--host").arg(&*compiler.host);
781 cmd.arg("--llvm-filecheck").arg(build.llvm_filecheck(build.build));
783 if let Some(ref nodejs) = build.config.nodejs {
784 cmd.arg("--nodejs").arg(nodejs);
787 let mut flags = vec!["-Crpath".to_string()];
788 if build.config.rust_optimize_tests {
789 flags.push("-O".to_string());
791 if build.config.rust_debuginfo_tests {
792 flags.push("-g".to_string());
794 flags.push("-Zmiri -Zunstable-options".to_string());
796 if let Some(linker) = build.linker(target) {
797 cmd.arg("--linker").arg(linker);
800 let hostflags = flags.clone();
801 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
803 let mut targetflags = flags.clone();
804 targetflags.push(format!("-Lnative={}",
805 build.test_helpers_out(target).display()));
806 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
808 cmd.arg("--docck-python").arg(build.python());
810 if build.build.ends_with("apple-darwin") {
811 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
812 // LLDB plugin's compiled module which only works with the system python
813 // (namely not Homebrew-installed python)
814 cmd.arg("--lldb-python").arg("/usr/bin/python");
816 cmd.arg("--lldb-python").arg(build.python());
819 if let Some(ref gdb) = build.config.gdb {
820 cmd.arg("--gdb").arg(gdb);
822 if let Some(ref vers) = build.lldb_version {
823 cmd.arg("--lldb-version").arg(vers);
825 if let Some(ref dir) = build.lldb_python_dir {
826 cmd.arg("--lldb-python-dir").arg(dir);
829 cmd.args(&build.config.cmd.test_args());
831 if build.is_verbose() {
832 cmd.arg("--verbose");
835 if build.config.quiet_tests {
839 if build.config.llvm_enabled {
840 let llvm_config = build.llvm_config(target);
841 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
842 cmd.arg("--llvm-version").arg(llvm_version);
843 if !build.is_rust_llvm(target) {
844 cmd.arg("--system-llvm");
847 // Only pass correct values for these flags for the `run-make` suite as it
848 // requires that a C++ compiler was configured which isn't always the case.
849 if suite == "run-make" {
850 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
851 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
852 cmd.arg("--cc").arg(build.cc(target))
853 .arg("--cxx").arg(build.cxx(target).unwrap())
854 .arg("--cflags").arg(build.cflags(target).join(" "))
855 .arg("--llvm-components").arg(llvm_components.trim())
856 .arg("--llvm-cxxflags").arg(llvm_cxxflags.trim());
857 if let Some(ar) = build.ar(target) {
858 cmd.arg("--ar").arg(ar);
862 if suite == "run-make" && !build.config.llvm_enabled {
863 println!("Ignoring run-make test suite as they generally dont work without LLVM");
867 if suite != "run-make" {
868 cmd.arg("--cc").arg("")
869 .arg("--cxx").arg("")
870 .arg("--cflags").arg("")
871 .arg("--llvm-components").arg("")
872 .arg("--llvm-cxxflags").arg("");
875 if build.remote_tested(target) {
876 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
879 // Running a C compiler on MSVC requires a few env vars to be set, to be
880 // sure to set them here.
882 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
883 // rather than stomp over it.
884 if target.contains("msvc") {
885 for &(ref k, ref v) in build.cc[&target].env() {
891 cmd.env("RUSTC_BOOTSTRAP", "1");
892 build.add_rust_test_threads(&mut cmd);
894 if build.config.sanitizers {
895 cmd.env("SANITIZER_SUPPORT", "1");
898 if build.config.profiler {
899 cmd.env("PROFILER_SUPPORT", "1");
902 cmd.arg("--adb-path").arg("adb");
903 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
904 if target.contains("android") {
905 // Assume that cc for this target comes from the android sysroot
906 cmd.arg("--android-cross-path")
907 .arg(build.cc(target).parent().unwrap().parent().unwrap());
909 cmd.arg("--android-cross-path").arg("");
912 build.ci_env.force_coloring_in_ci(&mut cmd);
914 let _time = util::timeit();
915 try_run(build, &mut cmd);
919 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
926 const DEFAULT: bool = true;
927 const ONLY_HOSTS: bool = true;
929 fn should_run(run: ShouldRun) -> ShouldRun {
933 fn make_run(run: RunConfig) {
934 run.builder.ensure(Docs {
935 compiler: run.builder.compiler(run.builder.top_stage, run.host),
939 /// Run `rustdoc --test` for all documentation in `src/doc`.
941 /// This will run all tests in our markdown documentation (e.g. the book)
942 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
944 fn run(self, builder: &Builder) {
945 let build = builder.build;
946 let compiler = self.compiler;
948 builder.ensure(compile::Test { compiler, target: compiler.host });
950 // Do a breadth-first traversal of the `src/doc` directory and just run
951 // tests for all files that end in `*.md`
952 let mut stack = vec![build.src.join("src/doc")];
953 let _time = util::timeit();
954 let _folder = build.fold_output(|| "test_docs");
956 while let Some(p) = stack.pop() {
958 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
962 if p.extension().and_then(|s| s.to_str()) != Some("md") {
966 // The nostarch directory in the book is for no starch, and so isn't
967 // guaranteed to build. We don't care if it doesn't build, so skip it.
968 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
972 markdown_test(builder, compiler, &p);
977 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
978 pub struct ErrorIndex {
982 impl Step for ErrorIndex {
984 const DEFAULT: bool = true;
985 const ONLY_HOSTS: bool = true;
987 fn should_run(run: ShouldRun) -> ShouldRun {
988 run.path("src/tools/error_index_generator")
991 fn make_run(run: RunConfig) {
992 run.builder.ensure(ErrorIndex {
993 compiler: run.builder.compiler(run.builder.top_stage, run.host),
997 /// Run the error index generator tool to execute the tests located in the error
1000 /// The `error_index_generator` tool lives in `src/tools` and is used to
1001 /// generate a markdown file from the error indexes of the code base which is
1002 /// then passed to `rustdoc --test`.
1003 fn run(self, builder: &Builder) {
1004 let build = builder.build;
1005 let compiler = self.compiler;
1007 builder.ensure(compile::Std { compiler, target: compiler.host });
1009 let _folder = build.fold_output(|| "test_error_index");
1010 println!("Testing error-index stage{}", compiler.stage);
1012 let dir = testdir(build, compiler.host);
1013 t!(fs::create_dir_all(&dir));
1014 let output = dir.join("error-index.md");
1016 let _time = util::timeit();
1017 build.run(builder.tool_cmd(Tool::ErrorIndex)
1020 .env("CFG_BUILD", &build.build)
1021 .env("RUSTC_ERROR_METADATA_DST", build.extended_error_dir()));
1023 markdown_test(builder, compiler, &output);
1027 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
1028 let build = builder.build;
1029 let mut file = t!(File::open(markdown));
1030 let mut contents = String::new();
1031 t!(file.read_to_string(&mut contents));
1032 if !contents.contains("```") {
1036 println!("doc tests for: {}", markdown.display());
1037 let mut cmd = builder.rustdoc_cmd(compiler.host);
1038 build.add_rust_test_threads(&mut cmd);
1041 cmd.env("RUSTC_BOOTSTRAP", "1");
1043 let test_args = build.config.cmd.test_args().join(" ");
1044 cmd.arg("--test-args").arg(test_args);
1046 if build.config.quiet_tests {
1047 try_run_quiet(build, &mut cmd);
1049 try_run(build, &mut cmd);
1053 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1054 pub struct CrateLibrustc {
1056 target: Interned<String>,
1057 test_kind: TestKind,
1058 krate: Option<Interned<String>>,
1061 impl Step for CrateLibrustc {
1063 const DEFAULT: bool = true;
1064 const ONLY_HOSTS: bool = true;
1066 fn should_run(run: ShouldRun) -> ShouldRun {
1067 run.krate("rustc-main")
1070 fn make_run(run: RunConfig) {
1071 let builder = run.builder;
1072 let compiler = builder.compiler(builder.top_stage, run.host);
1074 let make = |name: Option<Interned<String>>| {
1075 let test_kind = if builder.kind == Kind::Test {
1077 } else if builder.kind == Kind::Bench {
1080 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1083 builder.ensure(CrateLibrustc {
1091 if let Some(path) = run.path {
1092 for (name, krate_path) in builder.crates("rustc-main") {
1093 if path.ends_with(krate_path) {
1103 fn run(self, builder: &Builder) {
1104 builder.ensure(Crate {
1105 compiler: self.compiler,
1106 target: self.target,
1107 mode: Mode::Librustc,
1108 test_kind: self.test_kind,
1114 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1117 target: Interned<String>,
1119 test_kind: TestKind,
1120 krate: Option<Interned<String>>,
1123 impl Step for Crate {
1125 const DEFAULT: bool = true;
1127 fn should_run(run: ShouldRun) -> ShouldRun {
1128 run.krate("std").krate("test")
1131 fn make_run(run: RunConfig) {
1132 let builder = run.builder;
1133 let compiler = builder.compiler(builder.top_stage, run.host);
1135 let make = |mode: Mode, name: Option<Interned<String>>| {
1136 let test_kind = if builder.kind == Kind::Test {
1138 } else if builder.kind == Kind::Bench {
1141 panic!("unexpected builder.kind in crate: {:?}", builder.kind);
1144 builder.ensure(Crate {
1153 if let Some(path) = run.path {
1154 for (name, krate_path) in builder.crates("std") {
1155 if path.ends_with(krate_path) {
1156 make(Mode::Libstd, Some(name));
1159 for (name, krate_path) in builder.crates("test") {
1160 if path.ends_with(krate_path) {
1161 make(Mode::Libtest, Some(name));
1165 make(Mode::Libstd, None);
1166 make(Mode::Libtest, None);
1170 /// Run all unit tests plus documentation tests for an entire crate DAG defined
1171 /// by a `Cargo.toml`
1173 /// This is what runs tests for crates like the standard library, compiler, etc.
1174 /// It essentially is the driver for running `cargo test`.
1176 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1177 /// arguments, and those arguments are discovered from `cargo metadata`.
1178 fn run(self, builder: &Builder) {
1179 let build = builder.build;
1180 let compiler = self.compiler;
1181 let target = self.target;
1182 let mode = self.mode;
1183 let test_kind = self.test_kind;
1184 let krate = self.krate;
1186 builder.ensure(compile::Test { compiler, target });
1187 builder.ensure(RemoteCopyLibs { compiler, target });
1189 // If we're not doing a full bootstrap but we're testing a stage2 version of
1190 // libstd, then what we're actually testing is the libstd produced in
1191 // stage1. Reflect that here by updating the compiler that we're working
1192 // with automatically.
1193 let compiler = if build.force_use_stage1(compiler, target) {
1194 builder.compiler(1, compiler.host)
1199 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1200 let (name, root) = match mode {
1202 compile::std_cargo(build, &compiler, target, &mut cargo);
1206 compile::test_cargo(build, &compiler, target, &mut cargo);
1210 builder.ensure(compile::Rustc { compiler, target });
1211 compile::rustc_cargo(build, target, &mut cargo);
1212 ("librustc", "rustc-main")
1214 _ => panic!("can only test libraries"),
1216 let root = INTERNER.intern_string(String::from(root));
1217 let _folder = build.fold_output(|| {
1218 format!("{}_stage{}-{}", test_kind.subcommand(), compiler.stage, name)
1220 println!("{} {} stage{} ({} -> {})", test_kind, name, compiler.stage,
1221 &compiler.host, target);
1223 // Build up the base `cargo test` command.
1225 // Pass in some standard flags then iterate over the graph we've discovered
1226 // in `cargo metadata` with the maps above and figure out what `-p`
1227 // arguments need to get passed.
1228 if test_kind.subcommand() == "test" && !build.fail_fast {
1229 cargo.arg("--no-fail-fast");
1234 cargo.arg("-p").arg(krate);
1237 let mut visited = HashSet::new();
1238 let mut next = vec![root];
1239 while let Some(name) = next.pop() {
1240 // Right now jemalloc and the sanitizer crates are
1241 // target-specific crate in the sense that it's not present
1242 // on all platforms. Custom skip it here for now, but if we
1243 // add more this probably wants to get more generalized.
1245 // Also skip `build_helper` as it's not compiled normally
1246 // for target during the bootstrap and it's just meant to be
1247 // a helper crate, not tested. If it leaks through then it
1248 // ends up messing with various mtime calculations and such.
1249 if !name.contains("jemalloc") &&
1250 *name != *"build_helper" &&
1251 !(name.starts_with("rustc_") && name.ends_with("san")) &&
1252 name != "dlmalloc" {
1253 cargo.arg("-p").arg(&format!("{}:0.0.0", name));
1255 for dep in build.crates[&name].deps.iter() {
1256 if visited.insert(dep) {
1264 // The tests are going to run with the *target* libraries, so we need to
1265 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1267 // Note that to run the compiler we need to run with the *host* libraries,
1268 // but our wrapper scripts arrange for that to be the case anyway.
1269 let mut dylib_path = dylib_path();
1270 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1271 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1274 cargo.args(&build.config.cmd.test_args());
1276 if build.config.quiet_tests {
1277 cargo.arg("--quiet");
1280 let _time = util::timeit();
1282 if target.contains("emscripten") {
1283 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1284 build.config.nodejs.as_ref().expect("nodejs not configured"));
1285 } else if target.starts_with("wasm32") {
1286 // On the wasm32-unknown-unknown target we're using LTO which is
1287 // incompatible with `-C prefer-dynamic`, so disable that here
1288 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1290 let node = build.config.nodejs.as_ref()
1291 .expect("nodejs not configured");
1292 let runner = format!("{} {}/src/etc/wasm32-shim.js",
1294 build.src.display());
1295 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1296 } else if build.remote_tested(target) {
1297 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1299 builder.tool_exe(Tool::RemoteTestClient).display()));
1301 try_run(build, &mut cargo);
1305 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1306 pub struct Rustdoc {
1307 host: Interned<String>,
1308 test_kind: TestKind,
1311 impl Step for Rustdoc {
1313 const DEFAULT: bool = true;
1314 const ONLY_HOSTS: bool = true;
1316 fn should_run(run: ShouldRun) -> ShouldRun {
1317 run.path("src/librustdoc").path("src/tools/rustdoc")
1320 fn make_run(run: RunConfig) {
1321 let builder = run.builder;
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(Rustdoc {
1337 fn run(self, builder: &Builder) {
1338 let build = builder.build;
1339 let test_kind = self.test_kind;
1341 let compiler = builder.compiler(builder.top_stage, self.host);
1342 let target = compiler.host;
1344 let mut cargo = tool::prepare_tool_cargo(builder,
1347 test_kind.subcommand(),
1348 "src/tools/rustdoc");
1349 let _folder = build.fold_output(|| {
1350 format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage)
1352 println!("{} rustdoc stage{} ({} -> {})", test_kind, compiler.stage,
1353 &compiler.host, target);
1355 if test_kind.subcommand() == "test" && !build.fail_fast {
1356 cargo.arg("--no-fail-fast");
1359 cargo.arg("-p").arg("rustdoc:0.0.0");
1362 cargo.args(&build.config.cmd.test_args());
1364 if build.config.quiet_tests {
1365 cargo.arg("--quiet");
1368 let _time = util::timeit();
1370 try_run(build, &mut cargo);
1374 fn envify(s: &str) -> String {
1380 }).flat_map(|c| c.to_uppercase()).collect()
1383 /// Some test suites are run inside emulators or on remote devices, and most
1384 /// of our test binaries are linked dynamically which means we need to ship
1385 /// the standard library and such to the emulator ahead of time. This step
1386 /// represents this and is a dependency of all test suites.
1388 /// Most of the time this is a noop. For some steps such as shipping data to
1389 /// QEMU we have to build our own tools so we've got conditional dependencies
1390 /// on those programs as well. Note that the remote test client is built for
1391 /// the build target (us) and the server is built for the target.
1392 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1393 pub struct RemoteCopyLibs {
1395 target: Interned<String>,
1398 impl Step for RemoteCopyLibs {
1401 fn should_run(run: ShouldRun) -> ShouldRun {
1405 fn run(self, builder: &Builder) {
1406 let build = builder.build;
1407 let compiler = self.compiler;
1408 let target = self.target;
1409 if !build.remote_tested(target) {
1413 builder.ensure(compile::Test { compiler, target });
1415 println!("REMOTE copy libs to emulator ({})", target);
1416 t!(fs::create_dir_all(build.out.join("tmp")));
1418 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
1420 // Spawn the emulator and wait for it to come online
1421 let tool = builder.tool_exe(Tool::RemoteTestClient);
1422 let mut cmd = Command::new(&tool);
1423 cmd.arg("spawn-emulator")
1426 .arg(build.out.join("tmp"));
1427 if let Some(rootfs) = build.qemu_rootfs(target) {
1430 build.run(&mut cmd);
1432 // Push all our dylibs to the emulator
1433 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1435 let name = f.file_name().into_string().unwrap();
1436 if util::is_dylib(&name) {
1437 build.run(Command::new(&tool)
1445 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1446 pub struct Distcheck;
1448 impl Step for Distcheck {
1450 const ONLY_BUILD: bool = true;
1452 fn should_run(run: ShouldRun) -> ShouldRun {
1453 run.path("distcheck")
1456 fn make_run(run: RunConfig) {
1457 run.builder.ensure(Distcheck);
1460 /// Run "distcheck", a 'make check' from a tarball
1461 fn run(self, builder: &Builder) {
1462 let build = builder.build;
1464 println!("Distcheck");
1465 let dir = build.out.join("tmp").join("distcheck");
1466 let _ = fs::remove_dir_all(&dir);
1467 t!(fs::create_dir_all(&dir));
1469 // Guarantee that these are built before we begin running.
1470 builder.ensure(dist::PlainSourceTarball);
1471 builder.ensure(dist::Src);
1473 let mut cmd = Command::new("tar");
1475 .arg(builder.ensure(dist::PlainSourceTarball))
1476 .arg("--strip-components=1")
1478 build.run(&mut cmd);
1479 build.run(Command::new("./configure")
1480 .args(&build.config.configure_args)
1481 .arg("--enable-vendor")
1482 .current_dir(&dir));
1483 build.run(Command::new(build_helper::make(&build.build))
1485 .current_dir(&dir));
1487 // Now make sure that rust-src has all of libstd's dependencies
1488 println!("Distcheck rust-src");
1489 let dir = build.out.join("tmp").join("distcheck-src");
1490 let _ = fs::remove_dir_all(&dir);
1491 t!(fs::create_dir_all(&dir));
1493 let mut cmd = Command::new("tar");
1495 .arg(builder.ensure(dist::Src))
1496 .arg("--strip-components=1")
1498 build.run(&mut cmd);
1500 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1501 build.run(Command::new(&build.initial_cargo)
1502 .arg("generate-lockfile")
1503 .arg("--manifest-path")
1505 .current_dir(&dir));
1509 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1510 pub struct Bootstrap;
1512 impl Step for Bootstrap {
1514 const DEFAULT: bool = true;
1515 const ONLY_HOSTS: bool = true;
1516 const ONLY_BUILD: bool = true;
1518 /// Test the build system itself
1519 fn run(self, builder: &Builder) {
1520 let build = builder.build;
1521 let mut cmd = Command::new(&build.initial_cargo);
1523 .current_dir(build.src.join("src/bootstrap"))
1524 .env("CARGO_TARGET_DIR", build.out.join("bootstrap"))
1525 .env("RUSTC_BOOTSTRAP", "1")
1526 .env("RUSTC", &build.initial_rustc);
1527 if !build.fail_fast {
1528 cmd.arg("--no-fail-fast");
1530 cmd.arg("--").args(&build.config.cmd.test_args());
1531 try_run(build, &mut cmd);
1534 fn should_run(run: ShouldRun) -> ShouldRun {
1535 run.path("src/bootstrap")
1538 fn make_run(run: RunConfig) {
1539 run.builder.ensure(Bootstrap);