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;
19 use std::fs::{self, File};
22 use std::path::{Path, PathBuf};
23 use std::process::Command;
25 use build_helper::{self, output};
27 use builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
28 use cache::{Interned, INTERNER};
31 use flags::Subcommand;
33 use tool::{self, Tool, SourceType};
34 use toolstate::ToolState;
35 use util::{self, dylib_path, dylib_path_var};
36 use Crate as CargoCrate;
37 use {DocTests, Mode, GitRepo};
39 const ADB_TEST_DIR: &str = "/data/tmp/work";
41 /// The two modes of the test runner; tests or benchmarks.
42 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
50 impl From<Kind> for TestKind {
51 fn from(kind: Kind) -> Self {
53 Kind::Test => TestKind::Test,
54 Kind::Bench => TestKind::Bench,
55 _ => panic!("unexpected kind in crate: {:?}", kind),
61 // Return the cargo subcommand for this test kind
62 fn subcommand(self) -> &'static str {
64 TestKind::Test => "test",
65 TestKind::Bench => "bench",
70 impl fmt::Display for TestKind {
71 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
72 f.write_str(match *self {
73 TestKind::Test => "Testing",
74 TestKind::Bench => "Benchmarking",
79 fn try_run(builder: &Builder, cmd: &mut Command) -> bool {
80 if !builder.fail_fast {
81 if !builder.try_run(cmd) {
82 let mut failures = builder.delayed_failures.borrow_mut();
83 failures.push(format!("{:?}", cmd));
92 fn try_run_quiet(builder: &Builder, cmd: &mut Command) -> bool {
93 if !builder.fail_fast {
94 if !builder.try_run_quiet(cmd) {
95 let mut failures = builder.delayed_failures.borrow_mut();
96 failures.push(format!("{:?}", cmd));
100 builder.run_quiet(cmd);
105 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
106 pub struct Linkcheck {
107 host: Interned<String>,
110 impl Step for Linkcheck {
112 const ONLY_HOSTS: bool = true;
113 const DEFAULT: bool = true;
115 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
117 /// This tool in `src/tools` will verify the validity of all our links in the
118 /// documentation to ensure we don't have a bunch of dead ones.
119 fn run(self, builder: &Builder) {
120 let host = self.host;
122 builder.info(&format!("Linkcheck ({})", host));
124 builder.default_doc(None);
126 let _time = util::timeit(&builder);
130 .tool_cmd(Tool::Linkchecker)
131 .arg(builder.out.join(host).join("doc")),
135 fn should_run(run: ShouldRun) -> ShouldRun {
136 let builder = run.builder;
137 run.path("src/tools/linkchecker")
138 .default_condition(builder.config.docs)
141 fn make_run(run: RunConfig) {
142 run.builder.ensure(Linkcheck { host: run.target });
146 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
147 pub struct Cargotest {
149 host: Interned<String>,
152 impl Step for Cargotest {
154 const ONLY_HOSTS: bool = true;
156 fn should_run(run: ShouldRun) -> ShouldRun {
157 run.path("src/tools/cargotest")
160 fn make_run(run: RunConfig) {
161 run.builder.ensure(Cargotest {
162 stage: run.builder.top_stage,
167 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
169 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
170 /// test` to ensure that we don't regress the test suites there.
171 fn run(self, builder: &Builder) {
172 let compiler = builder.compiler(self.stage, self.host);
173 builder.ensure(compile::Rustc {
175 target: compiler.host,
178 // Note that this is a short, cryptic, and not scoped directory name. This
179 // is currently to minimize the length of path on Windows where we otherwise
180 // quickly run into path name limit constraints.
181 let out_dir = builder.out.join("ct");
182 t!(fs::create_dir_all(&out_dir));
184 let _time = util::timeit(&builder);
185 let mut cmd = builder.tool_cmd(Tool::CargoTest);
188 cmd.arg(&builder.initial_cargo)
190 .env("RUSTC", builder.rustc(compiler))
191 .env("RUSTDOC", builder.rustdoc(compiler.host)),
196 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
199 host: Interned<String>,
202 impl Step for Cargo {
204 const ONLY_HOSTS: bool = true;
206 fn should_run(run: ShouldRun) -> ShouldRun {
207 run.path("src/tools/cargo")
210 fn make_run(run: RunConfig) {
211 run.builder.ensure(Cargo {
212 stage: run.builder.top_stage,
217 /// Runs `cargo test` for `cargo` packaged with Rust.
218 fn run(self, builder: &Builder) {
219 let compiler = builder.compiler(self.stage, self.host);
221 builder.ensure(tool::Cargo {
225 let mut cargo = tool::prepare_tool_cargo(builder,
231 SourceType::Submodule,
234 if !builder.fail_fast {
235 cargo.arg("--no-fail-fast");
238 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
240 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
241 // Disable a test that has issues with mingw.
242 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
246 cargo.env("PATH", &path_for_cargo(builder, compiler)),
251 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
254 host: Interned<String>,
259 const ONLY_HOSTS: bool = true;
261 fn should_run(run: ShouldRun) -> ShouldRun {
262 run.path("src/tools/rls")
265 fn make_run(run: RunConfig) {
266 run.builder.ensure(Rls {
267 stage: run.builder.top_stage,
272 /// Runs `cargo test` for the rls.
273 fn run(self, builder: &Builder) {
274 let stage = self.stage;
275 let host = self.host;
276 let compiler = builder.compiler(stage, host);
278 let build_result = builder.ensure(tool::Rls {
281 extra_features: Vec::new(),
283 if build_result.is_none() {
284 eprintln!("failed to test rls: could not build");
288 let mut cargo = tool::prepare_tool_cargo(builder,
294 SourceType::Submodule,
297 // Copy `src/tools/rls/test_data` to a writable drive.
298 let test_workspace_path = builder.out.join("rls-test-data");
299 let test_data_path = test_workspace_path.join("test_data");
300 builder.create_dir(&test_data_path);
301 builder.cp_r(&builder.src.join("src/tools/rls/test_data"), &test_data_path);
302 cargo.env("RLS_TEST_WORKSPACE_DIR", test_workspace_path);
304 builder.add_rustc_lib_path(compiler, &mut cargo);
306 .args(builder.config.cmd.test_args());
308 if try_run(builder, &mut cargo) {
309 builder.save_toolstate("rls", ToolState::TestPass);
314 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
317 host: Interned<String>,
320 impl Step for Rustfmt {
322 const ONLY_HOSTS: bool = true;
324 fn should_run(run: ShouldRun) -> ShouldRun {
325 run.path("src/tools/rustfmt")
328 fn make_run(run: RunConfig) {
329 run.builder.ensure(Rustfmt {
330 stage: run.builder.top_stage,
335 /// Runs `cargo test` for rustfmt.
336 fn run(self, builder: &Builder) {
337 let stage = self.stage;
338 let host = self.host;
339 let compiler = builder.compiler(stage, host);
341 let build_result = builder.ensure(tool::Rustfmt {
344 extra_features: Vec::new(),
346 if build_result.is_none() {
347 eprintln!("failed to test rustfmt: could not build");
351 let mut cargo = tool::prepare_tool_cargo(builder,
357 SourceType::Submodule,
360 let dir = testdir(builder, compiler.host);
361 t!(fs::create_dir_all(&dir));
362 cargo.env("RUSTFMT_TEST_DIR", dir);
364 builder.add_rustc_lib_path(compiler, &mut cargo);
366 if try_run(builder, &mut cargo) {
367 builder.save_toolstate("rustfmt", ToolState::TestPass);
372 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
375 host: Interned<String>,
380 const ONLY_HOSTS: bool = true;
381 const DEFAULT: bool = true;
383 fn should_run(run: ShouldRun) -> ShouldRun {
384 let test_miri = run.builder.config.test_miri;
385 run.path("src/tools/miri").default_condition(test_miri)
388 fn make_run(run: RunConfig) {
389 run.builder.ensure(Miri {
390 stage: run.builder.top_stage,
395 /// Runs `cargo test` for miri.
396 fn run(self, builder: &Builder) {
397 let stage = self.stage;
398 let host = self.host;
399 let compiler = builder.compiler(stage, host);
401 let miri = builder.ensure(tool::Miri {
404 extra_features: Vec::new(),
406 if let Some(miri) = miri {
407 let mut cargo = tool::prepare_tool_cargo(builder,
413 SourceType::Submodule,
416 // miri tests need to know about the stage sysroot
417 cargo.env("MIRI_SYSROOT", builder.sysroot(compiler));
418 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
419 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
420 cargo.env("MIRI_PATH", miri);
422 builder.add_rustc_lib_path(compiler, &mut cargo);
424 if try_run(builder, &mut cargo) {
425 builder.save_toolstate("miri", ToolState::TestPass);
428 eprintln!("failed to test miri: could not build");
433 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
436 host: Interned<String>,
439 impl Step for Clippy {
441 const ONLY_HOSTS: bool = true;
442 const DEFAULT: bool = false;
444 fn should_run(run: ShouldRun) -> ShouldRun {
445 run.path("src/tools/clippy")
448 fn make_run(run: RunConfig) {
449 run.builder.ensure(Clippy {
450 stage: run.builder.top_stage,
455 /// Runs `cargo test` for clippy.
456 fn run(self, builder: &Builder) {
457 let stage = self.stage;
458 let host = self.host;
459 let compiler = builder.compiler(stage, host);
461 let clippy = builder.ensure(tool::Clippy {
464 extra_features: Vec::new(),
466 if let Some(clippy) = clippy {
467 let mut cargo = tool::prepare_tool_cargo(builder,
473 SourceType::Submodule,
476 // clippy tests need to know about the stage sysroot
477 cargo.env("SYSROOT", builder.sysroot(compiler));
478 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
479 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
480 let host_libs = builder
481 .stage_out(compiler, Mode::ToolRustc)
482 .join(builder.cargo_dir());
483 cargo.env("HOST_LIBS", host_libs);
484 // clippy tests need to find the driver
485 cargo.env("CLIPPY_DRIVER_PATH", clippy);
487 builder.add_rustc_lib_path(compiler, &mut cargo);
489 if try_run(builder, &mut cargo) {
490 builder.save_toolstate("clippy-driver", ToolState::TestPass);
493 eprintln!("failed to test clippy: could not build");
498 fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString {
499 // Configure PATH to find the right rustc. NB. we have to use PATH
500 // and not RUSTC because the Cargo test suite has tests that will
501 // fail if rustc is not spelled `rustc`.
502 let path = builder.sysroot(compiler).join("bin");
503 let old_path = env::var_os("PATH").unwrap_or_default();
504 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
507 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
508 pub struct RustdocTheme {
509 pub compiler: Compiler,
512 impl Step for RustdocTheme {
514 const DEFAULT: bool = true;
515 const ONLY_HOSTS: bool = true;
517 fn should_run(run: ShouldRun) -> ShouldRun {
518 run.path("src/tools/rustdoc-themes")
521 fn make_run(run: RunConfig) {
522 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
524 run.builder.ensure(RustdocTheme { compiler });
527 fn run(self, builder: &Builder) {
528 let rustdoc = builder.out.join("bootstrap/debug/rustdoc");
529 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
530 cmd.arg(rustdoc.to_str().unwrap())
534 .join("src/librustdoc/html/static/themes")
538 .env("RUSTC_STAGE", self.compiler.stage.to_string())
539 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
542 builder.sysroot_libdir(self.compiler, self.compiler.host),
544 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
545 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler.host))
546 .env("RUSTDOC_CRATE_VERSION", builder.rust_version())
547 .env("RUSTC_BOOTSTRAP", "1");
548 if let Some(linker) = builder.linker(self.compiler.host) {
549 cmd.env("RUSTC_TARGET_LINKER", linker);
551 try_run(builder, &mut cmd);
555 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
556 pub struct RustdocJS {
557 pub host: Interned<String>,
558 pub target: Interned<String>,
561 impl Step for RustdocJS {
563 const DEFAULT: bool = true;
564 const ONLY_HOSTS: bool = true;
566 fn should_run(run: ShouldRun) -> ShouldRun {
567 run.path("src/test/rustdoc-js")
570 fn make_run(run: RunConfig) {
571 run.builder.ensure(RustdocJS {
577 fn run(self, builder: &Builder) {
578 if let Some(ref nodejs) = builder.config.nodejs {
579 let mut command = Command::new(nodejs);
580 command.args(&["src/tools/rustdoc-js/tester.js", &*self.host]);
581 builder.ensure(::doc::Std {
583 stage: builder.top_stage,
585 builder.run(&mut command);
588 "No nodejs found, skipping \"src/test/rustdoc-js\" tests"
594 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
595 pub struct RustdocUi {
596 pub host: Interned<String>,
597 pub target: Interned<String>,
598 pub compiler: Compiler,
601 impl Step for RustdocUi {
603 const DEFAULT: bool = true;
604 const ONLY_HOSTS: bool = true;
606 fn should_run(run: ShouldRun) -> ShouldRun {
607 run.path("src/test/rustdoc-ui")
610 fn make_run(run: RunConfig) {
611 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
612 run.builder.ensure(RustdocUi {
619 fn run(self, builder: &Builder) {
620 builder.ensure(Compiletest {
621 compiler: self.compiler,
631 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
636 const DEFAULT: bool = true;
637 const ONLY_HOSTS: bool = true;
639 /// Runs the `tidy` tool.
641 /// This tool in `src/tools` checks up on various bits and pieces of style and
642 /// otherwise just implements a few lint-like checks that are specific to the
644 fn run(self, builder: &Builder) {
645 let mut cmd = builder.tool_cmd(Tool::Tidy);
646 cmd.arg(builder.src.join("src"));
647 cmd.arg(&builder.initial_cargo);
648 if !builder.config.vendor {
649 cmd.arg("--no-vendor");
651 if !builder.config.verbose_tests {
655 let _folder = builder.fold_output(|| "tidy");
656 builder.info("tidy check");
657 try_run(builder, &mut cmd);
660 fn should_run(run: ShouldRun) -> ShouldRun {
661 run.path("src/tools/tidy")
664 fn make_run(run: RunConfig) {
665 run.builder.ensure(Tidy);
669 fn testdir(builder: &Builder, host: Interned<String>) -> PathBuf {
670 builder.out.join(host).join("test")
673 macro_rules! default_test {
674 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
675 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
679 macro_rules! default_test_with_compare_mode {
680 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
681 compare_mode: $compare_mode:expr }) => {
682 test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
683 host: false, compare_mode: $compare_mode });
687 macro_rules! host_test {
688 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
689 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
694 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
695 host: $host:expr }) => {
696 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
697 host: $host, compare_mode: None });
701 macro_rules! test_with_compare_mode {
702 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
703 host: $host:expr, compare_mode: $compare_mode:expr }) => {
704 test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
705 host: $host, compare_mode: Some($compare_mode) });
709 macro_rules! test_definitions {
714 default: $default:expr,
716 compare_mode: $compare_mode:expr
718 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
720 pub compiler: Compiler,
721 pub target: Interned<String>,
724 impl Step for $name {
726 const DEFAULT: bool = $default;
727 const ONLY_HOSTS: bool = $host;
729 fn should_run(run: ShouldRun) -> ShouldRun {
730 run.suite_path($path)
733 fn make_run(run: RunConfig) {
734 let compiler = run.builder.compiler(run.builder.top_stage, run.host);
736 run.builder.ensure($name {
742 fn run(self, builder: &Builder) {
743 builder.ensure(Compiletest {
744 compiler: self.compiler,
749 compare_mode: $compare_mode,
756 default_test_with_compare_mode!(Ui {
763 default_test_with_compare_mode!(RunPass {
764 path: "src/test/run-pass",
770 default_test!(CompileFail {
771 path: "src/test/compile-fail",
772 mode: "compile-fail",
773 suite: "compile-fail"
776 default_test!(RunFail {
777 path: "src/test/run-fail",
782 default_test!(RunPassValgrind {
783 path: "src/test/run-pass-valgrind",
784 mode: "run-pass-valgrind",
785 suite: "run-pass-valgrind"
788 default_test!(MirOpt {
789 path: "src/test/mir-opt",
794 default_test!(Codegen {
795 path: "src/test/codegen",
800 default_test!(CodegenUnits {
801 path: "src/test/codegen-units",
802 mode: "codegen-units",
803 suite: "codegen-units"
806 default_test!(Incremental {
807 path: "src/test/incremental",
812 default_test!(Debuginfo {
813 path: "src/test/debuginfo",
818 host_test!(UiFullDeps {
819 path: "src/test/ui-fulldeps",
824 host_test!(RunPassFullDeps {
825 path: "src/test/run-pass-fulldeps",
827 suite: "run-pass-fulldeps"
830 host_test!(RunFailFullDeps {
831 path: "src/test/run-fail-fulldeps",
833 suite: "run-fail-fulldeps"
836 host_test!(CompileFailFullDeps {
837 path: "src/test/compile-fail-fulldeps",
838 mode: "compile-fail",
839 suite: "compile-fail-fulldeps"
842 host_test!(IncrementalFullDeps {
843 path: "src/test/incremental-fulldeps",
845 suite: "incremental-fulldeps"
849 path: "src/test/rustdoc",
855 path: "src/test/pretty",
861 test!(RunPassPretty {
862 path: "src/test/run-pass/pretty",
868 test!(RunFailPretty {
869 path: "src/test/run-fail/pretty",
875 test!(RunPassValgrindPretty {
876 path: "src/test/run-pass-valgrind/pretty",
878 suite: "run-pass-valgrind",
882 test!(RunPassFullDepsPretty {
883 path: "src/test/run-pass-fulldeps/pretty",
885 suite: "run-pass-fulldeps",
889 test!(RunFailFullDepsPretty {
890 path: "src/test/run-fail-fulldeps/pretty",
892 suite: "run-fail-fulldeps",
897 default_test!(RunMake {
898 path: "src/test/run-make",
903 host_test!(RunMakeFullDeps {
904 path: "src/test/run-make-fulldeps",
906 suite: "run-make-fulldeps"
909 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
912 target: Interned<String>,
915 path: Option<&'static str>,
916 compare_mode: Option<&'static str>,
919 impl Step for Compiletest {
922 fn should_run(run: ShouldRun) -> ShouldRun {
926 /// Executes the `compiletest` tool to run a suite of tests.
928 /// Compiles all tests with `compiler` for `target` with the specified
929 /// compiletest `mode` and `suite` arguments. For example `mode` can be
930 /// "run-pass" or `suite` can be something like `debuginfo`.
931 fn run(self, builder: &Builder) {
932 let compiler = self.compiler;
933 let target = self.target;
934 let mode = self.mode;
935 let suite = self.suite;
937 // Path for test suite
938 let suite_path = self.path.unwrap_or("");
940 // Skip codegen tests if they aren't enabled in configuration.
941 if !builder.config.codegen_tests && suite == "codegen" {
945 if suite == "debuginfo" {
946 // Skip debuginfo tests on MSVC
947 if builder.config.build.contains("msvc") {
951 if mode == "debuginfo" {
952 return builder.ensure(Compiletest {
953 mode: "debuginfo-both",
958 builder.ensure(dist::DebuggerScripts {
959 sysroot: builder.sysroot(compiler),
964 if suite.ends_with("fulldeps") ||
965 // FIXME: Does pretty need librustc compiled? Note that there are
966 // fulldeps test suites with mode = pretty as well.
969 builder.ensure(compile::Rustc { compiler, target });
972 if builder.no_std(target) == Some(true) {
973 // the `test` doesn't compile for no-std targets
974 builder.ensure(compile::Std { compiler, target });
976 builder.ensure(compile::Test { compiler, target });
979 if builder.no_std(target) == Some(true) {
980 // for no_std run-make (e.g. thumb*),
981 // we need a host compiler which is called by cargo.
982 builder.ensure(compile::Std { compiler, target: compiler.host });
985 builder.ensure(native::TestHelpers { target });
986 builder.ensure(RemoteCopyLibs { compiler, target });
988 let mut cmd = builder.tool_cmd(Tool::Compiletest);
990 // compiletest currently has... a lot of arguments, so let's just pass all
993 cmd.arg("--compile-lib-path")
994 .arg(builder.rustc_libdir(compiler));
995 cmd.arg("--run-lib-path")
996 .arg(builder.sysroot_libdir(compiler, target));
997 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
999 let is_rustdoc_ui = suite.ends_with("rustdoc-ui");
1001 // Avoid depending on rustdoc when we don't need it.
1002 if mode == "rustdoc"
1003 || (mode == "run-make" && suite.ends_with("fulldeps"))
1004 || (mode == "ui" && is_rustdoc_ui)
1006 cmd.arg("--rustdoc-path")
1007 .arg(builder.rustdoc(compiler.host));
1010 cmd.arg("--src-base")
1011 .arg(builder.src.join("src/test").join(suite));
1012 cmd.arg("--build-base")
1013 .arg(testdir(builder, compiler.host).join(suite));
1014 cmd.arg("--stage-id")
1015 .arg(format!("stage{}-{}", compiler.stage, target));
1016 cmd.arg("--mode").arg(mode);
1017 cmd.arg("--target").arg(target);
1018 cmd.arg("--host").arg(&*compiler.host);
1019 cmd.arg("--llvm-filecheck")
1020 .arg(builder.llvm_filecheck(builder.config.build));
1022 if builder.config.cmd.bless() {
1026 let compare_mode = builder.config.cmd.compare_mode().or(self.compare_mode);
1028 if let Some(ref nodejs) = builder.config.nodejs {
1029 cmd.arg("--nodejs").arg(nodejs);
1032 let mut flags = if is_rustdoc_ui {
1035 vec!["-Crpath".to_string()]
1038 if builder.config.rust_optimize_tests {
1039 flags.push("-O".to_string());
1041 if builder.config.rust_debuginfo_tests {
1042 flags.push("-g".to_string());
1045 flags.push("-Zunstable-options".to_string());
1046 flags.push(builder.config.cmd.rustc_args().join(" "));
1048 if let Some(linker) = builder.linker(target) {
1049 cmd.arg("--linker").arg(linker);
1052 let hostflags = flags.clone();
1053 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1055 let mut targetflags = flags;
1056 targetflags.push(format!(
1058 builder.test_helpers_out(target).display()
1060 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1062 cmd.arg("--docck-python").arg(builder.python());
1064 if builder.config.build.ends_with("apple-darwin") {
1065 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
1066 // LLDB plugin's compiled module which only works with the system python
1067 // (namely not Homebrew-installed python)
1068 cmd.arg("--lldb-python").arg("/usr/bin/python");
1070 cmd.arg("--lldb-python").arg(builder.python());
1073 if let Some(ref gdb) = builder.config.gdb {
1074 cmd.arg("--gdb").arg(gdb);
1077 let run = |cmd: &mut Command| {
1078 cmd.output().map(|output| {
1079 String::from_utf8_lossy(&output.stdout)
1080 .lines().next().unwrap_or_else(|| {
1081 panic!("{:?} failed {:?}", cmd, output)
1085 let lldb_exe = if builder.config.lldb_enabled && !target.contains("emscripten") {
1086 // Test against the lldb that was just built.
1087 builder.llvm_out(target)
1091 PathBuf::from("lldb")
1093 let lldb_version = Command::new(&lldb_exe)
1096 .map(|output| { String::from_utf8_lossy(&output.stdout).to_string() })
1098 if let Some(ref vers) = lldb_version {
1099 cmd.arg("--lldb-version").arg(vers);
1100 let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1101 if let Some(ref dir) = lldb_python_dir {
1102 cmd.arg("--lldb-python-dir").arg(dir);
1106 // Get paths from cmd args
1107 let paths = match &builder.config.cmd {
1108 Subcommand::Test { ref paths, .. } => &paths[..],
1112 // Get test-args by striping suite path
1113 let mut test_args: Vec<&str> = paths
1116 match p.strip_prefix(".") {
1121 .filter(|p| p.starts_with(suite_path) && p.is_file())
1122 .map(|p| p.strip_prefix(suite_path).unwrap().to_str().unwrap())
1125 test_args.append(&mut builder.config.cmd.test_args());
1127 cmd.args(&test_args);
1129 if builder.is_verbose() {
1130 cmd.arg("--verbose");
1133 if !builder.config.verbose_tests {
1137 if builder.config.llvm_enabled {
1138 let llvm_config = builder.ensure(native::Llvm {
1139 target: builder.config.build,
1142 if !builder.config.dry_run {
1143 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1144 cmd.arg("--llvm-version").arg(llvm_version);
1146 if !builder.is_rust_llvm(target) {
1147 cmd.arg("--system-llvm");
1150 // Only pass correct values for these flags for the `run-make` suite as it
1151 // requires that a C++ compiler was configured which isn't always the case.
1152 if !builder.config.dry_run && suite == "run-make-fulldeps" {
1153 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1154 let llvm_cxxflags = output(Command::new(&llvm_config).arg("--cxxflags"));
1156 .arg(builder.cc(target))
1158 .arg(builder.cxx(target).unwrap())
1160 .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
1161 .arg("--llvm-components")
1162 .arg(llvm_components.trim())
1163 .arg("--llvm-cxxflags")
1164 .arg(llvm_cxxflags.trim());
1165 if let Some(ar) = builder.ar(target) {
1166 cmd.arg("--ar").arg(ar);
1170 if suite == "run-make-fulldeps" && !builder.config.llvm_enabled {
1172 "Ignoring run-make test suite as they generally don't work without LLVM"
1177 if suite != "run-make-fulldeps" {
1184 .arg("--llvm-components")
1186 .arg("--llvm-cxxflags")
1190 if builder.remote_tested(target) {
1191 cmd.arg("--remote-test-client")
1192 .arg(builder.tool_exe(Tool::RemoteTestClient));
1195 // Running a C compiler on MSVC requires a few env vars to be set, to be
1196 // sure to set them here.
1198 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1199 // rather than stomp over it.
1200 if target.contains("msvc") {
1201 for &(ref k, ref v) in builder.cc[&target].env() {
1207 cmd.env("RUSTC_BOOTSTRAP", "1");
1208 builder.add_rust_test_threads(&mut cmd);
1210 if builder.config.sanitizers {
1211 cmd.env("SANITIZER_SUPPORT", "1");
1214 if builder.config.profiler {
1215 cmd.env("PROFILER_SUPPORT", "1");
1218 cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
1220 cmd.arg("--adb-path").arg("adb");
1221 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1222 if target.contains("android") {
1223 // Assume that cc for this target comes from the android sysroot
1224 cmd.arg("--android-cross-path")
1225 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1227 cmd.arg("--android-cross-path").arg("");
1230 builder.ci_env.force_coloring_in_ci(&mut cmd);
1232 let _folder = builder.fold_output(|| format!("test_{}", suite));
1233 builder.info(&format!(
1234 "Check compiletest suite={} mode={} ({} -> {})",
1235 suite, mode, &compiler.host, target
1237 let _time = util::timeit(&builder);
1238 try_run(builder, &mut cmd);
1240 if let Some(compare_mode) = compare_mode {
1241 cmd.arg("--compare-mode").arg(compare_mode);
1242 let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
1243 builder.info(&format!(
1244 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1245 suite, mode, compare_mode, &compiler.host, target
1247 let _time = util::timeit(&builder);
1248 try_run(builder, &mut cmd);
1253 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1261 impl Step for DocTest {
1263 const ONLY_HOSTS: bool = true;
1265 fn should_run(run: ShouldRun) -> ShouldRun {
1269 /// Run `rustdoc --test` for all documentation in `src/doc`.
1271 /// This will run all tests in our markdown documentation (e.g. the book)
1272 /// located in `src/doc`. The `rustdoc` that's run is the one that sits next to
1274 fn run(self, builder: &Builder) {
1275 let compiler = self.compiler;
1277 builder.ensure(compile::Test {
1279 target: compiler.host,
1282 // Do a breadth-first traversal of the `src/doc` directory and just run
1283 // tests for all files that end in `*.md`
1284 let mut stack = vec![builder.src.join(self.path)];
1285 let _time = util::timeit(&builder);
1286 let _folder = builder.fold_output(|| format!("test_{}", self.name));
1288 let mut files = Vec::new();
1289 while let Some(p) = stack.pop() {
1291 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1295 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1299 // The nostarch directory in the book is for no starch, and so isn't
1300 // guaranteed to builder. We don't care if it doesn't build, so skip it.
1301 if p.to_str().map_or(false, |p| p.contains("nostarch")) {
1310 let mut toolstate = ToolState::TestPass;
1312 if !markdown_test(builder, compiler, &file) {
1313 toolstate = ToolState::TestFail;
1316 if self.is_ext_doc {
1317 builder.save_toolstate(self.name, toolstate);
1322 macro_rules! test_book {
1323 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1325 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1330 impl Step for $name {
1332 const DEFAULT: bool = $default;
1333 const ONLY_HOSTS: bool = true;
1335 fn should_run(run: ShouldRun) -> ShouldRun {
1339 fn make_run(run: RunConfig) {
1340 run.builder.ensure($name {
1341 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1345 fn run(self, builder: &Builder) {
1346 builder.ensure(DocTest {
1347 compiler: self.compiler,
1350 is_ext_doc: !$default,
1359 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1360 Reference, "src/doc/reference", "reference", default=false;
1361 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1362 RustcBook, "src/doc/rustc", "rustc", default=true;
1363 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1364 TheBook, "src/doc/book", "book", default=false;
1365 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1368 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1369 pub struct ErrorIndex {
1373 impl Step for ErrorIndex {
1375 const DEFAULT: bool = true;
1376 const ONLY_HOSTS: bool = true;
1378 fn should_run(run: ShouldRun) -> ShouldRun {
1379 run.path("src/tools/error_index_generator")
1382 fn make_run(run: RunConfig) {
1383 run.builder.ensure(ErrorIndex {
1384 compiler: run.builder.compiler(run.builder.top_stage, run.host),
1388 /// Run the error index generator tool to execute the tests located in the error
1391 /// The `error_index_generator` tool lives in `src/tools` and is used to
1392 /// generate a markdown file from the error indexes of the code base which is
1393 /// then passed to `rustdoc --test`.
1394 fn run(self, builder: &Builder) {
1395 let compiler = self.compiler;
1397 builder.ensure(compile::Std {
1399 target: compiler.host,
1402 let dir = testdir(builder, compiler.host);
1403 t!(fs::create_dir_all(&dir));
1404 let output = dir.join("error-index.md");
1406 let mut tool = builder.tool_cmd(Tool::ErrorIndex);
1407 tool.arg("markdown")
1409 .env("CFG_BUILD", &builder.config.build)
1410 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
1412 let _folder = builder.fold_output(|| "test_error_index");
1413 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1414 let _time = util::timeit(&builder);
1415 builder.run(&mut tool);
1416 markdown_test(builder, compiler, &output);
1420 fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) -> bool {
1421 match File::open(markdown) {
1423 let mut contents = String::new();
1424 t!(file.read_to_string(&mut contents));
1425 if !contents.contains("```") {
1432 builder.info(&format!("doc tests for: {}", markdown.display()));
1433 let mut cmd = builder.rustdoc_cmd(compiler.host);
1434 builder.add_rust_test_threads(&mut cmd);
1437 cmd.env("RUSTC_BOOTSTRAP", "1");
1439 let test_args = builder.config.cmd.test_args().join(" ");
1440 cmd.arg("--test-args").arg(test_args);
1442 if builder.config.verbose_tests {
1443 try_run(builder, &mut cmd)
1445 try_run_quiet(builder, &mut cmd)
1449 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1450 pub struct CrateLibrustc {
1452 target: Interned<String>,
1453 test_kind: TestKind,
1454 krate: Interned<String>,
1457 impl Step for CrateLibrustc {
1459 const DEFAULT: bool = true;
1460 const ONLY_HOSTS: bool = true;
1462 fn should_run(run: ShouldRun) -> ShouldRun {
1463 run.krate("rustc-main")
1466 fn make_run(run: RunConfig) {
1467 let builder = run.builder;
1468 let compiler = builder.compiler(builder.top_stage, run.host);
1470 for krate in builder.in_tree_crates("rustc-main") {
1471 if run.path.ends_with(&krate.path) {
1472 let test_kind = builder.kind.into();
1474 builder.ensure(CrateLibrustc {
1484 fn run(self, builder: &Builder) {
1485 builder.ensure(Crate {
1486 compiler: self.compiler,
1487 target: self.target,
1489 test_kind: self.test_kind,
1495 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1496 pub struct CrateNotDefault {
1498 target: Interned<String>,
1499 test_kind: TestKind,
1500 krate: &'static str,
1503 impl Step for CrateNotDefault {
1506 fn should_run(run: ShouldRun) -> ShouldRun {
1507 run.path("src/librustc_asan")
1508 .path("src/librustc_lsan")
1509 .path("src/librustc_msan")
1510 .path("src/librustc_tsan")
1513 fn make_run(run: RunConfig) {
1514 let builder = run.builder;
1515 let compiler = builder.compiler(builder.top_stage, run.host);
1517 let test_kind = builder.kind.into();
1519 builder.ensure(CrateNotDefault {
1523 krate: match run.path {
1524 _ if run.path.ends_with("src/librustc_asan") => "rustc_asan",
1525 _ if run.path.ends_with("src/librustc_lsan") => "rustc_lsan",
1526 _ if run.path.ends_with("src/librustc_msan") => "rustc_msan",
1527 _ if run.path.ends_with("src/librustc_tsan") => "rustc_tsan",
1528 _ => panic!("unexpected path {:?}", run.path),
1533 fn run(self, builder: &Builder) {
1534 builder.ensure(Crate {
1535 compiler: self.compiler,
1536 target: self.target,
1538 test_kind: self.test_kind,
1539 krate: INTERNER.intern_str(self.krate),
1544 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1546 pub compiler: Compiler,
1547 pub target: Interned<String>,
1549 pub test_kind: TestKind,
1550 pub krate: Interned<String>,
1553 impl Step for Crate {
1555 const DEFAULT: bool = true;
1557 fn should_run(mut run: ShouldRun) -> ShouldRun {
1558 let builder = run.builder;
1559 run = run.krate("test");
1560 for krate in run.builder.in_tree_crates("std") {
1561 if krate.is_local(&run.builder)
1562 && !(krate.name.starts_with("rustc_") && krate.name.ends_with("san"))
1563 && krate.name != "dlmalloc"
1565 run = run.path(krate.local_path(&builder).to_str().unwrap());
1571 fn make_run(run: RunConfig) {
1572 let builder = run.builder;
1573 let compiler = builder.compiler(builder.top_stage, run.host);
1575 let make = |mode: Mode, krate: &CargoCrate| {
1576 let test_kind = builder.kind.into();
1578 builder.ensure(Crate {
1587 for krate in builder.in_tree_crates("std") {
1588 if run.path.ends_with(&krate.local_path(&builder)) {
1589 make(Mode::Std, krate);
1592 for krate in builder.in_tree_crates("test") {
1593 if run.path.ends_with(&krate.local_path(&builder)) {
1594 make(Mode::Test, krate);
1599 /// Run all unit tests plus documentation tests for a given crate defined
1600 /// by a `Cargo.toml` (single manifest)
1602 /// This is what runs tests for crates like the standard library, compiler, etc.
1603 /// It essentially is the driver for running `cargo test`.
1605 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1606 /// arguments, and those arguments are discovered from `cargo metadata`.
1607 fn run(self, builder: &Builder) {
1608 let compiler = self.compiler;
1609 let target = self.target;
1610 let mode = self.mode;
1611 let test_kind = self.test_kind;
1612 let krate = self.krate;
1614 builder.ensure(compile::Test { compiler, target });
1615 builder.ensure(RemoteCopyLibs { compiler, target });
1617 // If we're not doing a full bootstrap but we're testing a stage2 version of
1618 // libstd, then what we're actually testing is the libstd produced in
1619 // stage1. Reflect that here by updating the compiler that we're working
1620 // with automatically.
1621 let compiler = if builder.force_use_stage1(compiler, target) {
1622 builder.compiler(1, compiler.host)
1627 let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand());
1630 compile::std_cargo(builder, &compiler, target, &mut cargo);
1633 compile::test_cargo(builder, &compiler, target, &mut cargo);
1636 builder.ensure(compile::Rustc { compiler, target });
1637 compile::rustc_cargo(builder, &mut cargo);
1639 _ => panic!("can only test libraries"),
1642 // Build up the base `cargo test` command.
1644 // Pass in some standard flags then iterate over the graph we've discovered
1645 // in `cargo metadata` with the maps above and figure out what `-p`
1646 // arguments need to get passed.
1647 if test_kind.subcommand() == "test" && !builder.fail_fast {
1648 cargo.arg("--no-fail-fast");
1650 match builder.doc_tests {
1655 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1660 cargo.arg("-p").arg(krate);
1662 // The tests are going to run with the *target* libraries, so we need to
1663 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1665 // Note that to run the compiler we need to run with the *host* libraries,
1666 // but our wrapper scripts arrange for that to be the case anyway.
1667 let mut dylib_path = dylib_path();
1668 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1669 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1672 cargo.args(&builder.config.cmd.test_args());
1674 if !builder.config.verbose_tests {
1675 cargo.arg("--quiet");
1678 if target.contains("emscripten") {
1680 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1685 .expect("nodejs not configured"),
1687 } else if target.starts_with("wasm32") {
1688 // Warn about running tests without the `wasm_syscall` feature enabled.
1689 // The javascript shim implements the syscall interface so that test
1690 // output can be correctly reported.
1691 if !builder.config.wasm_syscall {
1693 "Libstd was built without `wasm_syscall` feature enabled: \
1694 test output may not be visible."
1698 // On the wasm32-unknown-unknown target we're using LTO which is
1699 // incompatible with `-C prefer-dynamic`, so disable that here
1700 cargo.env("RUSTC_NO_PREFER_DYNAMIC", "1");
1706 .expect("nodejs not configured");
1707 let runner = format!(
1708 "{} {}/src/etc/wasm32-shim.js",
1710 builder.src.display()
1712 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target)), &runner);
1713 } else if builder.remote_tested(target) {
1715 format!("CARGO_TARGET_{}_RUNNER", envify(&target)),
1716 format!("{} run", builder.tool_exe(Tool::RemoteTestClient).display()),
1720 let _folder = builder.fold_output(|| {
1723 test_kind.subcommand(),
1728 builder.info(&format!(
1729 "{} {} stage{} ({} -> {})",
1730 test_kind, krate, compiler.stage, &compiler.host, target
1732 let _time = util::timeit(&builder);
1733 try_run(builder, &mut cargo);
1737 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1738 pub struct CrateRustdoc {
1739 host: Interned<String>,
1740 test_kind: TestKind,
1743 impl Step for CrateRustdoc {
1745 const DEFAULT: bool = true;
1746 const ONLY_HOSTS: bool = true;
1748 fn should_run(run: ShouldRun) -> ShouldRun {
1749 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1752 fn make_run(run: RunConfig) {
1753 let builder = run.builder;
1755 let test_kind = builder.kind.into();
1757 builder.ensure(CrateRustdoc {
1763 fn run(self, builder: &Builder) {
1764 let test_kind = self.test_kind;
1766 let compiler = builder.compiler(builder.top_stage, self.host);
1767 let target = compiler.host;
1768 builder.ensure(compile::Rustc { compiler, target });
1770 let mut cargo = tool::prepare_tool_cargo(builder,
1774 test_kind.subcommand(),
1775 "src/tools/rustdoc",
1778 if test_kind.subcommand() == "test" && !builder.fail_fast {
1779 cargo.arg("--no-fail-fast");
1782 cargo.arg("-p").arg("rustdoc:0.0.0");
1785 cargo.args(&builder.config.cmd.test_args());
1787 if !builder.config.verbose_tests {
1788 cargo.arg("--quiet");
1791 let _folder = builder
1792 .fold_output(|| format!("{}_stage{}-rustdoc", test_kind.subcommand(), compiler.stage));
1793 builder.info(&format!(
1794 "{} rustdoc stage{} ({} -> {})",
1795 test_kind, compiler.stage, &compiler.host, target
1797 let _time = util::timeit(&builder);
1799 try_run(builder, &mut cargo);
1803 fn envify(s: &str) -> String {
1809 .flat_map(|c| c.to_uppercase())
1813 /// Some test suites are run inside emulators or on remote devices, and most
1814 /// of our test binaries are linked dynamically which means we need to ship
1815 /// the standard library and such to the emulator ahead of time. This step
1816 /// represents this and is a dependency of all test suites.
1818 /// Most of the time this is a noop. For some steps such as shipping data to
1819 /// QEMU we have to build our own tools so we've got conditional dependencies
1820 /// on those programs as well. Note that the remote test client is built for
1821 /// the build target (us) and the server is built for the target.
1822 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1823 pub struct RemoteCopyLibs {
1825 target: Interned<String>,
1828 impl Step for RemoteCopyLibs {
1831 fn should_run(run: ShouldRun) -> ShouldRun {
1835 fn run(self, builder: &Builder) {
1836 let compiler = self.compiler;
1837 let target = self.target;
1838 if !builder.remote_tested(target) {
1842 builder.ensure(compile::Test { compiler, target });
1844 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
1845 t!(fs::create_dir_all(builder.out.join("tmp")));
1847 let server = builder.ensure(tool::RemoteTestServer {
1848 compiler: compiler.with_stage(0),
1852 // Spawn the emulator and wait for it to come online
1853 let tool = builder.tool_exe(Tool::RemoteTestClient);
1854 let mut cmd = Command::new(&tool);
1855 cmd.arg("spawn-emulator")
1858 .arg(builder.out.join("tmp"));
1859 if let Some(rootfs) = builder.qemu_rootfs(target) {
1862 builder.run(&mut cmd);
1864 // Push all our dylibs to the emulator
1865 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
1867 let name = f.file_name().into_string().unwrap();
1868 if util::is_dylib(&name) {
1869 builder.run(Command::new(&tool).arg("push").arg(f.path()));
1875 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1876 pub struct Distcheck;
1878 impl Step for Distcheck {
1881 fn should_run(run: ShouldRun) -> ShouldRun {
1882 run.path("distcheck")
1885 fn make_run(run: RunConfig) {
1886 run.builder.ensure(Distcheck);
1889 /// Run "distcheck", a 'make check' from a tarball
1890 fn run(self, builder: &Builder) {
1891 builder.info("Distcheck");
1892 let dir = builder.out.join("tmp").join("distcheck");
1893 let _ = fs::remove_dir_all(&dir);
1894 t!(fs::create_dir_all(&dir));
1896 // Guarantee that these are built before we begin running.
1897 builder.ensure(dist::PlainSourceTarball);
1898 builder.ensure(dist::Src);
1900 let mut cmd = Command::new("tar");
1902 .arg(builder.ensure(dist::PlainSourceTarball))
1903 .arg("--strip-components=1")
1905 builder.run(&mut cmd);
1907 Command::new("./configure")
1908 .args(&builder.config.configure_args)
1909 .arg("--enable-vendor")
1913 Command::new(build_helper::make(&builder.config.build))
1918 // Now make sure that rust-src has all of libstd's dependencies
1919 builder.info("Distcheck rust-src");
1920 let dir = builder.out.join("tmp").join("distcheck-src");
1921 let _ = fs::remove_dir_all(&dir);
1922 t!(fs::create_dir_all(&dir));
1924 let mut cmd = Command::new("tar");
1926 .arg(builder.ensure(dist::Src))
1927 .arg("--strip-components=1")
1929 builder.run(&mut cmd);
1931 let toml = dir.join("rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml");
1933 Command::new(&builder.initial_cargo)
1934 .arg("generate-lockfile")
1935 .arg("--manifest-path")
1937 .env("__CARGO_TEST_ROOT", &dir)
1943 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1944 pub struct Bootstrap;
1946 impl Step for Bootstrap {
1948 const DEFAULT: bool = true;
1949 const ONLY_HOSTS: bool = true;
1951 /// Test the build system itself
1952 fn run(self, builder: &Builder) {
1953 let mut cmd = Command::new(&builder.initial_cargo);
1955 .current_dir(builder.src.join("src/bootstrap"))
1956 .env("RUSTFLAGS", "-Cdebuginfo=2")
1957 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
1958 .env("RUSTC_BOOTSTRAP", "1")
1959 .env("RUSTC", &builder.initial_rustc);
1960 if let Some(flags) = option_env!("RUSTFLAGS") {
1961 // Use the same rustc flags for testing as for "normal" compilation,
1962 // so that Cargo doesn’t recompile the entire dependency graph every time:
1963 // https://github.com/rust-lang/rust/issues/49215
1964 cmd.env("RUSTFLAGS", flags);
1966 if !builder.fail_fast {
1967 cmd.arg("--no-fail-fast");
1969 cmd.arg("--").args(&builder.config.cmd.test_args());
1970 // rustbuild tests are racy on directory creation so just run them one at a time.
1971 // Since there's not many this shouldn't be a problem.
1972 cmd.arg("--test-threads=1");
1973 try_run(builder, &mut cmd);
1976 fn should_run(run: ShouldRun) -> ShouldRun {
1977 run.path("src/bootstrap")
1980 fn make_run(run: RunConfig) {
1981 run.builder.ensure(Bootstrap);