1 //! Implementation of the test-related targets of the build system.
3 //! This file implements the various regression test suites that we execute on
7 use std::ffi::OsString;
11 use std::path::{Path, PathBuf};
12 use std::process::{Command, Stdio};
14 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
15 use crate::cache::Interned;
17 use crate::config::TargetSelection;
19 use crate::flags::Subcommand;
21 use crate::tool::{self, SourceType, Tool};
22 use crate::toolstate::ToolState;
23 use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
24 use crate::{envify, CLang, DocTests, GitRepo, Mode};
26 const ADB_TEST_DIR: &str = "/data/tmp/work";
28 /// The two modes of the test runner; tests or benchmarks.
29 #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
33 /// Run `cargo bench`.
37 impl From<Kind> for TestKind {
38 fn from(kind: Kind) -> Self {
40 Kind::Test => TestKind::Test,
41 Kind::Bench => TestKind::Bench,
42 _ => panic!("unexpected kind in crate: {:?}", kind),
48 // Return the cargo subcommand for this test kind
49 fn subcommand(self) -> &'static str {
51 TestKind::Test => "test",
52 TestKind::Bench => "bench",
57 impl fmt::Display for TestKind {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 f.write_str(match *self {
60 TestKind::Test => "Testing",
61 TestKind::Bench => "Benchmarking",
66 fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
67 if !builder.fail_fast {
68 if !builder.try_run(cmd) {
69 let mut failures = builder.delayed_failures.borrow_mut();
70 failures.push(format!("{:?}", cmd));
79 fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
80 if !builder.fail_fast {
81 if !builder.try_run_quiet(cmd) {
82 let mut failures = builder.delayed_failures.borrow_mut();
83 failures.push(format!("{:?}", cmd));
87 builder.run_quiet(cmd);
92 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
93 pub struct Linkcheck {
94 host: TargetSelection,
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 host = self.host;
108 let hosts = &builder.hosts;
109 let targets = &builder.targets;
111 // if we have different hosts and targets, some things may be built for
112 // the host (e.g. rustc) and others for the target (e.g. std). The
113 // documentation built for each will contain broken links to
114 // docs built for the other platform (e.g. rustc linking to cargo)
115 if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
117 "Linkcheck currently does not support builds with different hosts and targets.
118 You can skip linkcheck with --exclude src/tools/linkchecker"
122 builder.info(&format!("Linkcheck ({})", host));
124 // Test the linkchecker itself.
125 let bootstrap_host = builder.config.build;
126 let compiler = builder.compiler(0, bootstrap_host);
127 let cargo = tool::prepare_tool_cargo(
133 "src/tools/linkchecker",
137 try_run(builder, &mut cargo.into());
139 // Build all the default documentation.
140 builder.default_doc(&[]);
142 // Run the linkchecker.
143 let _time = util::timeit(&builder);
146 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
150 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
151 let builder = run.builder;
152 let run = run.path("src/tools/linkchecker");
153 run.default_condition(builder.config.docs)
156 fn make_run(run: RunConfig<'_>) {
157 run.builder.ensure(Linkcheck { host: run.target });
161 fn check_if_tidy_is_installed() -> bool {
164 .stdout(Stdio::null())
166 .map_or(false, |status| status.success())
169 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
170 pub struct HtmlCheck {
171 target: TargetSelection,
174 impl Step for HtmlCheck {
176 const DEFAULT: bool = true;
177 const ONLY_HOSTS: bool = true;
179 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
180 let run = run.path("src/tools/html-checker");
181 run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
184 fn make_run(run: RunConfig<'_>) {
185 run.builder.ensure(HtmlCheck { target: run.target });
188 fn run(self, builder: &Builder<'_>) {
189 if !check_if_tidy_is_installed() {
190 eprintln!("not running HTML-check tool because `tidy` is missing");
192 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
194 panic!("Cannot run html-check tests");
196 // Ensure that a few different kinds of documentation are available.
197 builder.default_doc(&[]);
198 builder.ensure(crate::doc::Rustc { target: self.target, stage: builder.top_stage });
200 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
204 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205 pub struct Cargotest {
207 host: TargetSelection,
210 impl Step for Cargotest {
212 const ONLY_HOSTS: bool = true;
214 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
215 run.path("src/tools/cargotest")
218 fn make_run(run: RunConfig<'_>) {
219 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
222 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
224 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
225 /// test` to ensure that we don't regress the test suites there.
226 fn run(self, builder: &Builder<'_>) {
227 let compiler = builder.compiler(self.stage, self.host);
228 builder.ensure(compile::Rustc::new(compiler, compiler.host));
229 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
231 // Note that this is a short, cryptic, and not scoped directory name. This
232 // is currently to minimize the length of path on Windows where we otherwise
233 // quickly run into path name limit constraints.
234 let out_dir = builder.out.join("ct");
235 t!(fs::create_dir_all(&out_dir));
237 let _time = util::timeit(&builder);
238 let mut cmd = builder.tool_cmd(Tool::CargoTest);
243 .args(builder.config.cmd.test_args())
244 .env("RUSTC", builder.rustc(compiler))
245 .env("RUSTDOC", builder.rustdoc(compiler)),
250 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
253 host: TargetSelection,
256 impl Step for Cargo {
258 const ONLY_HOSTS: bool = true;
260 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
261 run.path("src/tools/cargo")
264 fn make_run(run: RunConfig<'_>) {
265 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
268 /// Runs `cargo test` for `cargo` packaged with Rust.
269 fn run(self, builder: &Builder<'_>) {
270 let compiler = builder.compiler(self.stage, self.host);
272 builder.ensure(tool::Cargo { compiler, target: self.host });
273 let mut cargo = tool::prepare_tool_cargo(
280 SourceType::Submodule,
284 if !builder.fail_fast {
285 cargo.arg("--no-fail-fast");
287 cargo.arg("--").args(builder.config.cmd.test_args());
289 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
291 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
292 // Forcibly disable tests using nightly features since any changes to
293 // those features won't be able to land.
294 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
296 cargo.env("PATH", &path_for_cargo(builder, compiler));
298 try_run(builder, &mut cargo.into());
302 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
303 pub struct RustAnalyzer {
305 host: TargetSelection,
308 impl Step for RustAnalyzer {
310 const ONLY_HOSTS: bool = true;
311 const DEFAULT: bool = true;
313 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
314 run.path("src/tools/rust-analyzer")
317 fn make_run(run: RunConfig<'_>) {
318 run.builder.ensure(Self { stage: run.builder.top_stage, host: run.target });
321 /// Runs `cargo test` for rust-analyzer
322 fn run(self, builder: &Builder<'_>) {
323 let stage = self.stage;
324 let host = self.host;
325 let compiler = builder.compiler(stage, host);
327 builder.ensure(tool::RustAnalyzer { compiler, target: self.host }).expect("in-tree tool");
329 let workspace_path = "src/tools/rust-analyzer";
330 // until the whole RA test suite runs on `i686`, we only run
331 // `proc-macro-srv` tests
332 let crate_path = "src/tools/rust-analyzer/crates/proc-macro-srv";
333 let mut cargo = tool::prepare_tool_cargo(
341 &["sysroot-abi".to_owned()],
344 let dir = builder.src.join(workspace_path);
345 // needed by rust-analyzer to find its own text fixtures, cf.
346 // https://github.com/rust-analyzer/expect-test/issues/33
347 cargo.env("CARGO_WORKSPACE_DIR", &dir);
349 // RA's test suite tries to write to the source directory, that can't
351 cargo.env("SKIP_SLOW_TESTS", "1");
353 cargo.add_rustc_lib_path(builder, compiler);
354 cargo.arg("--").args(builder.config.cmd.test_args());
356 builder.run(&mut cargo.into());
360 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
363 host: TargetSelection,
366 impl Step for Rustfmt {
368 const ONLY_HOSTS: bool = true;
370 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
371 run.path("src/tools/rustfmt")
374 fn make_run(run: RunConfig<'_>) {
375 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
378 /// Runs `cargo test` for rustfmt.
379 fn run(self, builder: &Builder<'_>) {
380 let stage = self.stage;
381 let host = self.host;
382 let compiler = builder.compiler(stage, host);
385 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
386 .expect("in-tree tool");
388 let mut cargo = tool::prepare_tool_cargo(
399 let dir = testdir(builder, compiler.host);
400 t!(fs::create_dir_all(&dir));
401 cargo.env("RUSTFMT_TEST_DIR", dir);
403 cargo.add_rustc_lib_path(builder, compiler);
405 builder.run(&mut cargo.into());
409 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
410 pub struct RustDemangler {
412 host: TargetSelection,
415 impl Step for RustDemangler {
417 const ONLY_HOSTS: bool = true;
419 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
420 run.path("src/tools/rust-demangler")
423 fn make_run(run: RunConfig<'_>) {
424 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
427 /// Runs `cargo test` for rust-demangler.
428 fn run(self, builder: &Builder<'_>) {
429 let stage = self.stage;
430 let host = self.host;
431 let compiler = builder.compiler(stage, host);
433 let rust_demangler = builder
434 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
435 .expect("in-tree tool");
436 let mut cargo = tool::prepare_tool_cargo(
442 "src/tools/rust-demangler",
447 let dir = testdir(builder, compiler.host);
448 t!(fs::create_dir_all(&dir));
450 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
452 cargo.arg("--").args(builder.config.cmd.test_args());
454 cargo.add_rustc_lib_path(builder, compiler);
456 builder.run(&mut cargo.into());
460 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
463 host: TargetSelection,
468 const ONLY_HOSTS: bool = true;
470 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
471 run.path("src/tools/miri")
474 fn make_run(run: RunConfig<'_>) {
475 run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
478 /// Runs `cargo test` for miri.
479 fn run(self, builder: &Builder<'_>) {
480 let stage = self.stage;
481 let host = self.host;
482 let compiler = builder.compiler(stage, host);
483 // We need the stdlib for the *next* stage, as it was built with this compiler that also built Miri.
484 // Except if we are at stage 2, the bootstrap loop is complete and we can stick with our current stage.
485 let compiler_std = builder.compiler(if stage < 2 { stage + 1 } else { stage }, host);
488 builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
489 let cargo_miri = builder.ensure(tool::CargoMiri {
492 extra_features: Vec::new(),
494 // The stdlib we need might be at a different stage. And just asking for the
495 // sysroot does not seem to populate it, so we do that first.
496 builder.ensure(compile::Std::new(compiler_std, host));
497 let sysroot = builder.sysroot(compiler_std);
498 if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) {
500 builder.cargo(compiler, Mode::ToolRustc, SourceType::Submodule, host, "install");
502 // Configure `cargo install` path. cargo adds a `bin/`.
503 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
505 let mut cargo = Command::from(cargo);
506 if !try_run(builder, &mut cargo) {
510 // # Run `cargo miri setup`.
511 let mut cargo = tool::prepare_tool_cargo(
517 "src/tools/miri/cargo-miri",
518 SourceType::Submodule,
521 cargo.add_rustc_lib_path(builder, compiler);
522 cargo.arg("--").arg("miri").arg("setup");
524 // Tell `cargo miri setup` where to find the sources.
525 cargo.env("XARGO_RUST_SRC", builder.src.join("library"));
526 // Tell it where to find Miri.
527 cargo.env("MIRI", &miri);
529 cargo.env("RUST_BACKTRACE", "1");
530 // Let cargo-miri know where xargo ended up.
531 cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));
533 let mut cargo = Command::from(cargo);
534 if !try_run(builder, &mut cargo) {
538 // # Determine where Miri put its sysroot.
539 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
540 // (We do this separately from the above so that when the setup actually
541 // happens we get some output.)
542 // We re-use the `cargo` from above.
543 cargo.arg("--print-sysroot");
545 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
546 let miri_sysroot = if builder.config.dry_run {
549 builder.verbose(&format!("running: {:?}", cargo));
552 .expect("We already ran `cargo miri setup` before and that worked");
553 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
554 // Output is "<sysroot>\n".
555 let stdout = String::from_utf8(out.stdout)
556 .expect("`cargo miri setup` stdout is not valid UTF-8");
557 let sysroot = stdout.trim_end();
558 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
562 // # Run `cargo test`.
563 let mut cargo = tool::prepare_tool_cargo(
570 SourceType::Submodule,
573 cargo.add_rustc_lib_path(builder, compiler);
575 // miri tests need to know about the stage sysroot
576 cargo.env("MIRI_SYSROOT", miri_sysroot);
577 cargo.env("MIRI_HOST_SYSROOT", sysroot);
578 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
579 cargo.env("MIRI", miri);
581 if builder.config.cmd.bless() {
582 cargo.env("MIRI_BLESS", "Gesundheit");
585 cargo.arg("--").args(builder.config.cmd.test_args());
587 let mut cargo = Command::from(cargo);
588 if !try_run(builder, &mut cargo) {
593 builder.save_toolstate("miri", ToolState::TestPass);
595 eprintln!("failed to test miri: could not build");
600 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
601 pub struct CompiletestTest {
602 host: TargetSelection,
605 impl Step for CompiletestTest {
608 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
609 run.path("src/tools/compiletest")
612 fn make_run(run: RunConfig<'_>) {
613 run.builder.ensure(CompiletestTest { host: run.target });
616 /// Runs `cargo test` for compiletest.
617 fn run(self, builder: &Builder<'_>) {
618 let host = self.host;
619 let compiler = builder.compiler(0, host);
621 // We need `ToolStd` for the locally-built sysroot because
622 // compiletest uses unstable features of the `test` crate.
623 builder.ensure(compile::Std::new(compiler, host));
624 let cargo = tool::prepare_tool_cargo(
630 "src/tools/compiletest",
635 try_run(builder, &mut cargo.into());
639 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
642 host: TargetSelection,
645 impl Step for Clippy {
647 const ONLY_HOSTS: bool = true;
648 const DEFAULT: bool = false;
650 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
651 run.path("src/tools/clippy")
654 fn make_run(run: RunConfig<'_>) {
655 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
658 /// Runs `cargo test` for clippy.
659 fn run(self, builder: &Builder<'_>) {
660 let stage = self.stage;
661 let host = self.host;
662 let compiler = builder.compiler(stage, host);
665 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
666 .expect("in-tree tool");
667 let mut cargo = tool::prepare_tool_cargo(
678 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
679 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
680 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
681 cargo.env("HOST_LIBS", host_libs);
683 cargo.arg("--").args(builder.config.cmd.test_args());
685 cargo.add_rustc_lib_path(builder, compiler);
687 if builder.try_run(&mut cargo.into()) {
688 // The tests succeeded; nothing to do.
692 if !builder.config.cmd.bless() {
693 crate::detail_exit(1);
696 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
697 cargo.arg("-p").arg("clippy_dev");
698 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
699 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
700 if builder.config.rust_optimize {
701 cargo.env("PROFILE", "release");
703 cargo.env("PROFILE", "debug");
707 builder.run(&mut cargo.into());
711 fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
712 // Configure PATH to find the right rustc. NB. we have to use PATH
713 // and not RUSTC because the Cargo test suite has tests that will
714 // fail if rustc is not spelled `rustc`.
715 let path = builder.sysroot(compiler).join("bin");
716 let old_path = env::var_os("PATH").unwrap_or_default();
717 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
720 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
721 pub struct RustdocTheme {
722 pub compiler: Compiler,
725 impl Step for RustdocTheme {
727 const DEFAULT: bool = true;
728 const ONLY_HOSTS: bool = true;
730 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
731 run.path("src/tools/rustdoc-themes")
734 fn make_run(run: RunConfig<'_>) {
735 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
737 run.builder.ensure(RustdocTheme { compiler });
740 fn run(self, builder: &Builder<'_>) {
741 let rustdoc = builder.bootstrap_out.join("rustdoc");
742 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
743 cmd.arg(rustdoc.to_str().unwrap())
744 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
745 .env("RUSTC_STAGE", self.compiler.stage.to_string())
746 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
747 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
748 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
749 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
750 .env("RUSTC_BOOTSTRAP", "1");
751 if let Some(linker) = builder.linker(self.compiler.host) {
752 cmd.env("RUSTDOC_LINKER", linker);
754 if builder.is_fuse_ld_lld(self.compiler.host) {
755 cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
757 try_run(builder, &mut cmd);
761 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
762 pub struct RustdocJSStd {
763 pub target: TargetSelection,
766 impl Step for RustdocJSStd {
768 const DEFAULT: bool = true;
769 const ONLY_HOSTS: bool = true;
771 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
772 run.suite_path("src/test/rustdoc-js-std")
775 fn make_run(run: RunConfig<'_>) {
776 run.builder.ensure(RustdocJSStd { target: run.target });
779 fn run(self, builder: &Builder<'_>) {
780 if let Some(ref nodejs) = builder.config.nodejs {
781 let mut command = Command::new(nodejs);
783 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
786 .arg("--resource-suffix")
787 .arg(&builder.version)
789 .arg(builder.doc_out(self.target))
790 .arg("--test-folder")
791 .arg(builder.src.join("src/test/rustdoc-js-std"));
792 for path in &builder.paths {
794 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
796 if !p.ends_with(".js") {
797 eprintln!("A non-js file was given: `{}`", path.display());
798 panic!("Cannot run rustdoc-js-std tests");
800 command.arg("--test-file").arg(path);
803 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
804 builder.run(&mut command);
806 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
811 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
812 pub struct RustdocJSNotStd {
813 pub target: TargetSelection,
814 pub compiler: Compiler,
817 impl Step for RustdocJSNotStd {
819 const DEFAULT: bool = true;
820 const ONLY_HOSTS: bool = true;
822 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
823 run.suite_path("src/test/rustdoc-js")
826 fn make_run(run: RunConfig<'_>) {
827 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
828 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
831 fn run(self, builder: &Builder<'_>) {
832 if builder.config.nodejs.is_some() {
833 builder.ensure(Compiletest {
834 compiler: self.compiler,
838 path: "src/test/rustdoc-js",
842 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
847 fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
848 let mut command = Command::new(&npm);
849 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
851 command.arg("--global");
855 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
856 .unwrap_or(String::new());
859 .find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
860 .map(|v| v.to_owned())
863 fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
864 get_browser_ui_test_version_inner(npm, false)
865 .or_else(|| get_browser_ui_test_version_inner(npm, true))
868 fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
869 match fs::read_to_string(
870 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
873 if v.trim() != installed_version {
875 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
876 one used in the CI (`{}`)",
880 "You can install this version using `npm update browser-ui-test` or by using \
881 `npm install browser-ui-test@{}`",
886 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
890 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
891 pub struct RustdocGUI {
892 pub target: TargetSelection,
893 pub compiler: Compiler,
896 impl Step for RustdocGUI {
898 const DEFAULT: bool = true;
899 const ONLY_HOSTS: bool = true;
901 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
902 let builder = run.builder;
903 let run = run.suite_path("src/test/rustdoc-gui");
904 run.lazy_default_condition(Box::new(move || {
905 builder.config.nodejs.is_some()
910 .map(|p| get_browser_ui_test_version(p).is_some())
915 fn make_run(run: RunConfig<'_>) {
916 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
917 run.builder.ensure(RustdocGUI { target: run.target, compiler });
920 fn run(self, builder: &Builder<'_>) {
921 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
922 let npm = builder.config.npm.as_ref().expect("npm isn't available");
924 builder.ensure(compile::Std::new(self.compiler, self.target));
926 // The goal here is to check if the necessary packages are installed, and if not, we
928 match get_browser_ui_test_version(&npm) {
930 // We also check the version currently used in CI and emit a warning if it's not the
932 compare_browser_ui_test_version(&version, &builder.build.src);
936 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
937 dependency is missing",
940 "If you want to install the `{0}` dependency, run `npm install {0}`",
943 panic!("Cannot run rustdoc-gui tests");
947 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
949 // We remove existing folder to be sure there won't be artifacts remaining.
950 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
952 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
953 // We generate docs for the libraries present in the rustdoc-gui's src folder.
954 for entry in src_path.read_dir().expect("read_dir call failed") {
955 if let Ok(entry) = entry {
956 let path = entry.path();
962 let mut cargo = Command::new(&builder.initial_cargo);
967 .env("RUSTDOC", builder.rustdoc(self.compiler))
968 .env("RUSTC", builder.rustc(self.compiler))
970 // FIXME: implement a `// compile-flags` command or similar
971 // instead of hard-coding this test
972 if entry.file_name() == "link_to_definition" {
973 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
975 builder.run(&mut cargo);
979 // We now run GUI tests.
980 let mut command = Command::new(&nodejs);
982 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
984 .arg(&builder.jobs().to_string())
986 .arg(out_dir.join("doc"))
987 .arg("--tests-folder")
988 .arg(builder.build.src.join("src/test/rustdoc-gui"));
989 for path in &builder.paths {
990 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
991 if !p.ends_with(".goml") {
992 eprintln!("A non-goml file was given: `{}`", path.display());
993 panic!("Cannot run rustdoc-gui tests");
995 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
996 command.arg("--file").arg(name);
1000 for test_arg in builder.config.cmd.test_args() {
1001 command.arg(test_arg);
1003 builder.run(&mut command);
1007 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1010 impl Step for Tidy {
1012 const DEFAULT: bool = true;
1013 const ONLY_HOSTS: bool = true;
1015 /// Runs the `tidy` tool.
1017 /// This tool in `src/tools` checks up on various bits and pieces of style and
1018 /// otherwise just implements a few lint-like checks that are specific to the
1019 /// compiler itself.
1021 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
1022 /// for the `dev` or `nightly` channels.
1023 fn run(self, builder: &Builder<'_>) {
1024 let mut cmd = builder.tool_cmd(Tool::Tidy);
1025 cmd.arg(&builder.src);
1026 cmd.arg(&builder.initial_cargo);
1027 cmd.arg(&builder.out);
1028 cmd.arg(builder.jobs().to_string());
1029 if builder.is_verbose() {
1030 cmd.arg("--verbose");
1033 builder.info("tidy check");
1034 try_run(builder, &mut cmd);
1036 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1037 builder.info("fmt check");
1038 if builder.initial_rustfmt().is_none() {
1039 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1042 error: no `rustfmt` binary found in {PATH}
1043 info: `rust.channel` is currently set to \"{CHAN}\"
1044 help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1045 help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1046 PATH = inferred_rustfmt_dir.display(),
1047 CHAN = builder.config.channel,
1049 crate::detail_exit(1);
1051 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
1055 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1056 run.path("src/tools/tidy")
1059 fn make_run(run: RunConfig<'_>) {
1060 run.builder.ensure(Tidy);
1064 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1065 pub struct ExpandYamlAnchors;
1067 impl Step for ExpandYamlAnchors {
1069 const ONLY_HOSTS: bool = true;
1071 /// Ensure the `generate-ci-config` tool was run locally.
1073 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1074 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1075 /// by the user before committing CI changes.
1076 fn run(self, builder: &Builder<'_>) {
1077 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1080 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1084 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1085 run.path("src/tools/expand-yaml-anchors")
1088 fn make_run(run: RunConfig<'_>) {
1089 run.builder.ensure(ExpandYamlAnchors);
1093 fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1094 builder.out.join(host.triple).join("test")
1097 macro_rules! default_test {
1098 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1099 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
1103 macro_rules! default_test_with_compare_mode {
1104 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1105 compare_mode: $compare_mode:expr }) => {
1106 test_with_compare_mode!($name {
1112 compare_mode: $compare_mode
1117 macro_rules! host_test {
1118 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1119 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
1124 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1125 host: $host:expr }) => {
1126 test_definitions!($name {
1137 macro_rules! test_with_compare_mode {
1138 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1139 host: $host:expr, compare_mode: $compare_mode:expr }) => {
1140 test_definitions!($name {
1146 compare_mode: Some($compare_mode)
1151 macro_rules! test_definitions {
1156 default: $default:expr,
1158 compare_mode: $compare_mode:expr
1160 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1162 pub compiler: Compiler,
1163 pub target: TargetSelection,
1166 impl Step for $name {
1168 const DEFAULT: bool = $default;
1169 const ONLY_HOSTS: bool = $host;
1171 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1172 run.suite_path($path)
1175 fn make_run(run: RunConfig<'_>) {
1176 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1178 run.builder.ensure($name { compiler, target: run.target });
1181 fn run(self, builder: &Builder<'_>) {
1182 builder.ensure(Compiletest {
1183 compiler: self.compiler,
1184 target: self.target,
1188 compare_mode: $compare_mode,
1195 default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
1197 default_test!(RunPassValgrind {
1198 path: "src/test/run-pass-valgrind",
1199 mode: "run-pass-valgrind",
1200 suite: "run-pass-valgrind"
1203 default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
1205 default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
1207 default_test!(CodegenUnits {
1208 path: "src/test/codegen-units",
1209 mode: "codegen-units",
1210 suite: "codegen-units"
1213 default_test!(Incremental {
1214 path: "src/test/incremental",
1215 mode: "incremental",
1216 suite: "incremental"
1219 default_test_with_compare_mode!(Debuginfo {
1220 path: "src/test/debuginfo",
1223 compare_mode: "split-dwarf"
1226 host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
1228 host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
1229 host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1231 host_test!(RustdocJson {
1232 path: "src/test/rustdoc-json",
1233 mode: "rustdoc-json",
1234 suite: "rustdoc-json"
1237 host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
1239 default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
1241 host_test!(RunMakeFullDeps {
1242 path: "src/test/run-make-fulldeps",
1244 suite: "run-make-fulldeps"
1247 default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
1249 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1250 struct Compiletest {
1252 target: TargetSelection,
1254 suite: &'static str,
1256 compare_mode: Option<&'static str>,
1259 impl Step for Compiletest {
1262 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1266 /// Executes the `compiletest` tool to run a suite of tests.
1268 /// Compiles all tests with `compiler` for `target` with the specified
1269 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1270 /// "run-pass" or `suite` can be something like `debuginfo`.
1271 fn run(self, builder: &Builder<'_>) {
1272 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1274 error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1275 help: to test the compiler, use `--stage 1` instead
1276 help: to test the standard library, use `--stage 0 library/std` instead
1277 note: if you're sure you want to do this, please open an issue as to why. In the meantime, you can override this with `COMPILETEST_FORCE_STAGE0=1`."
1279 crate::detail_exit(1);
1282 let compiler = self.compiler;
1283 let target = self.target;
1284 let mode = self.mode;
1285 let suite = self.suite;
1287 // Path for test suite
1288 let suite_path = self.path;
1290 // Skip codegen tests if they aren't enabled in configuration.
1291 if !builder.config.codegen_tests && suite == "codegen" {
1295 if suite == "debuginfo" {
1297 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
1300 if suite.ends_with("fulldeps") {
1301 builder.ensure(compile::Rustc::new(compiler, target));
1304 builder.ensure(compile::Std::new(compiler, target));
1305 // ensure that `libproc_macro` is available on the host.
1306 builder.ensure(compile::Std::new(compiler, compiler.host));
1308 // Also provide `rust_test_helpers` for the host.
1309 builder.ensure(native::TestHelpers { target: compiler.host });
1311 // As well as the target, except for plain wasm32, which can't build it
1312 if !target.contains("wasm") || target.contains("emscripten") {
1313 builder.ensure(native::TestHelpers { target });
1316 builder.ensure(RemoteCopyLibs { compiler, target });
1318 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1320 // compiletest currently has... a lot of arguments, so let's just pass all
1323 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1324 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
1325 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1327 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
1329 // Avoid depending on rustdoc when we don't need it.
1330 if mode == "rustdoc"
1331 || mode == "run-make"
1332 || (mode == "ui" && is_rustdoc)
1333 || mode == "js-doc-test"
1334 || mode == "rustdoc-json"
1336 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
1339 if mode == "rustdoc-json" {
1340 // Use the beta compiler for jsondocck
1341 let json_compiler = compiler.with_stage(0);
1342 cmd.arg("--jsondocck-path")
1343 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1344 cmd.arg("--jsondoclint-path")
1345 .arg(builder.ensure(tool::JsonDocLint { compiler: json_compiler, target }));
1348 if mode == "run-make" {
1349 let rust_demangler = builder
1350 .ensure(tool::RustDemangler {
1352 target: compiler.host,
1353 extra_features: Vec::new(),
1355 .expect("in-tree tool");
1356 cmd.arg("--rust-demangler-path").arg(rust_demangler);
1359 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1360 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1361 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
1362 cmd.arg("--suite").arg(suite);
1363 cmd.arg("--mode").arg(mode);
1364 cmd.arg("--target").arg(target.rustc_target_arg());
1365 cmd.arg("--host").arg(&*compiler.host.triple);
1366 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
1368 if builder.config.cmd.bless() {
1372 if builder.config.cmd.force_rerun() {
1373 cmd.arg("--force-rerun");
1377 builder.config.cmd.compare_mode().or_else(|| {
1378 if builder.config.test_compare_mode { self.compare_mode } else { None }
1381 if let Some(ref pass) = builder.config.cmd.pass() {
1386 if let Some(ref run) = builder.config.cmd.run() {
1391 if let Some(ref nodejs) = builder.config.nodejs {
1392 cmd.arg("--nodejs").arg(nodejs);
1394 if let Some(ref npm) = builder.config.npm {
1395 cmd.arg("--npm").arg(npm);
1397 if builder.config.rust_optimize_tests {
1398 cmd.arg("--optimize-tests");
1400 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
1401 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
1402 flags.push(builder.config.cmd.rustc_args().join(" "));
1404 if let Some(linker) = builder.linker(target) {
1405 cmd.arg("--linker").arg(linker);
1408 let mut hostflags = flags.clone();
1409 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1410 hostflags.extend(builder.lld_flags(compiler.host));
1411 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1413 let mut targetflags = flags;
1414 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1415 targetflags.extend(builder.lld_flags(target));
1416 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1418 cmd.arg("--python").arg(builder.python());
1420 if let Some(ref gdb) = builder.config.gdb {
1421 cmd.arg("--gdb").arg(gdb);
1424 let run = |cmd: &mut Command| {
1425 cmd.output().map(|output| {
1426 String::from_utf8_lossy(&output.stdout)
1429 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1433 let lldb_exe = "lldb";
1434 let lldb_version = Command::new(lldb_exe)
1437 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1439 if let Some(ref vers) = lldb_version {
1440 cmd.arg("--lldb-version").arg(vers);
1441 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
1442 if let Some(ref dir) = lldb_python_dir {
1443 cmd.arg("--lldb-python-dir").arg(dir);
1447 if util::forcing_clang_based_tests() {
1448 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1449 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
1452 for exclude in &builder.config.exclude {
1454 cmd.arg(&exclude.path);
1457 // Get paths from cmd args
1458 let paths = match &builder.config.cmd {
1459 Subcommand::Test { ref paths, .. } => &paths[..],
1463 // Get test-args by striping suite path
1464 let mut test_args: Vec<&str> = paths
1466 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
1469 test_args.append(&mut builder.config.cmd.test_args());
1471 // On Windows, replace forward slashes in test-args by backslashes
1472 // so the correct filters are passed to libtest
1474 let test_args_win: Vec<String> =
1475 test_args.iter().map(|s| s.replace("/", "\\")).collect();
1476 cmd.args(&test_args_win);
1478 cmd.args(&test_args);
1481 if builder.is_verbose() {
1482 cmd.arg("--verbose");
1485 if !builder.config.verbose_tests {
1489 let mut llvm_components_passed = false;
1490 let mut copts_passed = false;
1491 if builder.config.llvm_enabled() {
1492 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
1493 if !builder.config.dry_run {
1494 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1495 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1496 // Remove trailing newline from llvm-config output.
1497 cmd.arg("--llvm-version")
1498 .arg(llvm_version.trim())
1499 .arg("--llvm-components")
1500 .arg(llvm_components.trim());
1501 llvm_components_passed = true;
1503 if !builder.is_rust_llvm(target) {
1504 cmd.arg("--system-llvm");
1507 // Tests that use compiler libraries may inherit the `-lLLVM` link
1508 // requirement, but the `-L` library path is not propagated across
1509 // separate compilations. We can add LLVM's library path to the
1510 // platform-specific environment variable as a workaround.
1511 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1512 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1513 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1516 // Only pass correct values for these flags for the `run-make` suite as it
1517 // requires that a C++ compiler was configured which isn't always the case.
1518 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1519 // The llvm/bin directory contains many useful cross-platform
1520 // tools. Pass the path to run-make tests so they can use them.
1521 let llvm_bin_path = llvm_config
1523 .expect("Expected llvm-config to be contained in directory");
1524 assert!(llvm_bin_path.is_dir());
1525 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1527 // If LLD is available, add it to the PATH
1528 if builder.config.lld_enabled {
1529 let lld_install_root =
1530 builder.ensure(native::Lld { target: builder.config.build });
1532 let lld_bin_path = lld_install_root.join("bin");
1534 let old_path = env::var_os("PATH").unwrap_or_default();
1535 let new_path = env::join_paths(
1536 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1538 .expect("Could not add LLD bin path to PATH");
1539 cmd.env("PATH", new_path);
1544 // Only pass correct values for these flags for the `run-make` suite as it
1545 // requires that a C++ compiler was configured which isn't always the case.
1546 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1548 .arg(builder.cc(target))
1550 .arg(builder.cxx(target).unwrap())
1552 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1554 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
1555 copts_passed = true;
1556 if let Some(ar) = builder.ar(target) {
1557 cmd.arg("--ar").arg(ar);
1561 if !llvm_components_passed {
1562 cmd.arg("--llvm-components").arg("");
1575 if builder.remote_tested(target) {
1576 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
1579 // Running a C compiler on MSVC requires a few env vars to be set, to be
1580 // sure to set them here.
1582 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1583 // rather than stomp over it.
1584 if target.contains("msvc") {
1585 for &(ref k, ref v) in builder.cc[&target].env() {
1591 cmd.env("RUSTC_BOOTSTRAP", "1");
1592 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1593 // needed when diffing test output.
1594 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
1595 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
1596 builder.add_rust_test_threads(&mut cmd);
1598 if builder.config.sanitizers_enabled(target) {
1599 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
1602 if builder.config.profiler_enabled(target) {
1603 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
1606 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
1608 cmd.arg("--adb-path").arg("adb");
1609 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1610 if target.contains("android") {
1611 // Assume that cc for this target comes from the android sysroot
1612 cmd.arg("--android-cross-path")
1613 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
1615 cmd.arg("--android-cross-path").arg("");
1618 if builder.config.cmd.rustfix_coverage() {
1619 cmd.arg("--rustfix-coverage");
1622 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1624 cmd.arg("--channel").arg(&builder.config.channel);
1626 builder.ci_env.force_coloring_in_ci(&mut cmd);
1628 builder.info(&format!(
1629 "Check compiletest suite={} mode={} ({} -> {})",
1630 suite, mode, &compiler.host, target
1632 let _time = util::timeit(&builder);
1633 try_run(builder, &mut cmd);
1635 if let Some(compare_mode) = compare_mode {
1636 cmd.arg("--compare-mode").arg(compare_mode);
1637 builder.info(&format!(
1638 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1639 suite, mode, compare_mode, &compiler.host, target
1641 let _time = util::timeit(&builder);
1642 try_run(builder, &mut cmd);
1647 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1655 impl Step for BookTest {
1657 const ONLY_HOSTS: bool = true;
1659 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1663 /// Runs the documentation tests for a book in `src/doc`.
1665 /// This uses the `rustdoc` that sits next to `compiler`.
1666 fn run(self, builder: &Builder<'_>) {
1667 // External docs are different from local because:
1668 // - Some books need pre-processing by mdbook before being tested.
1669 // - They need to save their state to toolstate.
1670 // - They are only tested on the "checktools" builders.
1672 // The local docs are tested by default, and we don't want to pay the
1673 // cost of building mdbook, so they use `rustdoc --test` directly.
1674 // Also, the unstable book is special because SUMMARY.md is generated,
1675 // so it is easier to just run `rustdoc` on its files.
1676 if self.is_ext_doc {
1677 self.run_ext_doc(builder);
1679 self.run_local_doc(builder);
1685 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1686 /// which in turn runs `rustdoc --test` on each file in the book.
1687 fn run_ext_doc(self, builder: &Builder<'_>) {
1688 let compiler = self.compiler;
1690 builder.ensure(compile::Std::new(compiler, compiler.host));
1692 // mdbook just executes a binary named "rustdoc", so we need to update
1693 // PATH so that it points to our rustdoc.
1694 let mut rustdoc_path = builder.rustdoc(compiler);
1696 let old_path = env::var_os("PATH").unwrap_or_default();
1697 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1698 .expect("could not add rustdoc to PATH");
1700 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1701 let path = builder.src.join(&self.path);
1702 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1703 builder.add_rust_test_threads(&mut rustbook_cmd);
1704 builder.info(&format!("Testing rustbook {}", self.path.display()));
1705 let _time = util::timeit(&builder);
1706 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1711 builder.save_toolstate(self.name, toolstate);
1714 /// This runs `rustdoc --test` on all `.md` files in the path.
1715 fn run_local_doc(self, builder: &Builder<'_>) {
1716 let compiler = self.compiler;
1718 builder.ensure(compile::Std::new(compiler, compiler.host));
1720 // Do a breadth-first traversal of the `src/doc` directory and just run
1721 // tests for all files that end in `*.md`
1722 let mut stack = vec![builder.src.join(self.path)];
1723 let _time = util::timeit(&builder);
1724 let mut files = Vec::new();
1725 while let Some(p) = stack.pop() {
1727 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
1731 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1741 markdown_test(builder, compiler, &file);
1746 macro_rules! test_book {
1747 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1749 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1754 impl Step for $name {
1756 const DEFAULT: bool = $default;
1757 const ONLY_HOSTS: bool = true;
1759 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1763 fn make_run(run: RunConfig<'_>) {
1764 run.builder.ensure($name {
1765 compiler: run.builder.compiler(run.builder.top_stage, run.target),
1769 fn run(self, builder: &Builder<'_>) {
1770 builder.ensure(BookTest {
1771 compiler: self.compiler,
1772 path: PathBuf::from($path),
1774 is_ext_doc: !$default,
1783 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1784 Reference, "src/doc/reference", "reference", default=false;
1785 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
1786 RustcBook, "src/doc/rustc", "rustc", default=true;
1787 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
1788 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
1789 TheBook, "src/doc/book", "book", default=false;
1790 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
1791 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
1794 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1795 pub struct ErrorIndex {
1799 impl Step for ErrorIndex {
1801 const DEFAULT: bool = true;
1802 const ONLY_HOSTS: bool = true;
1804 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1805 run.path("src/tools/error_index_generator")
1808 fn make_run(run: RunConfig<'_>) {
1809 // error_index_generator depends on librustdoc. Use the compiler that
1810 // is normally used to build rustdoc for other tests (like compiletest
1811 // tests in src/test/rustdoc) so that it shares the same artifacts.
1812 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
1813 run.builder.ensure(ErrorIndex { compiler });
1816 /// Runs the error index generator tool to execute the tests located in the error
1819 /// The `error_index_generator` tool lives in `src/tools` and is used to
1820 /// generate a markdown file from the error indexes of the code base which is
1821 /// then passed to `rustdoc --test`.
1822 fn run(self, builder: &Builder<'_>) {
1823 let compiler = self.compiler;
1825 let dir = testdir(builder, compiler.host);
1826 t!(fs::create_dir_all(&dir));
1827 let output = dir.join("error-index.md");
1829 let mut tool = tool::ErrorIndex::command(builder);
1830 tool.arg("markdown").arg(&output);
1832 builder.info(&format!("Testing error-index stage{}", compiler.stage));
1833 let _time = util::timeit(&builder);
1834 builder.run_quiet(&mut tool);
1835 // The tests themselves need to link to std, so make sure it is
1837 builder.ensure(compile::Std::new(compiler, compiler.host));
1838 markdown_test(builder, compiler, &output);
1842 fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
1843 if let Ok(contents) = fs::read_to_string(markdown) {
1844 if !contents.contains("```") {
1849 builder.info(&format!("doc tests for: {}", markdown.display()));
1850 let mut cmd = builder.rustdoc_cmd(compiler);
1851 builder.add_rust_test_threads(&mut cmd);
1852 // allow for unstable options such as new editions
1854 cmd.arg("unstable-options");
1857 cmd.env("RUSTC_BOOTSTRAP", "1");
1859 let test_args = builder.config.cmd.test_args().join(" ");
1860 cmd.arg("--test-args").arg(test_args);
1862 if builder.config.verbose_tests {
1863 try_run(builder, &mut cmd)
1865 try_run_quiet(builder, &mut cmd)
1869 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1870 pub struct RustcGuide;
1872 impl Step for RustcGuide {
1874 const DEFAULT: bool = false;
1875 const ONLY_HOSTS: bool = true;
1877 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1878 run.path("src/doc/rustc-dev-guide")
1881 fn make_run(run: RunConfig<'_>) {
1882 run.builder.ensure(RustcGuide);
1885 fn run(self, builder: &Builder<'_>) {
1886 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1887 builder.update_submodule(&relative_path);
1889 let src = builder.src.join(relative_path);
1890 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1891 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1896 builder.save_toolstate("rustc-dev-guide", toolstate);
1900 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
1901 pub struct CrateLibrustc {
1903 target: TargetSelection,
1904 test_kind: TestKind,
1905 crates: Vec<Interned<String>>,
1908 impl Step for CrateLibrustc {
1910 const DEFAULT: bool = true;
1911 const ONLY_HOSTS: bool = true;
1913 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1914 run.crate_or_deps("rustc-main")
1917 fn make_run(run: RunConfig<'_>) {
1918 let builder = run.builder;
1919 let host = run.build_triple();
1920 let compiler = builder.compiler_for(builder.top_stage, host, host);
1924 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1926 let test_kind = builder.kind.into();
1928 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
1931 fn run(self, builder: &Builder<'_>) {
1932 builder.ensure(Crate {
1933 compiler: self.compiler,
1934 target: self.target,
1936 test_kind: self.test_kind,
1937 crates: self.crates,
1942 #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1944 pub compiler: Compiler,
1945 pub target: TargetSelection,
1947 pub test_kind: TestKind,
1948 pub crates: Vec<Interned<String>>,
1951 impl Step for Crate {
1953 const DEFAULT: bool = true;
1955 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1956 run.crate_or_deps("test")
1959 fn make_run(run: RunConfig<'_>) {
1960 let builder = run.builder;
1961 let host = run.build_triple();
1962 let compiler = builder.compiler_for(builder.top_stage, host, host);
1963 let test_kind = builder.kind.into();
1967 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1970 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
1973 /// Runs all unit tests plus documentation tests for a given crate defined
1974 /// by a `Cargo.toml` (single manifest)
1976 /// This is what runs tests for crates like the standard library, compiler, etc.
1977 /// It essentially is the driver for running `cargo test`.
1979 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1980 /// arguments, and those arguments are discovered from `cargo metadata`.
1981 fn run(self, builder: &Builder<'_>) {
1982 let compiler = self.compiler;
1983 let target = self.target;
1984 let mode = self.mode;
1985 let test_kind = self.test_kind;
1987 builder.ensure(compile::Std::new(compiler, target));
1988 builder.ensure(RemoteCopyLibs { compiler, target });
1990 // If we're not doing a full bootstrap but we're testing a stage2
1991 // version of libstd, then what we're actually testing is the libstd
1992 // produced in stage1. Reflect that here by updating the compiler that
1993 // we're working with automatically.
1994 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
1997 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2000 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2003 compile::rustc_cargo(builder, &mut cargo, target);
2005 _ => panic!("can only test libraries"),
2008 // Build up the base `cargo test` command.
2010 // Pass in some standard flags then iterate over the graph we've discovered
2011 // in `cargo metadata` with the maps above and figure out what `-p`
2012 // arguments need to get passed.
2013 if test_kind.subcommand() == "test" && !builder.fail_fast {
2014 cargo.arg("--no-fail-fast");
2016 match builder.doc_tests {
2021 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2026 for krate in &self.crates {
2027 cargo.arg("-p").arg(krate);
2030 // The tests are going to run with the *target* libraries, so we need to
2031 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2033 // Note that to run the compiler we need to run with the *host* libraries,
2034 // but our wrapper scripts arrange for that to be the case anyway.
2035 let mut dylib_path = dylib_path();
2036 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
2037 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2040 cargo.args(&builder.config.cmd.test_args());
2042 if !builder.config.verbose_tests {
2043 cargo.arg("--quiet");
2046 if target.contains("emscripten") {
2048 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2049 builder.config.nodejs.as_ref().expect("nodejs not configured"),
2051 } else if target.starts_with("wasm32") {
2052 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2054 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
2055 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
2056 } else if builder.remote_tested(target) {
2058 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
2059 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
2063 builder.info(&format!(
2064 "{} {:?} stage{} ({} -> {})",
2065 test_kind, self.crates, compiler.stage, &compiler.host, target
2067 let _time = util::timeit(&builder);
2068 try_run(builder, &mut cargo.into());
2072 /// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2073 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2074 pub struct CrateRustdoc {
2075 host: TargetSelection,
2076 test_kind: TestKind,
2079 impl Step for CrateRustdoc {
2081 const DEFAULT: bool = true;
2082 const ONLY_HOSTS: bool = true;
2084 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2085 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2088 fn make_run(run: RunConfig<'_>) {
2089 let builder = run.builder;
2091 let test_kind = builder.kind.into();
2093 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2096 fn run(self, builder: &Builder<'_>) {
2097 let test_kind = self.test_kind;
2098 let target = self.host;
2100 let compiler = if builder.download_rustc() {
2101 builder.compiler(builder.top_stage, target)
2103 // Use the previous stage compiler to reuse the artifacts that are
2104 // created when running compiletest for src/test/rustdoc. If this used
2105 // `compiler`, then it would cause rustdoc to be built *again*, which
2106 // isn't really necessary.
2107 builder.compiler_for(builder.top_stage, target, target)
2109 builder.ensure(compile::Rustc::new(compiler, target));
2111 let mut cargo = tool::prepare_tool_cargo(
2116 test_kind.subcommand(),
2117 "src/tools/rustdoc",
2121 if test_kind.subcommand() == "test" && !builder.fail_fast {
2122 cargo.arg("--no-fail-fast");
2124 match builder.doc_tests {
2129 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2134 cargo.arg("-p").arg("rustdoc:0.0.0");
2137 cargo.args(&builder.config.cmd.test_args());
2139 if self.host.contains("musl") {
2140 cargo.arg("'-Ctarget-feature=-crt-static'");
2143 // This is needed for running doctests on librustdoc. This is a bit of
2144 // an unfortunate interaction with how bootstrap works and how cargo
2145 // sets up the dylib path, and the fact that the doctest (in
2146 // html/markdown.rs) links to rustc-private libs. For stage1, the
2147 // compiler host dylibs (in stage1/lib) are not the same as the target
2148 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2149 // rust distribution where they are the same.
2151 // On the cargo side, normal tests use `target_process` which handles
2152 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2153 // case). However, for doctests it uses `rustdoc_process` which only
2154 // sets up the dylib path for the *host* (stage1/lib), which is the
2157 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2159 // It should be considered to just stop running doctests on
2160 // librustdoc. There is only one test, and it doesn't look too
2161 // important. There might be other ways to avoid this, but it seems
2162 // pretty convoluted.
2164 // See also https://github.com/rust-lang/rust/issues/13983 where the
2165 // host vs target dylibs for rustdoc are consistently tricky to deal
2168 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
2169 let libdir = if builder.download_rustc() {
2170 builder.rustc_libdir(compiler)
2172 builder.sysroot_libdir(compiler, target).to_path_buf()
2174 let mut dylib_path = dylib_path();
2175 dylib_path.insert(0, PathBuf::from(&*libdir));
2176 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2178 if !builder.config.verbose_tests {
2179 cargo.arg("--quiet");
2182 builder.info(&format!(
2183 "{} rustdoc stage{} ({} -> {})",
2184 test_kind, compiler.stage, &compiler.host, target
2186 let _time = util::timeit(&builder);
2188 try_run(builder, &mut cargo.into());
2192 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2193 pub struct CrateRustdocJsonTypes {
2194 host: TargetSelection,
2195 test_kind: TestKind,
2198 impl Step for CrateRustdocJsonTypes {
2200 const DEFAULT: bool = true;
2201 const ONLY_HOSTS: bool = true;
2203 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2204 run.path("src/rustdoc-json-types")
2207 fn make_run(run: RunConfig<'_>) {
2208 let builder = run.builder;
2210 let test_kind = builder.kind.into();
2212 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2215 fn run(self, builder: &Builder<'_>) {
2216 let test_kind = self.test_kind;
2217 let target = self.host;
2219 // Use the previous stage compiler to reuse the artifacts that are
2220 // created when running compiletest for src/test/rustdoc. If this used
2221 // `compiler`, then it would cause rustdoc to be built *again*, which
2222 // isn't really necessary.
2223 let compiler = builder.compiler_for(builder.top_stage, target, target);
2224 builder.ensure(compile::Rustc::new(compiler, target));
2226 let mut cargo = tool::prepare_tool_cargo(
2231 test_kind.subcommand(),
2232 "src/rustdoc-json-types",
2236 if test_kind.subcommand() == "test" && !builder.fail_fast {
2237 cargo.arg("--no-fail-fast");
2240 cargo.arg("-p").arg("rustdoc-json-types");
2243 cargo.args(&builder.config.cmd.test_args());
2245 if self.host.contains("musl") {
2246 cargo.arg("'-Ctarget-feature=-crt-static'");
2249 if !builder.config.verbose_tests {
2250 cargo.arg("--quiet");
2253 builder.info(&format!(
2254 "{} rustdoc-json-types stage{} ({} -> {})",
2255 test_kind, compiler.stage, &compiler.host, target
2257 let _time = util::timeit(&builder);
2259 try_run(builder, &mut cargo.into());
2263 /// Some test suites are run inside emulators or on remote devices, and most
2264 /// of our test binaries are linked dynamically which means we need to ship
2265 /// the standard library and such to the emulator ahead of time. This step
2266 /// represents this and is a dependency of all test suites.
2268 /// Most of the time this is a no-op. For some steps such as shipping data to
2269 /// QEMU we have to build our own tools so we've got conditional dependencies
2270 /// on those programs as well. Note that the remote test client is built for
2271 /// the build target (us) and the server is built for the target.
2272 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2273 pub struct RemoteCopyLibs {
2275 target: TargetSelection,
2278 impl Step for RemoteCopyLibs {
2281 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2285 fn run(self, builder: &Builder<'_>) {
2286 let compiler = self.compiler;
2287 let target = self.target;
2288 if !builder.remote_tested(target) {
2292 builder.ensure(compile::Std::new(compiler, target));
2294 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2296 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2298 // Spawn the emulator and wait for it to come online
2299 let tool = builder.tool_exe(Tool::RemoteTestClient);
2300 let mut cmd = Command::new(&tool);
2301 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
2302 if let Some(rootfs) = builder.qemu_rootfs(target) {
2305 builder.run(&mut cmd);
2307 // Push all our dylibs to the emulator
2308 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2310 let name = f.file_name().into_string().unwrap();
2311 if util::is_dylib(&name) {
2312 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2318 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2319 pub struct Distcheck;
2321 impl Step for Distcheck {
2324 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2325 run.alias("distcheck")
2328 fn make_run(run: RunConfig<'_>) {
2329 run.builder.ensure(Distcheck);
2332 /// Runs "distcheck", a 'make check' from a tarball
2333 fn run(self, builder: &Builder<'_>) {
2334 builder.info("Distcheck");
2335 let dir = builder.tempdir().join("distcheck");
2336 let _ = fs::remove_dir_all(&dir);
2337 t!(fs::create_dir_all(&dir));
2339 // Guarantee that these are built before we begin running.
2340 builder.ensure(dist::PlainSourceTarball);
2341 builder.ensure(dist::Src);
2343 let mut cmd = Command::new("tar");
2345 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
2346 .arg("--strip-components=1")
2348 builder.run(&mut cmd);
2350 Command::new("./configure")
2351 .args(&builder.config.configure_args)
2352 .arg("--enable-vendor")
2356 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
2359 // Now make sure that rust-src has all of libstd's dependencies
2360 builder.info("Distcheck rust-src");
2361 let dir = builder.tempdir().join("distcheck-src");
2362 let _ = fs::remove_dir_all(&dir);
2363 t!(fs::create_dir_all(&dir));
2365 let mut cmd = Command::new("tar");
2367 .arg(builder.ensure(dist::Src).tarball())
2368 .arg("--strip-components=1")
2370 builder.run(&mut cmd);
2372 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
2374 Command::new(&builder.initial_cargo)
2375 .arg("generate-lockfile")
2376 .arg("--manifest-path")
2383 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2384 pub struct Bootstrap;
2386 impl Step for Bootstrap {
2388 const DEFAULT: bool = true;
2389 const ONLY_HOSTS: bool = true;
2391 /// Tests the build system itself.
2392 fn run(self, builder: &Builder<'_>) {
2393 let mut check_bootstrap = Command::new(&builder.python());
2394 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2395 try_run(builder, &mut check_bootstrap);
2397 let mut cmd = Command::new(&builder.initial_cargo);
2399 .current_dir(builder.src.join("src/bootstrap"))
2400 .env("RUSTFLAGS", "-Cdebuginfo=2")
2401 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2402 .env("RUSTC_BOOTSTRAP", "1")
2403 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
2404 .env("RUSTC", &builder.initial_rustc);
2405 if let Some(flags) = option_env!("RUSTFLAGS") {
2406 // Use the same rustc flags for testing as for "normal" compilation,
2407 // so that Cargo doesn’t recompile the entire dependency graph every time:
2408 // https://github.com/rust-lang/rust/issues/49215
2409 cmd.env("RUSTFLAGS", flags);
2411 if !builder.fail_fast {
2412 cmd.arg("--no-fail-fast");
2414 match builder.doc_tests {
2419 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2424 cmd.arg("--").args(&builder.config.cmd.test_args());
2425 // rustbuild tests are racy on directory creation so just run them one at a time.
2426 // Since there's not many this shouldn't be a problem.
2427 cmd.arg("--test-threads=1");
2428 try_run(builder, &mut cmd);
2431 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2432 run.path("src/bootstrap")
2435 fn make_run(run: RunConfig<'_>) {
2436 run.builder.ensure(Bootstrap);
2440 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2441 pub struct TierCheck {
2442 pub compiler: Compiler,
2445 impl Step for TierCheck {
2447 const DEFAULT: bool = true;
2448 const ONLY_HOSTS: bool = true;
2450 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2451 run.path("src/tools/tier-check")
2454 fn make_run(run: RunConfig<'_>) {
2456 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2457 run.builder.ensure(TierCheck { compiler });
2460 /// Tests the Platform Support page in the rustc book.
2461 fn run(self, builder: &Builder<'_>) {
2462 builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
2463 let mut cargo = tool::prepare_tool_cargo(
2469 "src/tools/tier-check",
2473 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2474 cargo.arg(&builder.rustc(self.compiler));
2475 if builder.is_verbose() {
2476 cargo.arg("--verbose");
2479 builder.info("platform support check");
2480 try_run(builder, &mut cargo.into());
2484 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2485 pub struct ReplacePlaceholderTest;
2487 impl Step for ReplacePlaceholderTest {
2489 const ONLY_HOSTS: bool = true;
2490 const DEFAULT: bool = true;
2492 /// Ensure the version placeholder replacement tool builds
2493 fn run(self, builder: &Builder<'_>) {
2494 builder.info("build check for version replacement placeholder");
2496 // Test the version placeholder replacement tool itself.
2497 let bootstrap_host = builder.config.build;
2498 let compiler = builder.compiler(0, bootstrap_host);
2499 let cargo = tool::prepare_tool_cargo(
2502 Mode::ToolBootstrap,
2505 "src/tools/replace-version-placeholder",
2509 try_run(builder, &mut cargo.into());
2512 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2513 run.path("src/tools/replace-version-placeholder")
2516 fn make_run(run: RunConfig<'_>) {
2517 run.builder.ensure(Self);
2521 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2522 pub struct LintDocs {
2523 pub compiler: Compiler,
2524 pub target: TargetSelection,
2527 impl Step for LintDocs {
2529 const DEFAULT: bool = true;
2530 const ONLY_HOSTS: bool = true;
2532 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2533 run.path("src/tools/lint-docs")
2536 fn make_run(run: RunConfig<'_>) {
2537 run.builder.ensure(LintDocs {
2538 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2543 /// Tests that the lint examples in the rustc book generate the correct
2544 /// lints and have the expected format.
2545 fn run(self, builder: &Builder<'_>) {
2546 builder.ensure(crate::doc::RustcBook {
2547 compiler: self.compiler,
2548 target: self.target,