]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/test.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / bootstrap / test.rs
CommitLineData
2c00a5a8
XL
1//! Implementation of the test-related targets of the build system.
2//!
3//! This file implements the various regression test suites that we execute on
4//! our CI.
5
6use std::env;
7use std::ffi::OsString;
2c00a5a8 8use std::fmt;
0731742a 9use std::fs;
94b46f34
XL
10use std::iter;
11use std::path::{Path, PathBuf};
136023e0 12use std::process::{Command, Stdio};
2c00a5a8 13
0731742a 14use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
5869c6ff 15use crate::cache::Interned;
0731742a 16use crate::compile;
3dfed10e 17use crate::config::TargetSelection;
0731742a
XL
18use crate::dist;
19use crate::flags::Subcommand;
20use crate::native;
dfeec247 21use crate::tool::{self, SourceType, Tool};
0731742a 22use crate::toolstate::ToolState;
5e7ed085 23use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
5099ac24 24use crate::{envify, CLang, DocTests, GitRepo, Mode};
2c00a5a8
XL
25
26const ADB_TEST_DIR: &str = "/data/tmp/work";
27
28/// The two modes of the test runner; tests or benchmarks.
83c7162d 29#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
2c00a5a8 30pub enum TestKind {
9fa01778 31 /// Run `cargo test`.
2c00a5a8 32 Test,
9fa01778 33 /// Run `cargo bench`.
2c00a5a8
XL
34 Bench,
35}
36
94b46f34
XL
37impl From<Kind> for TestKind {
38 fn from(kind: Kind) -> Self {
39 match kind {
40 Kind::Test => TestKind::Test,
41 Kind::Bench => TestKind::Bench,
42 _ => panic!("unexpected kind in crate: {:?}", kind),
43 }
44 }
45}
46
2c00a5a8
XL
47impl TestKind {
48 // Return the cargo subcommand for this test kind
49 fn subcommand(self) -> &'static str {
50 match self {
51 TestKind::Test => "test",
52 TestKind::Bench => "bench",
53 }
54 }
55}
56
57impl fmt::Display for TestKind {
9fa01778 58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2c00a5a8
XL
59 f.write_str(match *self {
60 TestKind::Test => "Testing",
61 TestKind::Bench => "Benchmarking",
62 })
63 }
64}
65
9fa01778 66fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
83c7162d
XL
67 if !builder.fail_fast {
68 if !builder.try_run(cmd) {
69 let mut failures = builder.delayed_failures.borrow_mut();
2c00a5a8
XL
70 failures.push(format!("{:?}", cmd));
71 return false;
72 }
73 } else {
83c7162d 74 builder.run(cmd);
2c00a5a8
XL
75 }
76 true
77}
78
9fa01778 79fn try_run_quiet(builder: &Builder<'_>, cmd: &mut Command) -> bool {
83c7162d
XL
80 if !builder.fail_fast {
81 if !builder.try_run_quiet(cmd) {
82 let mut failures = builder.delayed_failures.borrow_mut();
2c00a5a8 83 failures.push(format!("{:?}", cmd));
0531ce1d 84 return false;
2c00a5a8
XL
85 }
86 } else {
83c7162d 87 builder.run_quiet(cmd);
2c00a5a8 88 }
0531ce1d 89 true
2c00a5a8
XL
90}
91
92#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
93pub struct Linkcheck {
3dfed10e 94 host: TargetSelection,
2c00a5a8
XL
95}
96
97impl Step for Linkcheck {
98 type Output = ();
99 const ONLY_HOSTS: bool = true;
100 const DEFAULT: bool = true;
101
102 /// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
103 ///
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.
9fa01778 106 fn run(self, builder: &Builder<'_>) {
2c00a5a8 107 let host = self.host;
cdc7bbd5
XL
108 let hosts = &builder.hosts;
109 let targets = &builder.targets;
110
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() {
116 panic!(
117 "Linkcheck currently does not support builds with different hosts and targets.
118You can skip linkcheck with --exclude src/tools/linkchecker"
119 );
120 }
2c00a5a8 121
83c7162d 122 builder.info(&format!("Linkcheck ({})", host));
2c00a5a8 123
136023e0
XL
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(
128 builder,
129 compiler,
130 Mode::ToolBootstrap,
131 bootstrap_host,
132 "test",
133 "src/tools/linkchecker",
134 SourceType::InTree,
135 &[],
136 );
137 try_run(builder, &mut cargo.into());
138
139 // Build all the default documentation.
6a06907d 140 builder.default_doc(&[]);
2c00a5a8 141
136023e0 142 // Run the linkchecker.
83c7162d 143 let _time = util::timeit(&builder);
94b46f34
XL
144 try_run(
145 builder,
3dfed10e 146 builder.tool_cmd(Tool::Linkchecker).arg(builder.out.join(host.triple).join("doc")),
94b46f34 147 );
2c00a5a8
XL
148 }
149
9fa01778 150 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8 151 let builder = run.builder;
cdc7bbd5
XL
152 let run = run.path("src/tools/linkchecker");
153 run.default_condition(builder.config.docs)
2c00a5a8
XL
154 }
155
9fa01778 156 fn make_run(run: RunConfig<'_>) {
2c00a5a8
XL
157 run.builder.ensure(Linkcheck { host: run.target });
158 }
159}
160
136023e0
XL
161fn check_if_tidy_is_installed() -> bool {
162 Command::new("tidy")
163 .arg("--version")
164 .stdout(Stdio::null())
165 .status()
166 .map_or(false, |status| status.success())
167}
168
169#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
170pub struct HtmlCheck {
171 target: TargetSelection,
172}
173
174impl Step for HtmlCheck {
175 type Output = ();
176 const DEFAULT: bool = true;
177 const ONLY_HOSTS: bool = true;
178
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))
182 }
183
184 fn make_run(run: RunConfig<'_>) {
185 run.builder.ensure(HtmlCheck { target: run.target });
186 }
187
188 fn run(self, builder: &Builder<'_>) {
189 if !check_if_tidy_is_installed() {
190 eprintln!("not running HTML-check tool because `tidy` is missing");
191 eprintln!(
192 "Note that `tidy` is not the in-tree `src/tools/tidy` but needs to be installed"
193 );
194 panic!("Cannot run html-check tests");
195 }
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 });
199
200 try_run(builder, builder.tool_cmd(Tool::HtmlChecker).arg(builder.doc_out(self.target)));
201 }
202}
203
2c00a5a8
XL
204#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
205pub struct Cargotest {
206 stage: u32,
3dfed10e 207 host: TargetSelection,
2c00a5a8
XL
208}
209
210impl Step for Cargotest {
211 type Output = ();
212 const ONLY_HOSTS: bool = true;
213
9fa01778 214 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
215 run.path("src/tools/cargotest")
216 }
217
9fa01778 218 fn make_run(run: RunConfig<'_>) {
dfeec247 219 run.builder.ensure(Cargotest { stage: run.builder.top_stage, host: run.target });
2c00a5a8
XL
220 }
221
222 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
223 ///
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.
9fa01778 226 fn run(self, builder: &Builder<'_>) {
2c00a5a8 227 let compiler = builder.compiler(self.stage, self.host);
dfeec247 228 builder.ensure(compile::Rustc { compiler, target: compiler.host });
f035d41b 229 let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
2c00a5a8
XL
230
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.
83c7162d 234 let out_dir = builder.out.join("ct");
2c00a5a8
XL
235 t!(fs::create_dir_all(&out_dir));
236
83c7162d 237 let _time = util::timeit(&builder);
2c00a5a8 238 let mut cmd = builder.tool_cmd(Tool::CargoTest);
94b46f34
XL
239 try_run(
240 builder,
f035d41b 241 cmd.arg(&cargo)
94b46f34 242 .arg(&out_dir)
17df50a5 243 .args(builder.config.cmd.test_args())
94b46f34 244 .env("RUSTC", builder.rustc(compiler))
532ac7d7 245 .env("RUSTDOC", builder.rustdoc(compiler)),
94b46f34 246 );
2c00a5a8
XL
247 }
248}
249
250#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
251pub struct Cargo {
252 stage: u32,
3dfed10e 253 host: TargetSelection,
2c00a5a8
XL
254}
255
256impl Step for Cargo {
257 type Output = ();
258 const ONLY_HOSTS: bool = true;
259
9fa01778 260 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
261 run.path("src/tools/cargo")
262 }
263
9fa01778 264 fn make_run(run: RunConfig<'_>) {
dfeec247 265 run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
2c00a5a8
XL
266 }
267
268 /// Runs `cargo test` for `cargo` packaged with Rust.
9fa01778 269 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
270 let compiler = builder.compiler(self.stage, self.host);
271
dfeec247
XL
272 builder.ensure(tool::Cargo { compiler, target: self.host });
273 let mut cargo = tool::prepare_tool_cargo(
274 builder,
94b46f34 275 compiler,
dfeec247
XL
276 Mode::ToolRustc,
277 self.host,
278 "test",
279 "src/tools/cargo",
280 SourceType::Submodule,
281 &[],
282 );
8faf50e0 283
83c7162d 284 if !builder.fail_fast {
2c00a5a8
XL
285 cargo.arg("--no-fail-fast");
286 }
6a06907d 287 cargo.arg("--").args(builder.config.cmd.test_args());
2c00a5a8 288
2c00a5a8
XL
289 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
290 // available.
291 cargo.env("CFG_DISABLE_CROSS_TESTS", "1");
b7449926
XL
292 // Disable a test that has issues with mingw.
293 cargo.env("CARGO_TEST_DISABLE_GIT_CLI", "1");
416331ca
XL
294 // Forcibly disable tests using nightly features since any changes to
295 // those features won't be able to land.
296 cargo.env("CARGO_TEST_DISABLE_NIGHTLY", "1");
2c00a5a8 297
e1599b0c
XL
298 cargo.env("PATH", &path_for_cargo(builder, compiler));
299
300 try_run(builder, &mut cargo.into());
2c00a5a8
XL
301 }
302}
303
304#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
305pub struct Rls {
306 stage: u32,
3dfed10e 307 host: TargetSelection,
2c00a5a8
XL
308}
309
310impl Step for Rls {
311 type Output = ();
312 const ONLY_HOSTS: bool = true;
313
9fa01778 314 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
315 run.path("src/tools/rls")
316 }
317
9fa01778 318 fn make_run(run: RunConfig<'_>) {
dfeec247 319 run.builder.ensure(Rls { stage: run.builder.top_stage, host: run.target });
2c00a5a8
XL
320 }
321
322 /// Runs `cargo test` for the rls.
9fa01778 323 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
324 let stage = self.stage;
325 let host = self.host;
326 let compiler = builder.compiler(stage, host);
327
dfeec247
XL
328 let build_result =
329 builder.ensure(tool::Rls { compiler, target: self.host, extra_features: Vec::new() });
83c7162d
XL
330 if build_result.is_none() {
331 eprintln!("failed to test rls: could not build");
332 return;
333 }
334
dfeec247
XL
335 let mut cargo = tool::prepare_tool_cargo(
336 builder,
337 compiler,
338 Mode::ToolRustc,
339 host,
340 "test",
341 "src/tools/rls",
342 SourceType::Submodule,
343 &[],
344 );
2c00a5a8 345
1b1a35ee 346 cargo.add_rustc_lib_path(builder, compiler);
dfeec247 347 cargo.arg("--").args(builder.config.cmd.test_args());
2c00a5a8 348
e1599b0c 349 if try_run(builder, &mut cargo.into()) {
83c7162d 350 builder.save_toolstate("rls", ToolState::TestPass);
2c00a5a8
XL
351 }
352 }
353}
354
355#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
356pub struct Rustfmt {
357 stage: u32,
3dfed10e 358 host: TargetSelection,
2c00a5a8
XL
359}
360
361impl Step for Rustfmt {
362 type Output = ();
363 const ONLY_HOSTS: bool = true;
364
9fa01778 365 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
366 run.path("src/tools/rustfmt")
367 }
368
9fa01778 369 fn make_run(run: RunConfig<'_>) {
dfeec247 370 run.builder.ensure(Rustfmt { stage: run.builder.top_stage, host: run.target });
2c00a5a8
XL
371 }
372
373 /// Runs `cargo test` for rustfmt.
9fa01778 374 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
375 let stage = self.stage;
376 let host = self.host;
377 let compiler = builder.compiler(stage, host);
378
17df50a5
XL
379 builder
380 .ensure(tool::Rustfmt { compiler, target: self.host, extra_features: Vec::new() })
381 .expect("in-tree tool");
83c7162d 382
dfeec247
XL
383 let mut cargo = tool::prepare_tool_cargo(
384 builder,
385 compiler,
386 Mode::ToolRustc,
387 host,
388 "test",
389 "src/tools/rustfmt",
c295e0f8 390 SourceType::InTree,
dfeec247
XL
391 &[],
392 );
2c00a5a8 393
83c7162d
XL
394 let dir = testdir(builder, compiler.host);
395 t!(fs::create_dir_all(&dir));
396 cargo.env("RUSTFMT_TEST_DIR", dir);
2c00a5a8 397
1b1a35ee 398 cargo.add_rustc_lib_path(builder, compiler);
2c00a5a8 399
17df50a5 400 builder.run(&mut cargo.into());
2c00a5a8
XL
401 }
402}
403
cdc7bbd5
XL
404#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
405pub struct RustDemangler {
406 stage: u32,
407 host: TargetSelection,
408}
409
410impl Step for RustDemangler {
411 type Output = ();
412 const ONLY_HOSTS: bool = true;
413
414 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
415 run.path("src/tools/rust-demangler")
416 }
417
418 fn make_run(run: RunConfig<'_>) {
419 run.builder.ensure(RustDemangler { stage: run.builder.top_stage, host: run.target });
420 }
421
422 /// Runs `cargo test` for rust-demangler.
423 fn run(self, builder: &Builder<'_>) {
424 let stage = self.stage;
425 let host = self.host;
426 let compiler = builder.compiler(stage, host);
427
428 let rust_demangler = builder
429 .ensure(tool::RustDemangler { compiler, target: self.host, extra_features: Vec::new() })
430 .expect("in-tree tool");
431 let mut cargo = tool::prepare_tool_cargo(
432 builder,
433 compiler,
434 Mode::ToolRustc,
435 host,
436 "test",
437 "src/tools/rust-demangler",
438 SourceType::InTree,
439 &[],
440 );
441
442 let dir = testdir(builder, compiler.host);
443 t!(fs::create_dir_all(&dir));
444
445 cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
446
447 cargo.arg("--").args(builder.config.cmd.test_args());
448
449 cargo.add_rustc_lib_path(builder, compiler);
450
451 builder.run(&mut cargo.into());
452 }
453}
454
2c00a5a8
XL
455#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
456pub struct Miri {
457 stage: u32,
3dfed10e 458 host: TargetSelection,
2c00a5a8
XL
459}
460
461impl Step for Miri {
462 type Output = ();
463 const ONLY_HOSTS: bool = true;
2c00a5a8 464
9fa01778 465 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
416331ca 466 run.path("src/tools/miri")
2c00a5a8
XL
467 }
468
9fa01778 469 fn make_run(run: RunConfig<'_>) {
dfeec247 470 run.builder.ensure(Miri { stage: run.builder.top_stage, host: run.target });
2c00a5a8
XL
471 }
472
473 /// Runs `cargo test` for miri.
9fa01778 474 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
475 let stage = self.stage;
476 let host = self.host;
477 let compiler = builder.compiler(stage, host);
478
dfeec247
XL
479 let miri =
480 builder.ensure(tool::Miri { compiler, target: self.host, extra_features: Vec::new() });
f9f354fc
XL
481 let cargo_miri = builder.ensure(tool::CargoMiri {
482 compiler,
483 target: self.host,
484 extra_features: Vec::new(),
485 });
486 if let (Some(miri), Some(_cargo_miri)) = (miri, cargo_miri) {
f035d41b
XL
487 let mut cargo =
488 builder.cargo(compiler, Mode::ToolRustc, SourceType::Submodule, host, "install");
e74abb32
XL
489 cargo.arg("xargo");
490 // Configure `cargo install` path. cargo adds a `bin/`.
491 cargo.env("CARGO_INSTALL_ROOT", &builder.out);
492
493 let mut cargo = Command::from(cargo);
494 if !try_run(builder, &mut cargo) {
495 return;
496 }
497
416331ca 498 // # Run `cargo miri setup`.
416331ca
XL
499 let mut cargo = tool::prepare_tool_cargo(
500 builder,
501 compiler,
502 Mode::ToolRustc,
503 host,
504 "run",
f9f354fc 505 "src/tools/miri/cargo-miri",
416331ca
XL
506 SourceType::Submodule,
507 &[],
508 );
17df50a5 509 cargo.add_rustc_lib_path(builder, compiler);
f9f354fc 510 cargo.arg("--").arg("miri").arg("setup");
dfeec247 511
416331ca 512 // Tell `cargo miri setup` where to find the sources.
3dfed10e 513 cargo.env("XARGO_RUST_SRC", builder.src.join("library"));
f9f354fc
XL
514 // Tell it where to find Miri.
515 cargo.env("MIRI", &miri);
416331ca
XL
516 // Debug things.
517 cargo.env("RUST_BACKTRACE", "1");
e74abb32 518 // Let cargo-miri know where xargo ended up.
74b04a01 519 cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));
416331ca 520
e1599b0c 521 let mut cargo = Command::from(cargo);
416331ca
XL
522 if !try_run(builder, &mut cargo) {
523 return;
524 }
525
526 // # Determine where Miri put its sysroot.
74b04a01 527 // To this end, we run `cargo miri setup --print-sysroot` and capture the output.
416331ca
XL
528 // (We do this separately from the above so that when the setup actually
529 // happens we get some output.)
530 // We re-use the `cargo` from above.
e74abb32 531 cargo.arg("--print-sysroot");
416331ca
XL
532
533 // FIXME: Is there a way in which we can re-use the usual `run` helpers?
534 let miri_sysroot = if builder.config.dry_run {
535 String::new()
536 } else {
537 builder.verbose(&format!("running: {:?}", cargo));
dfeec247
XL
538 let out = cargo
539 .output()
416331ca
XL
540 .expect("We already ran `cargo miri setup` before and that worked");
541 assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
e74abb32 542 // Output is "<sysroot>\n".
416331ca
XL
543 let stdout = String::from_utf8(out.stdout)
544 .expect("`cargo miri setup` stdout is not valid UTF-8");
e74abb32
XL
545 let sysroot = stdout.trim_end();
546 builder.verbose(&format!("`cargo miri setup --print-sysroot` said: {:?}", sysroot));
416331ca
XL
547 sysroot.to_owned()
548 };
549
550 // # Run `cargo test`.
551 let mut cargo = tool::prepare_tool_cargo(
552 builder,
553 compiler,
554 Mode::ToolRustc,
555 host,
556 "test",
557 "src/tools/miri",
558 SourceType::Submodule,
559 &[],
560 );
17df50a5 561 cargo.add_rustc_lib_path(builder, compiler);
2c00a5a8 562
2c00a5a8 563 // miri tests need to know about the stage sysroot
416331ca 564 cargo.env("MIRI_SYSROOT", miri_sysroot);
2c00a5a8 565 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
f9f354fc
XL
566 cargo.env("MIRI", miri);
567
568 cargo.arg("--").args(builder.config.cmd.test_args());
2c00a5a8 569
cdc7bbd5
XL
570 let mut cargo = Command::from(cargo);
571 if !try_run(builder, &mut cargo) {
572 return;
573 }
574
416331ca
XL
575 // # Done!
576 builder.save_toolstate("miri", ToolState::TestPass);
2c00a5a8
XL
577 } else {
578 eprintln!("failed to test miri: could not build");
579 }
580 }
581}
582
0731742a
XL
583#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
584pub struct CompiletestTest {
3dfed10e 585 host: TargetSelection,
0731742a
XL
586}
587
588impl Step for CompiletestTest {
589 type Output = ();
590
9fa01778 591 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
0731742a
XL
592 run.path("src/tools/compiletest")
593 }
594
9fa01778 595 fn make_run(run: RunConfig<'_>) {
dfeec247 596 run.builder.ensure(CompiletestTest { host: run.target });
0731742a
XL
597 }
598
599 /// Runs `cargo test` for compiletest.
9fa01778 600 fn run(self, builder: &Builder<'_>) {
0731742a 601 let host = self.host;
532ac7d7 602 let compiler = builder.compiler(0, host);
0731742a 603
fc512014
XL
604 // We need `ToolStd` for the locally-built sysroot because
605 // compiletest uses unstable features of the `test` crate.
606 builder.ensure(compile::Std { compiler, target: host });
dfeec247
XL
607 let cargo = tool::prepare_tool_cargo(
608 builder,
609 compiler,
fc512014 610 Mode::ToolStd,
dfeec247
XL
611 host,
612 "test",
613 "src/tools/compiletest",
614 SourceType::InTree,
615 &[],
616 );
0731742a 617
e1599b0c 618 try_run(builder, &mut cargo.into());
0731742a
XL
619 }
620}
621
2c00a5a8
XL
622#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
623pub struct Clippy {
624 stage: u32,
3dfed10e 625 host: TargetSelection,
2c00a5a8
XL
626}
627
628impl Step for Clippy {
629 type Output = ();
630 const ONLY_HOSTS: bool = true;
631 const DEFAULT: bool = false;
632
9fa01778 633 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
634 run.path("src/tools/clippy")
635 }
636
9fa01778 637 fn make_run(run: RunConfig<'_>) {
dfeec247 638 run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
2c00a5a8
XL
639 }
640
641 /// Runs `cargo test` for clippy.
9fa01778 642 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
643 let stage = self.stage;
644 let host = self.host;
645 let compiler = builder.compiler(stage, host);
646
c295e0f8 647 builder
f9f354fc
XL
648 .ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
649 .expect("in-tree tool");
650 let mut cargo = tool::prepare_tool_cargo(
651 builder,
0531ce1d 652 compiler,
f9f354fc
XL
653 Mode::ToolRustc,
654 host,
655 "test",
656 "src/tools/clippy",
657 SourceType::InTree,
658 &[],
659 );
2c00a5a8 660
f9f354fc
XL
661 cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
662 cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
663 let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
f9f354fc 664 cargo.env("HOST_LIBS", host_libs);
2c00a5a8 665
f9f354fc 666 cargo.arg("--").args(builder.config.cmd.test_args());
2c00a5a8 667
1b1a35ee 668 cargo.add_rustc_lib_path(builder, compiler);
f9f354fc 669
cdc7bbd5
XL
670 if builder.try_run(&mut cargo.into()) {
671 // The tests succeeded; nothing to do.
672 return;
673 }
674
675 if !builder.config.cmd.bless() {
676 std::process::exit(1);
677 }
678
679 let mut cargo = builder.cargo(compiler, Mode::ToolRustc, SourceType::InTree, host, "run");
680 cargo.arg("-p").arg("clippy_dev");
681 // clippy_dev gets confused if it can't find `clippy/Cargo.toml`
682 cargo.current_dir(&builder.src.join("src").join("tools").join("clippy"));
683 if builder.config.rust_optimize {
684 cargo.env("PROFILE", "release");
685 } else {
686 cargo.env("PROFILE", "debug");
687 }
688 cargo.arg("--");
689 cargo.arg("bless");
f035d41b 690 builder.run(&mut cargo.into());
2c00a5a8
XL
691 }
692}
693
9fa01778 694fn path_for_cargo(builder: &Builder<'_>, compiler: Compiler) -> OsString {
2c00a5a8
XL
695 // Configure PATH to find the right rustc. NB. we have to use PATH
696 // and not RUSTC because the Cargo test suite has tests that will
697 // fail if rustc is not spelled `rustc`.
698 let path = builder.sysroot(compiler).join("bin");
699 let old_path = env::var_os("PATH").unwrap_or_default();
700 env::join_paths(iter::once(path).chain(env::split_paths(&old_path))).expect("")
701}
702
703#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
704pub struct RustdocTheme {
705 pub compiler: Compiler,
706}
707
708impl Step for RustdocTheme {
709 type Output = ();
710 const DEFAULT: bool = true;
711 const ONLY_HOSTS: bool = true;
712
9fa01778 713 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
714 run.path("src/tools/rustdoc-themes")
715 }
716
9fa01778 717 fn make_run(run: RunConfig<'_>) {
1b1a35ee 718 let compiler = run.builder.compiler(run.builder.top_stage, run.target);
2c00a5a8 719
a1dfa0c6 720 run.builder.ensure(RustdocTheme { compiler });
2c00a5a8
XL
721 }
722
9fa01778 723 fn run(self, builder: &Builder<'_>) {
5e7ed085 724 let rustdoc = builder.bootstrap_out.join("rustdoc");
2c00a5a8
XL
725 let mut cmd = builder.tool_cmd(Tool::RustdocTheme);
726 cmd.arg(rustdoc.to_str().unwrap())
136023e0 727 .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap())
94b46f34
XL
728 .env("RUSTC_STAGE", self.compiler.stage.to_string())
729 .env("RUSTC_SYSROOT", builder.sysroot(self.compiler))
dfeec247 730 .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host))
94b46f34 731 .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
532ac7d7 732 .env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
94b46f34 733 .env("RUSTC_BOOTSTRAP", "1");
1b1a35ee
XL
734 if let Some(linker) = builder.linker(self.compiler.host) {
735 cmd.env("RUSTDOC_LINKER", linker);
736 }
737 if builder.is_fuse_ld_lld(self.compiler.host) {
738 cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
2c00a5a8 739 }
83c7162d 740 try_run(builder, &mut cmd);
2c00a5a8
XL
741 }
742}
743
744#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
9fa01778 745pub struct RustdocJSStd {
3dfed10e 746 pub target: TargetSelection,
2c00a5a8
XL
747}
748
9fa01778 749impl Step for RustdocJSStd {
2c00a5a8
XL
750 type Output = ();
751 const DEFAULT: bool = true;
752 const ONLY_HOSTS: bool = true;
753
9fa01778 754 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
3c0e092e 755 run.suite_path("src/test/rustdoc-js-std")
2c00a5a8
XL
756 }
757
9fa01778 758 fn make_run(run: RunConfig<'_>) {
ba9703b0 759 run.builder.ensure(RustdocJSStd { target: run.target });
2c00a5a8
XL
760 }
761
9fa01778 762 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
763 if let Some(ref nodejs) = builder.config.nodejs {
764 let mut command = Command::new(nodejs);
ba9703b0
XL
765 command
766 .arg(builder.src.join("src/tools/rustdoc-js/tester.js"))
767 .arg("--crate-name")
768 .arg("std")
769 .arg("--resource-suffix")
1b1a35ee 770 .arg(&builder.version)
ba9703b0
XL
771 .arg("--doc-folder")
772 .arg(builder.doc_out(self.target))
773 .arg("--test-folder")
774 .arg(builder.src.join("src/test/rustdoc-js-std"));
3c0e092e
XL
775 for path in &builder.paths {
776 if let Some(p) =
777 util::is_valid_test_suite_arg(path, "src/test/rustdoc-js-std", builder)
778 {
779 if !p.ends_with(".js") {
780 eprintln!("A non-js file was given: `{}`", path.display());
781 panic!("Cannot run rustdoc-js-std tests");
782 }
783 command.arg("--test-file").arg(path);
784 }
785 }
dfeec247 786 builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
2c00a5a8 787 builder.run(&mut command);
9fa01778 788 } else {
dfeec247 789 builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");
9fa01778
XL
790 }
791 }
792}
793
794#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
795pub struct RustdocJSNotStd {
3dfed10e 796 pub target: TargetSelection,
9fa01778
XL
797 pub compiler: Compiler,
798}
799
800impl Step for RustdocJSNotStd {
801 type Output = ();
802 const DEFAULT: bool = true;
803 const ONLY_HOSTS: bool = true;
804
805 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
3c0e092e 806 run.suite_path("src/test/rustdoc-js")
9fa01778
XL
807 }
808
809 fn make_run(run: RunConfig<'_>) {
1b1a35ee
XL
810 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
811 run.builder.ensure(RustdocJSNotStd { target: run.target, compiler });
9fa01778
XL
812 }
813
814 fn run(self, builder: &Builder<'_>) {
815 if builder.config.nodejs.is_some() {
816 builder.ensure(Compiletest {
817 compiler: self.compiler,
818 target: self.target,
819 mode: "js-doc-test",
820 suite: "rustdoc-js",
74b04a01 821 path: "src/test/rustdoc-js",
9fa01778
XL
822 compare_mode: None,
823 });
2c00a5a8 824 } else {
dfeec247 825 builder.info("No nodejs found, skipping \"src/test/rustdoc-js\" tests");
2c00a5a8
XL
826 }
827 }
828}
829
5e7ed085 830fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
17df50a5 831 let mut command = Command::new(&npm);
5e7ed085 832 command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
17df50a5
XL
833 if global {
834 command.arg("--global");
835 }
836 let lines = command
837 .output()
838 .map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
839 .unwrap_or(String::new());
5e7ed085
FG
840 lines.lines().find_map(|l| l.split(":browser-ui-test@").skip(1).next()).map(|v| v.to_owned())
841}
842
843fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
844 get_browser_ui_test_version_inner(npm, false)
845 .or_else(|| get_browser_ui_test_version_inner(npm, true))
17df50a5
XL
846}
847
5e7ed085
FG
848fn compare_browser_ui_test_version(installed_version: &str, src: &Path) {
849 match fs::read_to_string(
850 src.join("src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version"),
851 ) {
852 Ok(v) => {
853 if v.trim() != installed_version {
854 eprintln!(
855 "⚠️ Installed version of browser-ui-test (`{}`) is different than the \
856 one used in the CI (`{}`)",
857 installed_version, v
858 );
859 }
860 }
861 Err(e) => eprintln!("Couldn't find the CI browser-ui-test version: {:?}", e),
862 }
17df50a5
XL
863}
864
6a06907d
XL
865#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
866pub struct RustdocGUI {
867 pub target: TargetSelection,
868 pub compiler: Compiler,
869}
870
871impl Step for RustdocGUI {
872 type Output = ();
873 const DEFAULT: bool = true;
874 const ONLY_HOSTS: bool = true;
875
876 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
17df50a5 877 let builder = run.builder;
136023e0
XL
878 let run = run.suite_path("src/test/rustdoc-gui");
879 run.lazy_default_condition(Box::new(move || {
17df50a5
XL
880 builder.config.nodejs.is_some()
881 && builder
882 .config
883 .npm
884 .as_ref()
5e7ed085 885 .map(|p| get_browser_ui_test_version(p).is_some())
136023e0
XL
886 .unwrap_or(false)
887 }))
6a06907d
XL
888 }
889
890 fn make_run(run: RunConfig<'_>) {
891 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
892 run.builder.ensure(RustdocGUI { target: run.target, compiler });
893 }
894
895 fn run(self, builder: &Builder<'_>) {
17df50a5
XL
896 let nodejs = builder.config.nodejs.as_ref().expect("nodejs isn't available");
897 let npm = builder.config.npm.as_ref().expect("npm isn't available");
6a06907d 898
17df50a5
XL
899 builder.ensure(compile::Std { compiler: self.compiler, target: self.target });
900
901 // The goal here is to check if the necessary packages are installed, and if not, we
902 // panic.
5e7ed085
FG
903 match get_browser_ui_test_version(&npm) {
904 Some(version) => {
905 // We also check the version currently used in CI and emit a warning if it's not the
906 // same one.
907 compare_browser_ui_test_version(&version, &builder.build.src);
908 }
909 None => {
910 eprintln!(
911 "error: rustdoc-gui test suite cannot be run because npm `browser-ui-test` \
912 dependency is missing",
913 );
914 eprintln!(
915 "If you want to install the `{0}` dependency, run `npm install {0}`",
916 "browser-ui-test",
917 );
918 panic!("Cannot run rustdoc-gui tests");
919 }
17df50a5 920 }
6a06907d 921
17df50a5 922 let out_dir = builder.test_out(self.target).join("rustdoc-gui");
6a06907d 923
17df50a5 924 // We remove existing folder to be sure there won't be artifacts remaining.
c295e0f8 925 builder.clear_if_dirty(&out_dir, &builder.rustdoc(self.compiler));
17df50a5 926
136023e0 927 let src_path = builder.build.src.join("src/test/rustdoc-gui/src");
17df50a5 928 // We generate docs for the libraries present in the rustdoc-gui's src folder.
136023e0
XL
929 for entry in src_path.read_dir().expect("read_dir call failed") {
930 if let Ok(entry) = entry {
931 let path = entry.path();
932
933 if !path.is_dir() {
934 continue;
935 }
936
937 let mut cargo = Command::new(&builder.initial_cargo);
938 cargo
939 .arg("doc")
940 .arg("--target-dir")
941 .arg(&out_dir)
942 .env("RUSTDOC", builder.rustdoc(self.compiler))
943 .env("RUSTC", builder.rustc(self.compiler))
944 .current_dir(path);
c295e0f8
XL
945 // FIXME: implement a `// compile-flags` command or similar
946 // instead of hard-coding this test
947 if entry.file_name() == "link_to_definition" {
948 cargo.env("RUSTDOCFLAGS", "-Zunstable-options --generate-link-to-definition");
949 }
136023e0 950 builder.run(&mut cargo);
6a06907d 951 }
6a06907d 952 }
17df50a5
XL
953
954 // We now run GUI tests.
955 let mut command = Command::new(&nodejs);
956 command
957 .arg(builder.build.src.join("src/tools/rustdoc-gui/tester.js"))
94222f64
XL
958 .arg("--jobs")
959 .arg(&builder.jobs().to_string())
17df50a5 960 .arg("--doc-folder")
136023e0 961 .arg(out_dir.join("doc"))
17df50a5
XL
962 .arg("--tests-folder")
963 .arg(builder.build.src.join("src/test/rustdoc-gui"));
136023e0 964 for path in &builder.paths {
3c0e092e
XL
965 if let Some(p) = util::is_valid_test_suite_arg(path, "src/test/rustdoc-gui", builder) {
966 if !p.ends_with(".goml") {
967 eprintln!("A non-goml file was given: `{}`", path.display());
968 panic!("Cannot run rustdoc-gui tests");
969 }
970 if let Some(name) = path.file_name().and_then(|f| f.to_str()) {
136023e0
XL
971 command.arg("--file").arg(name);
972 }
973 }
974 }
975 for test_arg in builder.config.cmd.test_args() {
976 command.arg(test_arg);
977 }
17df50a5 978 builder.run(&mut command);
6a06907d
XL
979 }
980}
981
2c00a5a8 982#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
0531ce1d 983pub struct Tidy;
2c00a5a8
XL
984
985impl Step for Tidy {
986 type Output = ();
987 const DEFAULT: bool = true;
988 const ONLY_HOSTS: bool = true;
2c00a5a8 989
0531ce1d 990 /// Runs the `tidy` tool.
2c00a5a8
XL
991 ///
992 /// This tool in `src/tools` checks up on various bits and pieces of style and
993 /// otherwise just implements a few lint-like checks that are specific to the
994 /// compiler itself.
dfeec247
XL
995 ///
996 /// Once tidy passes, this step also runs `fmt --check` if tests are being run
997 /// for the `dev` or `nightly` channels.
9fa01778 998 fn run(self, builder: &Builder<'_>) {
2c00a5a8 999 let mut cmd = builder.tool_cmd(Tool::Tidy);
1b1a35ee 1000 cmd.arg(&builder.src);
83c7162d 1001 cmd.arg(&builder.initial_cargo);
29967ef6 1002 cmd.arg(&builder.out);
cdc7bbd5 1003 cmd.arg(builder.jobs().to_string());
dc9dc135
XL
1004 if builder.is_verbose() {
1005 cmd.arg("--verbose");
2c00a5a8 1006 }
0531ce1d 1007
a1dfa0c6 1008 builder.info("tidy check");
83c7162d 1009 try_run(builder, &mut cmd);
dfeec247
XL
1010
1011 if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1012 builder.info("fmt check");
923072b8 1013 if builder.initial_rustfmt().is_none() {
6a06907d
XL
1014 let inferred_rustfmt_dir = builder.config.initial_rustc.parent().unwrap();
1015 eprintln!(
1016 "\
1017error: no `rustfmt` binary found in {PATH}
1018info: `rust.channel` is currently set to \"{CHAN}\"
1019help: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
1020help: to skip test's attempt to check tidiness, pass `--exclude src/tools/tidy` to `x.py test`",
1021 PATH = inferred_rustfmt_dir.display(),
1022 CHAN = builder.config.channel,
1023 );
1024 std::process::exit(1);
1025 }
923072b8 1026 crate::format::format(&builder, !builder.config.cmd.bless(), &[]);
dfeec247 1027 }
2c00a5a8
XL
1028 }
1029
9fa01778 1030 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
1031 run.path("src/tools/tidy")
1032 }
1033
9fa01778 1034 fn make_run(run: RunConfig<'_>) {
0531ce1d 1035 run.builder.ensure(Tidy);
2c00a5a8
XL
1036 }
1037}
1038
ba9703b0
XL
1039#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1040pub struct ExpandYamlAnchors;
1041
1042impl Step for ExpandYamlAnchors {
1043 type Output = ();
1044 const ONLY_HOSTS: bool = true;
1045
1046 /// Ensure the `generate-ci-config` tool was run locally.
1047 ///
1048 /// The tool in `src/tools` reads the CI definition in `src/ci/builders.yml` and generates the
1049 /// appropriate configuration for all our CI providers. This step ensures the tool was called
1050 /// by the user before committing CI changes.
1051 fn run(self, builder: &Builder<'_>) {
1052 builder.info("Ensuring the YAML anchors in the GitHub Actions config were expanded");
1053 try_run(
1054 builder,
1055 &mut builder.tool_cmd(Tool::ExpandYamlAnchors).arg("check").arg(&builder.src),
1056 );
1057 }
1058
1059 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1060 run.path("src/tools/expand-yaml-anchors")
1061 }
1062
1063 fn make_run(run: RunConfig<'_>) {
1064 run.builder.ensure(ExpandYamlAnchors);
1065 }
1066}
1067
3dfed10e
XL
1068fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
1069 builder.out.join(host.triple).join("test")
2c00a5a8
XL
1070}
1071
1072macro_rules! default_test {
1073 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1074 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: false });
dfeec247 1075 };
2c00a5a8
XL
1076}
1077
83c7162d
XL
1078macro_rules! default_test_with_compare_mode {
1079 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
1080 compare_mode: $compare_mode:expr }) => {
dfeec247
XL
1081 test_with_compare_mode!($name {
1082 path: $path,
1083 mode: $mode,
1084 suite: $suite,
1085 default: true,
1086 host: false,
1087 compare_mode: $compare_mode
1088 });
1089 };
83c7162d
XL
1090}
1091
2c00a5a8
XL
1092macro_rules! host_test {
1093 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
1094 test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
dfeec247 1095 };
2c00a5a8
XL
1096}
1097
1098macro_rules! test {
83c7162d
XL
1099 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1100 host: $host:expr }) => {
dfeec247
XL
1101 test_definitions!($name {
1102 path: $path,
1103 mode: $mode,
1104 suite: $suite,
1105 default: $default,
1106 host: $host,
1107 compare_mode: None
1108 });
1109 };
83c7162d
XL
1110}
1111
1112macro_rules! test_with_compare_mode {
1113 ($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
1114 host: $host:expr, compare_mode: $compare_mode:expr }) => {
dfeec247
XL
1115 test_definitions!($name {
1116 path: $path,
1117 mode: $mode,
1118 suite: $suite,
1119 default: $default,
1120 host: $host,
1121 compare_mode: Some($compare_mode)
1122 });
1123 };
83c7162d
XL
1124}
1125
1126macro_rules! test_definitions {
2c00a5a8
XL
1127 ($name:ident {
1128 path: $path:expr,
1129 mode: $mode:expr,
1130 suite: $suite:expr,
1131 default: $default:expr,
83c7162d
XL
1132 host: $host:expr,
1133 compare_mode: $compare_mode:expr
2c00a5a8
XL
1134 }) => {
1135 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1136 pub struct $name {
1137 pub compiler: Compiler,
3dfed10e 1138 pub target: TargetSelection,
2c00a5a8
XL
1139 }
1140
1141 impl Step for $name {
1142 type Output = ();
1143 const DEFAULT: bool = $default;
1144 const ONLY_HOSTS: bool = $host;
1145
9fa01778 1146 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
94b46f34 1147 run.suite_path($path)
2c00a5a8
XL
1148 }
1149
9fa01778 1150 fn make_run(run: RunConfig<'_>) {
1b1a35ee 1151 let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
2c00a5a8 1152
dfeec247 1153 run.builder.ensure($name { compiler, target: run.target });
2c00a5a8
XL
1154 }
1155
9fa01778 1156 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
1157 builder.ensure(Compiletest {
1158 compiler: self.compiler,
1159 target: self.target,
1160 mode: $mode,
1161 suite: $suite,
74b04a01 1162 path: $path,
83c7162d 1163 compare_mode: $compare_mode,
2c00a5a8
XL
1164 })
1165 }
1166 }
dfeec247 1167 };
2c00a5a8
XL
1168}
1169
923072b8 1170default_test!(Ui { path: "src/test/ui", mode: "ui", suite: "ui" });
2c00a5a8 1171
2c00a5a8
XL
1172default_test!(RunPassValgrind {
1173 path: "src/test/run-pass-valgrind",
1174 mode: "run-pass-valgrind",
1175 suite: "run-pass-valgrind"
1176});
1177
dfeec247 1178default_test!(MirOpt { path: "src/test/mir-opt", mode: "mir-opt", suite: "mir-opt" });
2c00a5a8 1179
dfeec247 1180default_test!(Codegen { path: "src/test/codegen", mode: "codegen", suite: "codegen" });
2c00a5a8
XL
1181
1182default_test!(CodegenUnits {
1183 path: "src/test/codegen-units",
1184 mode: "codegen-units",
1185 suite: "codegen-units"
1186});
1187
1188default_test!(Incremental {
1189 path: "src/test/incremental",
1190 mode: "incremental",
1191 suite: "incremental"
1192});
1193
fc512014
XL
1194default_test_with_compare_mode!(Debuginfo {
1195 path: "src/test/debuginfo",
1196 mode: "debuginfo",
1197 suite: "debuginfo",
1198 compare_mode: "split-dwarf"
1199});
2c00a5a8 1200
dfeec247 1201host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-fulldeps" });
2c00a5a8 1202
dfeec247 1203host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
fc512014
XL
1204host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
1205
1206host_test!(RustdocJson {
1207 path: "src/test/rustdoc-json",
1208 mode: "rustdoc-json",
1209 suite: "rustdoc-json"
1210});
2c00a5a8 1211
dfeec247 1212host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
2c00a5a8 1213
dfeec247 1214default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
2c00a5a8 1215
0531ce1d
XL
1216host_test!(RunMakeFullDeps {
1217 path: "src/test/run-make-fulldeps",
1218 mode: "run-make",
1219 suite: "run-make-fulldeps"
1220});
1221
dfeec247 1222default_test!(Assembly { path: "src/test/assembly", mode: "assembly", suite: "assembly" });
532ac7d7 1223
2c00a5a8
XL
1224#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1225struct Compiletest {
1226 compiler: Compiler,
3dfed10e 1227 target: TargetSelection,
2c00a5a8
XL
1228 mode: &'static str,
1229 suite: &'static str,
74b04a01 1230 path: &'static str,
83c7162d 1231 compare_mode: Option<&'static str>,
2c00a5a8
XL
1232}
1233
1234impl Step for Compiletest {
1235 type Output = ();
1236
9fa01778 1237 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
1238 run.never()
1239 }
1240
1241 /// Executes the `compiletest` tool to run a suite of tests.
1242 ///
1243 /// Compiles all tests with `compiler` for `target` with the specified
1244 /// compiletest `mode` and `suite` arguments. For example `mode` can be
1245 /// "run-pass" or `suite` can be something like `debuginfo`.
9fa01778 1246 fn run(self, builder: &Builder<'_>) {
29967ef6
XL
1247 if builder.top_stage == 0 && env::var("COMPILETEST_FORCE_STAGE0").is_err() {
1248 eprintln!("\
1249error: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
1250help: to test the compiler, use `--stage 1` instead
1251help: to test the standard library, use `--stage 0 library/std` instead
1252note: 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`."
1253 );
1254 std::process::exit(1);
1255 }
1256
2c00a5a8
XL
1257 let compiler = self.compiler;
1258 let target = self.target;
1259 let mode = self.mode;
1260 let suite = self.suite;
94b46f34
XL
1261
1262 // Path for test suite
74b04a01 1263 let suite_path = self.path;
2c00a5a8
XL
1264
1265 // Skip codegen tests if they aren't enabled in configuration.
83c7162d 1266 if !builder.config.codegen_tests && suite == "codegen" {
2c00a5a8
XL
1267 return;
1268 }
1269
1270 if suite == "debuginfo" {
dfeec247
XL
1271 builder
1272 .ensure(dist::DebuggerScripts { sysroot: builder.sysroot(compiler), host: target });
2c00a5a8
XL
1273 }
1274
532ac7d7 1275 if suite.ends_with("fulldeps") {
2c00a5a8
XL
1276 builder.ensure(compile::Rustc { compiler, target });
1277 }
1278
e1599b0c
XL
1279 builder.ensure(compile::Std { compiler, target });
1280 // ensure that `libproc_macro` is available on the host.
1281 builder.ensure(compile::Std { compiler, target: compiler.host });
b7449926 1282
a1dfa0c6
XL
1283 // Also provide `rust_test_helpers` for the host.
1284 builder.ensure(native::TestHelpers { target: compiler.host });
1285
e74abb32 1286 // As well as the target, except for plain wasm32, which can't build it
3c0e092e 1287 if !target.contains("wasm") || target.contains("emscripten") {
48663c56
XL
1288 builder.ensure(native::TestHelpers { target });
1289 }
e74abb32 1290
2c00a5a8
XL
1291 builder.ensure(RemoteCopyLibs { compiler, target });
1292
2c00a5a8
XL
1293 let mut cmd = builder.tool_cmd(Tool::Compiletest);
1294
1295 // compiletest currently has... a lot of arguments, so let's just pass all
1296 // of them!
1297
dfeec247
XL
1298 cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler));
1299 cmd.arg("--run-lib-path").arg(builder.sysroot_libdir(compiler, target));
2c00a5a8
XL
1300 cmd.arg("--rustc-path").arg(builder.rustc(compiler));
1301
9fa01778 1302 let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");
83c7162d 1303
2c00a5a8 1304 // Avoid depending on rustdoc when we don't need it.
94b46f34 1305 if mode == "rustdoc"
6a06907d 1306 || mode == "run-make"
9fa01778
XL
1307 || (mode == "ui" && is_rustdoc)
1308 || mode == "js-doc-test"
fc512014 1309 || mode == "rustdoc-json"
94b46f34 1310 {
dfeec247 1311 cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
2c00a5a8
XL
1312 }
1313
5869c6ff
XL
1314 if mode == "rustdoc-json" {
1315 // Use the beta compiler for jsondocck
1316 let json_compiler = compiler.with_stage(0);
1317 cmd.arg("--jsondocck-path")
1318 .arg(builder.ensure(tool::JsonDocCk { compiler: json_compiler, target }));
1319 }
1320
3dfed10e 1321 if mode == "run-make" && suite.ends_with("fulldeps") {
cdc7bbd5
XL
1322 let rust_demangler = builder
1323 .ensure(tool::RustDemangler { compiler, target, extra_features: Vec::new() })
1324 .expect("in-tree tool");
1325 cmd.arg("--rust-demangler-path").arg(rust_demangler);
3dfed10e
XL
1326 }
1327
dfeec247
XL
1328 cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
1329 cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1330 cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
29967ef6 1331 cmd.arg("--suite").arg(suite);
2c00a5a8 1332 cmd.arg("--mode").arg(mode);
3dfed10e
XL
1333 cmd.arg("--target").arg(target.rustc_target_arg());
1334 cmd.arg("--host").arg(&*compiler.host.triple);
dfeec247 1335 cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.build));
94b46f34
XL
1336
1337 if builder.config.cmd.bless() {
1338 cmd.arg("--bless");
1339 }
1340
94222f64
XL
1341 if builder.config.cmd.force_rerun() {
1342 cmd.arg("--force-rerun");
1343 }
1344
dfeec247
XL
1345 let compare_mode =
1346 builder.config.cmd.compare_mode().or_else(|| {
1347 if builder.config.test_compare_mode { self.compare_mode } else { None }
1348 });
2c00a5a8 1349
dc9dc135
XL
1350 if let Some(ref pass) = builder.config.cmd.pass() {
1351 cmd.arg("--pass");
1352 cmd.arg(pass);
1353 }
1354
17df50a5
XL
1355 if let Some(ref run) = builder.config.cmd.run() {
1356 cmd.arg("--run");
1357 cmd.arg(run);
1358 }
1359
83c7162d 1360 if let Some(ref nodejs) = builder.config.nodejs {
2c00a5a8
XL
1361 cmd.arg("--nodejs").arg(nodejs);
1362 }
6a06907d
XL
1363 if let Some(ref npm) = builder.config.npm {
1364 cmd.arg("--npm").arg(npm);
1365 }
2c00a5a8 1366
dfeec247 1367 let mut flags = if is_rustdoc { Vec::new() } else { vec!["-Crpath".to_string()] };
9fa01778 1368 if !is_rustdoc {
83c7162d
XL
1369 if builder.config.rust_optimize_tests {
1370 flags.push("-O".to_string());
1371 }
2c00a5a8 1372 }
dc9dc135 1373 flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
83c7162d 1374 flags.push(builder.config.cmd.rustc_args().join(" "));
2c00a5a8 1375
1b1a35ee 1376 if let Some(linker) = builder.linker(target) {
2c00a5a8
XL
1377 cmd.arg("--linker").arg(linker);
1378 }
1379
a1dfa0c6 1380 let mut hostflags = flags.clone();
dfeec247 1381 hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
17df50a5 1382 hostflags.extend(builder.lld_flags(compiler.host));
2c00a5a8
XL
1383 cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
1384
0bf4aa26 1385 let mut targetflags = flags;
dfeec247 1386 targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
17df50a5 1387 targetflags.extend(builder.lld_flags(target));
2c00a5a8
XL
1388 cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
1389
04454e1e 1390 cmd.arg("--python").arg(builder.python());
2c00a5a8 1391
83c7162d 1392 if let Some(ref gdb) = builder.config.gdb {
2c00a5a8
XL
1393 cmd.arg("--gdb").arg(gdb);
1394 }
0bf4aa26
XL
1395
1396 let run = |cmd: &mut Command| {
1397 cmd.output().map(|output| {
1398 String::from_utf8_lossy(&output.stdout)
dfeec247
XL
1399 .lines()
1400 .next()
1401 .unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1402 .to_string()
0bf4aa26
XL
1403 })
1404 };
f9f354fc
XL
1405 let lldb_exe = "lldb";
1406 let lldb_version = Command::new(lldb_exe)
0bf4aa26
XL
1407 .arg("--version")
1408 .output()
dfeec247 1409 .map(|output| String::from_utf8_lossy(&output.stdout).to_string())
0bf4aa26
XL
1410 .ok();
1411 if let Some(ref vers) = lldb_version {
2c00a5a8 1412 cmd.arg("--lldb-version").arg(vers);
f9f354fc 1413 let lldb_python_dir = run(Command::new(lldb_exe).arg("-P")).ok();
0bf4aa26
XL
1414 if let Some(ref dir) = lldb_python_dir {
1415 cmd.arg("--lldb-python-dir").arg(dir);
1416 }
2c00a5a8
XL
1417 }
1418
dc9dc135
XL
1419 if util::forcing_clang_based_tests() {
1420 let clang_exe = builder.llvm_out(target).join("bin").join("clang");
1421 cmd.arg("--run-clang-based-tests-with").arg(clang_exe);
9fa01778
XL
1422 }
1423
94b46f34
XL
1424 // Get paths from cmd args
1425 let paths = match &builder.config.cmd {
1426 Subcommand::Test { ref paths, .. } => &paths[..],
1427 _ => &[],
1428 };
1429
1430 // Get test-args by striping suite path
1431 let mut test_args: Vec<&str> = paths
1432 .iter()
3c0e092e 1433 .filter_map(|p| util::is_valid_test_suite_arg(p, suite_path, builder))
94b46f34
XL
1434 .collect();
1435
1436 test_args.append(&mut builder.config.cmd.test_args());
1437
1438 cmd.args(&test_args);
2c00a5a8 1439
83c7162d 1440 if builder.is_verbose() {
2c00a5a8
XL
1441 cmd.arg("--verbose");
1442 }
1443
94b46f34 1444 if !builder.config.verbose_tests {
2c00a5a8
XL
1445 cmd.arg("--quiet");
1446 }
1447
3dfed10e
XL
1448 let mut llvm_components_passed = false;
1449 let mut copts_passed = false;
532ac7d7 1450 if builder.config.llvm_enabled() {
dfeec247 1451 let llvm_config = builder.ensure(native::Llvm { target: builder.config.build });
83c7162d
XL
1452 if !builder.config.dry_run {
1453 let llvm_version = output(Command::new(&llvm_config).arg("--version"));
3dfed10e 1454 let llvm_components = output(Command::new(&llvm_config).arg("--components"));
ba9703b0 1455 // Remove trailing newline from llvm-config output.
3dfed10e
XL
1456 cmd.arg("--llvm-version")
1457 .arg(llvm_version.trim())
1458 .arg("--llvm-components")
1459 .arg(llvm_components.trim());
1460 llvm_components_passed = true;
83c7162d
XL
1461 }
1462 if !builder.is_rust_llvm(target) {
2c00a5a8
XL
1463 cmd.arg("--system-llvm");
1464 }
1465
ba9703b0
XL
1466 // Tests that use compiler libraries may inherit the `-lLLVM` link
1467 // requirement, but the `-L` library path is not propagated across
1468 // separate compilations. We can add LLVM's library path to the
1469 // platform-specific environment variable as a workaround.
1470 if !builder.config.dry_run && suite.ends_with("fulldeps") {
1471 let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1472 add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
1473 }
1474
2c00a5a8
XL
1475 // Only pass correct values for these flags for the `run-make` suite as it
1476 // requires that a C++ compiler was configured which isn't always the case.
29967ef6 1477 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
48663c56
XL
1478 // The llvm/bin directory contains many useful cross-platform
1479 // tools. Pass the path to run-make tests so they can use them.
dfeec247
XL
1480 let llvm_bin_path = llvm_config
1481 .parent()
48663c56
XL
1482 .expect("Expected llvm-config to be contained in directory");
1483 assert!(llvm_bin_path.is_dir());
1484 cmd.arg("--llvm-bin-dir").arg(llvm_bin_path);
1485
1486 // If LLD is available, add it to the PATH
1487 if builder.config.lld_enabled {
dfeec247
XL
1488 let lld_install_root =
1489 builder.ensure(native::Lld { target: builder.config.build });
48663c56
XL
1490
1491 let lld_bin_path = lld_install_root.join("bin");
1492
1493 let old_path = env::var_os("PATH").unwrap_or_default();
dfeec247
XL
1494 let new_path = env::join_paths(
1495 std::iter::once(lld_bin_path).chain(env::split_paths(&old_path)),
1496 )
1497 .expect("Could not add LLD bin path to PATH");
48663c56
XL
1498 cmd.env("PATH", new_path);
1499 }
2c00a5a8
XL
1500 }
1501 }
2c00a5a8 1502
29967ef6
XL
1503 // Only pass correct values for these flags for the `run-make` suite as it
1504 // requires that a C++ compiler was configured which isn't always the case.
1505 if !builder.config.dry_run && matches!(suite, "run-make" | "run-make-fulldeps") {
1506 cmd.arg("--cc")
1507 .arg(builder.cc(target))
1508 .arg("--cxx")
1509 .arg(builder.cxx(target).unwrap())
1510 .arg("--cflags")
5099ac24
FG
1511 .arg(builder.cflags(target, GitRepo::Rustc, CLang::C).join(" "))
1512 .arg("--cxxflags")
1513 .arg(builder.cflags(target, GitRepo::Rustc, CLang::Cxx).join(" "));
29967ef6
XL
1514 copts_passed = true;
1515 if let Some(ar) = builder.ar(target) {
1516 cmd.arg("--ar").arg(ar);
1517 }
1518 }
1519
3dfed10e
XL
1520 if !llvm_components_passed {
1521 cmd.arg("--llvm-components").arg("");
1522 }
1523 if !copts_passed {
5099ac24
FG
1524 cmd.arg("--cc")
1525 .arg("")
1526 .arg("--cxx")
1527 .arg("")
1528 .arg("--cflags")
1529 .arg("")
1530 .arg("--cxxflags")
1531 .arg("");
2c00a5a8
XL
1532 }
1533
83c7162d 1534 if builder.remote_tested(target) {
dfeec247 1535 cmd.arg("--remote-test-client").arg(builder.tool_exe(Tool::RemoteTestClient));
2c00a5a8
XL
1536 }
1537
1538 // Running a C compiler on MSVC requires a few env vars to be set, to be
1539 // sure to set them here.
1540 //
1541 // Note that if we encounter `PATH` we make sure to append to our own `PATH`
1542 // rather than stomp over it.
1543 if target.contains("msvc") {
83c7162d 1544 for &(ref k, ref v) in builder.cc[&target].env() {
2c00a5a8
XL
1545 if k != "PATH" {
1546 cmd.env(k, v);
1547 }
1548 }
1549 }
1550 cmd.env("RUSTC_BOOTSTRAP", "1");
5099ac24
FG
1551 // Override the rustc version used in symbol hashes to reduce the amount of normalization
1552 // needed when diffing test output.
1553 cmd.env("RUSTC_FORCE_RUSTC_VERSION", "compiletest");
17df50a5 1554 cmd.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel());
83c7162d 1555 builder.add_rust_test_threads(&mut cmd);
2c00a5a8 1556
29967ef6 1557 if builder.config.sanitizers_enabled(target) {
48663c56 1558 cmd.env("RUSTC_SANITIZER_SUPPORT", "1");
2c00a5a8
XL
1559 }
1560
29967ef6 1561 if builder.config.profiler_enabled(target) {
48663c56 1562 cmd.env("RUSTC_PROFILER_SUPPORT", "1");
2c00a5a8
XL
1563 }
1564
04454e1e 1565 cmd.env("RUST_TEST_TMPDIR", builder.tempdir());
e1599b0c 1566
2c00a5a8
XL
1567 cmd.arg("--adb-path").arg("adb");
1568 cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
1569 if target.contains("android") {
1570 // Assume that cc for this target comes from the android sysroot
1571 cmd.arg("--android-cross-path")
94b46f34 1572 .arg(builder.cc(target).parent().unwrap().parent().unwrap());
2c00a5a8
XL
1573 } else {
1574 cmd.arg("--android-cross-path").arg("");
1575 }
1576
532ac7d7
XL
1577 if builder.config.cmd.rustfix_coverage() {
1578 cmd.arg("--rustfix-coverage");
1579 }
1580
1b1a35ee
XL
1581 cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);
1582
17df50a5
XL
1583 cmd.arg("--channel").arg(&builder.config.channel);
1584
83c7162d
XL
1585 builder.ci_env.force_coloring_in_ci(&mut cmd);
1586
94b46f34
XL
1587 builder.info(&format!(
1588 "Check compiletest suite={} mode={} ({} -> {})",
1589 suite, mode, &compiler.host, target
1590 ));
83c7162d
XL
1591 let _time = util::timeit(&builder);
1592 try_run(builder, &mut cmd);
1593
1594 if let Some(compare_mode) = compare_mode {
1595 cmd.arg("--compare-mode").arg(compare_mode);
94b46f34
XL
1596 builder.info(&format!(
1597 "Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1598 suite, mode, compare_mode, &compiler.host, target
1599 ));
83c7162d
XL
1600 let _time = util::timeit(&builder);
1601 try_run(builder, &mut cmd);
1602 }
2c00a5a8
XL
1603 }
1604}
1605
74b04a01
XL
1606#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1607struct BookTest {
2c00a5a8 1608 compiler: Compiler,
74b04a01 1609 path: PathBuf,
0531ce1d
XL
1610 name: &'static str,
1611 is_ext_doc: bool,
2c00a5a8
XL
1612}
1613
74b04a01 1614impl Step for BookTest {
2c00a5a8 1615 type Output = ();
2c00a5a8
XL
1616 const ONLY_HOSTS: bool = true;
1617
9fa01778 1618 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
0531ce1d 1619 run.never()
2c00a5a8
XL
1620 }
1621
74b04a01 1622 /// Runs the documentation tests for a book in `src/doc`.
2c00a5a8 1623 ///
74b04a01 1624 /// This uses the `rustdoc` that sits next to `compiler`.
9fa01778 1625 fn run(self, builder: &Builder<'_>) {
74b04a01
XL
1626 // External docs are different from local because:
1627 // - Some books need pre-processing by mdbook before being tested.
1628 // - They need to save their state to toolstate.
1629 // - They are only tested on the "checktools" builders.
1630 //
1631 // The local docs are tested by default, and we don't want to pay the
1632 // cost of building mdbook, so they use `rustdoc --test` directly.
1633 // Also, the unstable book is special because SUMMARY.md is generated,
1634 // so it is easier to just run `rustdoc` on its files.
1635 if self.is_ext_doc {
1636 self.run_ext_doc(builder);
1637 } else {
1638 self.run_local_doc(builder);
1639 }
1640 }
1641}
1642
1643impl BookTest {
1644 /// This runs the equivalent of `mdbook test` (via the rustbook wrapper)
1645 /// which in turn runs `rustdoc --test` on each file in the book.
1646 fn run_ext_doc(self, builder: &Builder<'_>) {
1647 let compiler = self.compiler;
1648
1649 builder.ensure(compile::Std { compiler, target: compiler.host });
1650
1651 // mdbook just executes a binary named "rustdoc", so we need to update
1652 // PATH so that it points to our rustdoc.
1653 let mut rustdoc_path = builder.rustdoc(compiler);
1654 rustdoc_path.pop();
1655 let old_path = env::var_os("PATH").unwrap_or_default();
1656 let new_path = env::join_paths(iter::once(rustdoc_path).chain(env::split_paths(&old_path)))
1657 .expect("could not add rustdoc to PATH");
1658
1659 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1660 let path = builder.src.join(&self.path);
1661 rustbook_cmd.env("PATH", new_path).arg("test").arg(path);
1662 builder.add_rust_test_threads(&mut rustbook_cmd);
1663 builder.info(&format!("Testing rustbook {}", self.path.display()));
1664 let _time = util::timeit(&builder);
1665 let toolstate = if try_run(builder, &mut rustbook_cmd) {
1666 ToolState::TestPass
1667 } else {
1668 ToolState::TestFail
1669 };
1670 builder.save_toolstate(self.name, toolstate);
1671 }
1672
1673 /// This runs `rustdoc --test` on all `.md` files in the path.
1674 fn run_local_doc(self, builder: &Builder<'_>) {
2c00a5a8
XL
1675 let compiler = self.compiler;
1676
dfeec247 1677 builder.ensure(compile::Std { compiler, target: compiler.host });
2c00a5a8
XL
1678
1679 // Do a breadth-first traversal of the `src/doc` directory and just run
1680 // tests for all files that end in `*.md`
83c7162d
XL
1681 let mut stack = vec![builder.src.join(self.path)];
1682 let _time = util::timeit(&builder);
83c7162d 1683 let mut files = Vec::new();
2c00a5a8
XL
1684 while let Some(p) = stack.pop() {
1685 if p.is_dir() {
1686 stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
94b46f34 1687 continue;
2c00a5a8
XL
1688 }
1689
1690 if p.extension().and_then(|s| s.to_str()) != Some("md") {
1691 continue;
1692 }
1693
83c7162d
XL
1694 files.push(p);
1695 }
1696
1697 files.sort();
1698
1699 for file in files {
74b04a01 1700 markdown_test(builder, compiler, &file);
8faf50e0 1701 }
2c00a5a8
XL
1702 }
1703}
1704
0531ce1d
XL
1705macro_rules! test_book {
1706 ($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
1707 $(
1708 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1709 pub struct $name {
1710 compiler: Compiler,
1711 }
1712
1713 impl Step for $name {
1714 type Output = ();
1715 const DEFAULT: bool = $default;
1716 const ONLY_HOSTS: bool = true;
1717
9fa01778 1718 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
0531ce1d
XL
1719 run.path($path)
1720 }
1721
9fa01778 1722 fn make_run(run: RunConfig<'_>) {
0531ce1d 1723 run.builder.ensure($name {
1b1a35ee 1724 compiler: run.builder.compiler(run.builder.top_stage, run.target),
0531ce1d
XL
1725 });
1726 }
1727
9fa01778 1728 fn run(self, builder: &Builder<'_>) {
74b04a01 1729 builder.ensure(BookTest {
0531ce1d 1730 compiler: self.compiler,
74b04a01 1731 path: PathBuf::from($path),
0531ce1d
XL
1732 name: $book_name,
1733 is_ext_doc: !$default,
1734 });
1735 }
1736 }
1737 )+
1738 }
1739}
1740
1741test_book!(
1742 Nomicon, "src/doc/nomicon", "nomicon", default=false;
1743 Reference, "src/doc/reference", "reference", default=false;
1744 RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
83c7162d 1745 RustcBook, "src/doc/rustc", "rustc", default=true;
0531ce1d 1746 RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
9fa01778 1747 EmbeddedBook, "src/doc/embedded-book", "embedded-book", default=false;
0531ce1d
XL
1748 TheBook, "src/doc/book", "book", default=false;
1749 UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
532ac7d7 1750 EditionGuide, "src/doc/edition-guide", "edition-guide", default=false;
0531ce1d
XL
1751);
1752
2c00a5a8
XL
1753#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1754pub struct ErrorIndex {
1755 compiler: Compiler,
1756}
1757
1758impl Step for ErrorIndex {
1759 type Output = ();
1760 const DEFAULT: bool = true;
1761 const ONLY_HOSTS: bool = true;
1762
9fa01778 1763 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
1764 run.path("src/tools/error_index_generator")
1765 }
1766
9fa01778 1767 fn make_run(run: RunConfig<'_>) {
f035d41b
XL
1768 // error_index_generator depends on librustdoc. Use the compiler that
1769 // is normally used to build rustdoc for other tests (like compiletest
1770 // tests in src/test/rustdoc) so that it shares the same artifacts.
5869c6ff 1771 let compiler = run.builder.compiler(run.builder.top_stage, run.builder.config.build);
f035d41b 1772 run.builder.ensure(ErrorIndex { compiler });
2c00a5a8
XL
1773 }
1774
9fa01778 1775 /// Runs the error index generator tool to execute the tests located in the error
2c00a5a8
XL
1776 /// index.
1777 ///
1778 /// The `error_index_generator` tool lives in `src/tools` and is used to
1779 /// generate a markdown file from the error indexes of the code base which is
1780 /// then passed to `rustdoc --test`.
9fa01778 1781 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
1782 let compiler = self.compiler;
1783
83c7162d 1784 let dir = testdir(builder, compiler.host);
2c00a5a8
XL
1785 t!(fs::create_dir_all(&dir));
1786 let output = dir.join("error-index.md");
1787
5869c6ff 1788 let mut tool = tool::ErrorIndex::command(builder);
f035d41b 1789 tool.arg("markdown").arg(&output);
0531ce1d 1790
5869c6ff 1791 builder.info(&format!("Testing error-index stage{}", compiler.stage));
83c7162d 1792 let _time = util::timeit(&builder);
416331ca 1793 builder.run_quiet(&mut tool);
5869c6ff
XL
1794 // The tests themselves need to link to std, so make sure it is
1795 // available.
1796 builder.ensure(compile::Std { compiler, target: compiler.host });
1797 markdown_test(builder, compiler, &output);
2c00a5a8
XL
1798 }
1799}
1800
9fa01778 1801fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
74b04a01
XL
1802 if let Ok(contents) = fs::read_to_string(markdown) {
1803 if !contents.contains("```") {
1804 return true;
83c7162d 1805 }
2c00a5a8
XL
1806 }
1807
83c7162d 1808 builder.info(&format!("doc tests for: {}", markdown.display()));
532ac7d7 1809 let mut cmd = builder.rustdoc_cmd(compiler);
83c7162d 1810 builder.add_rust_test_threads(&mut cmd);
17df50a5
XL
1811 // allow for unstable options such as new editions
1812 cmd.arg("-Z");
1813 cmd.arg("unstable-options");
2c00a5a8
XL
1814 cmd.arg("--test");
1815 cmd.arg(markdown);
1816 cmd.env("RUSTC_BOOTSTRAP", "1");
1817
83c7162d 1818 let test_args = builder.config.cmd.test_args().join(" ");
2c00a5a8
XL
1819 cmd.arg("--test-args").arg(test_args);
1820
94b46f34 1821 if builder.config.verbose_tests {
83c7162d 1822 try_run(builder, &mut cmd)
94b46f34
XL
1823 } else {
1824 try_run_quiet(builder, &mut cmd)
2c00a5a8
XL
1825 }
1826}
1827
416331ca
XL
1828#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1829pub struct RustcGuide;
1830
1831impl Step for RustcGuide {
1832 type Output = ();
1833 const DEFAULT: bool = false;
1834 const ONLY_HOSTS: bool = true;
1835
1836 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
74b04a01 1837 run.path("src/doc/rustc-dev-guide")
416331ca
XL
1838 }
1839
1840 fn make_run(run: RunConfig<'_>) {
1841 run.builder.ensure(RustcGuide);
1842 }
1843
1844 fn run(self, builder: &Builder<'_>) {
136023e0
XL
1845 let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
1846 builder.update_submodule(&relative_path);
1847
1848 let src = builder.src.join(relative_path);
416331ca
XL
1849 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
1850 let toolstate = if try_run(builder, rustbook_cmd.arg("linkcheck").arg(&src)) {
1851 ToolState::TestPass
1852 } else {
1853 ToolState::TestFail
1854 };
74b04a01 1855 builder.save_toolstate("rustc-dev-guide", toolstate);
416331ca
XL
1856 }
1857}
1858
923072b8 1859#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2c00a5a8
XL
1860pub struct CrateLibrustc {
1861 compiler: Compiler,
3dfed10e 1862 target: TargetSelection,
2c00a5a8 1863 test_kind: TestKind,
923072b8 1864 crates: Vec<Interned<String>>,
2c00a5a8
XL
1865}
1866
1867impl Step for CrateLibrustc {
1868 type Output = ();
1869 const DEFAULT: bool = true;
1870 const ONLY_HOSTS: bool = true;
1871
9fa01778 1872 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
1873 run.krate("rustc-main")
1874 }
1875
9fa01778 1876 fn make_run(run: RunConfig<'_>) {
2c00a5a8 1877 let builder = run.builder;
04454e1e
FG
1878 let host = run.build_triple();
1879 let compiler = builder.compiler_for(builder.top_stage, host, host);
923072b8
FG
1880 let crates = run
1881 .paths
1882 .iter()
1883 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1884 .collect();
04454e1e
FG
1885 let test_kind = builder.kind.into();
1886
923072b8 1887 builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
2c00a5a8
XL
1888 }
1889
9fa01778 1890 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
1891 builder.ensure(Crate {
1892 compiler: self.compiler,
1893 target: self.target,
94b46f34 1894 mode: Mode::Rustc,
2c00a5a8 1895 test_kind: self.test_kind,
923072b8 1896 crates: self.crates,
2c00a5a8
XL
1897 });
1898 }
1899}
1900
923072b8 1901#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2c00a5a8 1902pub struct Crate {
83c7162d 1903 pub compiler: Compiler,
3dfed10e 1904 pub target: TargetSelection,
83c7162d
XL
1905 pub mode: Mode,
1906 pub test_kind: TestKind,
923072b8 1907 pub crates: Vec<Interned<String>>,
2c00a5a8
XL
1908}
1909
1910impl Step for Crate {
1911 type Output = ();
1912 const DEFAULT: bool = true;
1913
f035d41b
XL
1914 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1915 run.krate("test")
2c00a5a8
XL
1916 }
1917
9fa01778 1918 fn make_run(run: RunConfig<'_>) {
2c00a5a8 1919 let builder = run.builder;
04454e1e
FG
1920 let host = run.build_triple();
1921 let compiler = builder.compiler_for(builder.top_stage, host, host);
1922 let test_kind = builder.kind.into();
923072b8
FG
1923 let crates = run
1924 .paths
1925 .iter()
1926 .map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
1927 .collect();
2c00a5a8 1928
923072b8 1929 builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2c00a5a8
XL
1930 }
1931
9fa01778 1932 /// Runs all unit tests plus documentation tests for a given crate defined
2c00a5a8
XL
1933 /// by a `Cargo.toml` (single manifest)
1934 ///
1935 /// This is what runs tests for crates like the standard library, compiler, etc.
1936 /// It essentially is the driver for running `cargo test`.
1937 ///
1938 /// Currently this runs all tests for a DAG by passing a bunch of `-p foo`
1939 /// arguments, and those arguments are discovered from `cargo metadata`.
9fa01778 1940 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
1941 let compiler = self.compiler;
1942 let target = self.target;
1943 let mode = self.mode;
1944 let test_kind = self.test_kind;
2c00a5a8 1945
e1599b0c 1946 builder.ensure(compile::Std { compiler, target });
2c00a5a8
XL
1947 builder.ensure(RemoteCopyLibs { compiler, target });
1948
dc9dc135
XL
1949 // If we're not doing a full bootstrap but we're testing a stage2
1950 // version of libstd, then what we're actually testing is the libstd
1951 // produced in stage1. Reflect that here by updating the compiler that
1952 // we're working with automatically.
1953 let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
2c00a5a8 1954
f035d41b
XL
1955 let mut cargo =
1956 builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2c00a5a8 1957 match mode {
94b46f34 1958 Mode::Std => {
f9f354fc 1959 compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2c00a5a8 1960 }
94b46f34 1961 Mode::Rustc => {
60c5eb7d 1962 compile::rustc_cargo(builder, &mut cargo, target);
2c00a5a8
XL
1963 }
1964 _ => panic!("can only test libraries"),
1965 };
2c00a5a8
XL
1966
1967 // Build up the base `cargo test` command.
1968 //
1969 // Pass in some standard flags then iterate over the graph we've discovered
1970 // in `cargo metadata` with the maps above and figure out what `-p`
1971 // arguments need to get passed.
83c7162d 1972 if test_kind.subcommand() == "test" && !builder.fail_fast {
2c00a5a8
XL
1973 cargo.arg("--no-fail-fast");
1974 }
83c7162d
XL
1975 match builder.doc_tests {
1976 DocTests::Only => {
1977 cargo.arg("--doc");
1978 }
1979 DocTests::No => {
1980 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
1981 }
1982 DocTests::Yes => {}
0531ce1d 1983 }
2c00a5a8 1984
923072b8
FG
1985 for krate in &self.crates {
1986 cargo.arg("-p").arg(krate);
1987 }
2c00a5a8
XL
1988
1989 // The tests are going to run with the *target* libraries, so we need to
1990 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
1991 //
1992 // Note that to run the compiler we need to run with the *host* libraries,
1993 // but our wrapper scripts arrange for that to be the case anyway.
1994 let mut dylib_path = dylib_path();
1995 dylib_path.insert(0, PathBuf::from(&*builder.sysroot_libdir(compiler, target)));
1996 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1997
1998 cargo.arg("--");
83c7162d 1999 cargo.args(&builder.config.cmd.test_args());
2c00a5a8 2000
94b46f34 2001 if !builder.config.verbose_tests {
2c00a5a8
XL
2002 cargo.arg("--quiet");
2003 }
2004
2c00a5a8 2005 if target.contains("emscripten") {
94b46f34 2006 cargo.env(
3dfed10e 2007 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
dfeec247 2008 builder.config.nodejs.as_ref().expect("nodejs not configured"),
94b46f34 2009 );
2c00a5a8 2010 } else if target.starts_with("wasm32") {
dfeec247
XL
2011 let node = builder.config.nodejs.as_ref().expect("nodejs not configured");
2012 let runner =
2013 format!("{} {}/src/etc/wasm32-shim.js", node.display(), builder.src.display());
3dfed10e 2014 cargo.env(format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)), &runner);
83c7162d 2015 } else if builder.remote_tested(target) {
94b46f34 2016 cargo.env(
3dfed10e 2017 format!("CARGO_TARGET_{}_RUNNER", envify(&target.triple)),
f9f354fc 2018 format!("{} run 0", builder.tool_exe(Tool::RemoteTestClient).display()),
94b46f34 2019 );
2c00a5a8 2020 }
0531ce1d 2021
94b46f34 2022 builder.info(&format!(
923072b8
FG
2023 "{} {:?} stage{} ({} -> {})",
2024 test_kind, self.crates, compiler.stage, &compiler.host, target
94b46f34 2025 ));
83c7162d 2026 let _time = util::timeit(&builder);
e1599b0c 2027 try_run(builder, &mut cargo.into());
2c00a5a8
XL
2028 }
2029}
2030
04454e1e 2031/// Rustdoc is special in various ways, which is why this step is different from `Crate`.
2c00a5a8
XL
2032#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2033pub struct CrateRustdoc {
3dfed10e 2034 host: TargetSelection,
2c00a5a8
XL
2035 test_kind: TestKind,
2036}
2037
2038impl Step for CrateRustdoc {
2039 type Output = ();
2040 const DEFAULT: bool = true;
2041 const ONLY_HOSTS: bool = true;
2042
9fa01778 2043 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
2044 run.paths(&["src/librustdoc", "src/tools/rustdoc"])
2045 }
2046
9fa01778 2047 fn make_run(run: RunConfig<'_>) {
2c00a5a8
XL
2048 let builder = run.builder;
2049
94b46f34 2050 let test_kind = builder.kind.into();
2c00a5a8 2051
1b1a35ee 2052 builder.ensure(CrateRustdoc { host: run.target, test_kind });
2c00a5a8
XL
2053 }
2054
9fa01778 2055 fn run(self, builder: &Builder<'_>) {
2c00a5a8 2056 let test_kind = self.test_kind;
f035d41b 2057 let target = self.host;
2c00a5a8 2058
923072b8 2059 let compiler = if builder.download_rustc() {
04454e1e
FG
2060 builder.compiler(builder.top_stage, target)
2061 } else {
2062 // Use the previous stage compiler to reuse the artifacts that are
2063 // created when running compiletest for src/test/rustdoc. If this used
2064 // `compiler`, then it would cause rustdoc to be built *again*, which
2065 // isn't really necessary.
2066 builder.compiler_for(builder.top_stage, target, target)
2067 };
8faf50e0 2068 builder.ensure(compile::Rustc { compiler, target });
2c00a5a8 2069
dfeec247
XL
2070 let mut cargo = tool::prepare_tool_cargo(
2071 builder,
2072 compiler,
2073 Mode::ToolRustc,
2074 target,
2075 test_kind.subcommand(),
2076 "src/tools/rustdoc",
2077 SourceType::InTree,
2078 &[],
2079 );
83c7162d 2080 if test_kind.subcommand() == "test" && !builder.fail_fast {
2c00a5a8
XL
2081 cargo.arg("--no-fail-fast");
2082 }
04454e1e
FG
2083 match builder.doc_tests {
2084 DocTests::Only => {
2085 cargo.arg("--doc");
2086 }
2087 DocTests::No => {
2088 cargo.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2089 }
2090 DocTests::Yes => {}
2091 }
2c00a5a8
XL
2092
2093 cargo.arg("-p").arg("rustdoc:0.0.0");
2094
2095 cargo.arg("--");
83c7162d 2096 cargo.args(&builder.config.cmd.test_args());
2c00a5a8 2097
48663c56
XL
2098 if self.host.contains("musl") {
2099 cargo.arg("'-Ctarget-feature=-crt-static'");
2100 }
2101
f035d41b
XL
2102 // This is needed for running doctests on librustdoc. This is a bit of
2103 // an unfortunate interaction with how bootstrap works and how cargo
2104 // sets up the dylib path, and the fact that the doctest (in
2105 // html/markdown.rs) links to rustc-private libs. For stage1, the
2106 // compiler host dylibs (in stage1/lib) are not the same as the target
2107 // dylibs (in stage1/lib/rustlib/...). This is different from a normal
2108 // rust distribution where they are the same.
2109 //
2110 // On the cargo side, normal tests use `target_process` which handles
2111 // setting up the dylib for a *target* (stage1/lib/rustlib/... in this
2112 // case). However, for doctests it uses `rustdoc_process` which only
2113 // sets up the dylib path for the *host* (stage1/lib), which is the
2114 // wrong directory.
2115 //
04454e1e
FG
2116 // Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
2117 //
f035d41b
XL
2118 // It should be considered to just stop running doctests on
2119 // librustdoc. There is only one test, and it doesn't look too
2120 // important. There might be other ways to avoid this, but it seems
2121 // pretty convoluted.
2122 //
2123 // See also https://github.com/rust-lang/rust/issues/13983 where the
2124 // host vs target dylibs for rustdoc are consistently tricky to deal
2125 // with.
04454e1e
FG
2126 //
2127 // Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
923072b8 2128 let libdir = if builder.download_rustc() {
04454e1e
FG
2129 builder.rustc_libdir(compiler)
2130 } else {
2131 builder.sysroot_libdir(compiler, target).to_path_buf()
2132 };
f035d41b 2133 let mut dylib_path = dylib_path();
04454e1e 2134 dylib_path.insert(0, PathBuf::from(&*libdir));
f035d41b
XL
2135 cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
2136
94b46f34 2137 if !builder.config.verbose_tests {
2c00a5a8
XL
2138 cargo.arg("--quiet");
2139 }
2140
94b46f34
XL
2141 builder.info(&format!(
2142 "{} rustdoc stage{} ({} -> {})",
2143 test_kind, compiler.stage, &compiler.host, target
2144 ));
83c7162d 2145 let _time = util::timeit(&builder);
6a06907d
XL
2146
2147 try_run(builder, &mut cargo.into());
2148 }
2149}
2150
2151#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2152pub struct CrateRustdocJsonTypes {
2153 host: TargetSelection,
2154 test_kind: TestKind,
2155}
2156
2157impl Step for CrateRustdocJsonTypes {
2158 type Output = ();
2159 const DEFAULT: bool = true;
2160 const ONLY_HOSTS: bool = true;
2161
2162 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2163 run.path("src/rustdoc-json-types")
2164 }
2165
2166 fn make_run(run: RunConfig<'_>) {
2167 let builder = run.builder;
2168
2169 let test_kind = builder.kind.into();
2170
2171 builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2172 }
2173
2174 fn run(self, builder: &Builder<'_>) {
2175 let test_kind = self.test_kind;
2176 let target = self.host;
2177
2178 // Use the previous stage compiler to reuse the artifacts that are
2179 // created when running compiletest for src/test/rustdoc. If this used
2180 // `compiler`, then it would cause rustdoc to be built *again*, which
2181 // isn't really necessary.
2182 let compiler = builder.compiler_for(builder.top_stage, target, target);
2183 builder.ensure(compile::Rustc { compiler, target });
2184
2185 let mut cargo = tool::prepare_tool_cargo(
2186 builder,
2187 compiler,
2188 Mode::ToolRustc,
2189 target,
2190 test_kind.subcommand(),
2191 "src/rustdoc-json-types",
2192 SourceType::InTree,
2193 &[],
2194 );
2195 if test_kind.subcommand() == "test" && !builder.fail_fast {
2196 cargo.arg("--no-fail-fast");
2197 }
2198
2199 cargo.arg("-p").arg("rustdoc-json-types");
2200
2201 cargo.arg("--");
2202 cargo.args(&builder.config.cmd.test_args());
2203
2204 if self.host.contains("musl") {
2205 cargo.arg("'-Ctarget-feature=-crt-static'");
2206 }
2207
2208 if !builder.config.verbose_tests {
2209 cargo.arg("--quiet");
2210 }
2211
2212 builder.info(&format!(
2213 "{} rustdoc-json-types stage{} ({} -> {})",
2214 test_kind, compiler.stage, &compiler.host, target
2215 ));
2216 let _time = util::timeit(&builder);
2c00a5a8 2217
e1599b0c 2218 try_run(builder, &mut cargo.into());
2c00a5a8
XL
2219 }
2220}
2221
2c00a5a8
XL
2222/// Some test suites are run inside emulators or on remote devices, and most
2223/// of our test binaries are linked dynamically which means we need to ship
2224/// the standard library and such to the emulator ahead of time. This step
2225/// represents this and is a dependency of all test suites.
2226///
9fa01778 2227/// Most of the time this is a no-op. For some steps such as shipping data to
2c00a5a8
XL
2228/// QEMU we have to build our own tools so we've got conditional dependencies
2229/// on those programs as well. Note that the remote test client is built for
2230/// the build target (us) and the server is built for the target.
2231#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2232pub struct RemoteCopyLibs {
2233 compiler: Compiler,
3dfed10e 2234 target: TargetSelection,
2c00a5a8
XL
2235}
2236
2237impl Step for RemoteCopyLibs {
2238 type Output = ();
2239
9fa01778 2240 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
2241 run.never()
2242 }
2243
9fa01778 2244 fn run(self, builder: &Builder<'_>) {
2c00a5a8
XL
2245 let compiler = self.compiler;
2246 let target = self.target;
83c7162d 2247 if !builder.remote_tested(target) {
94b46f34 2248 return;
2c00a5a8
XL
2249 }
2250
e1599b0c 2251 builder.ensure(compile::Std { compiler, target });
2c00a5a8 2252
83c7162d 2253 builder.info(&format!("REMOTE copy libs to emulator ({})", target));
2c00a5a8 2254
5869c6ff 2255 let server = builder.ensure(tool::RemoteTestServer { compiler, target });
2c00a5a8
XL
2256
2257 // Spawn the emulator and wait for it to come online
2258 let tool = builder.tool_exe(Tool::RemoteTestClient);
2259 let mut cmd = Command::new(&tool);
04454e1e 2260 cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir());
83c7162d 2261 if let Some(rootfs) = builder.qemu_rootfs(target) {
2c00a5a8
XL
2262 cmd.arg(rootfs);
2263 }
83c7162d 2264 builder.run(&mut cmd);
2c00a5a8
XL
2265
2266 // Push all our dylibs to the emulator
2267 for f in t!(builder.sysroot_libdir(compiler, target).read_dir()) {
2268 let f = t!(f);
2269 let name = f.file_name().into_string().unwrap();
2270 if util::is_dylib(&name) {
94b46f34 2271 builder.run(Command::new(&tool).arg("push").arg(f.path()));
2c00a5a8
XL
2272 }
2273 }
2274 }
2275}
2276
2277#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2278pub struct Distcheck;
2279
2280impl Step for Distcheck {
2281 type Output = ();
2c00a5a8 2282
9fa01778 2283 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
04454e1e 2284 run.alias("distcheck")
2c00a5a8
XL
2285 }
2286
9fa01778 2287 fn make_run(run: RunConfig<'_>) {
2c00a5a8
XL
2288 run.builder.ensure(Distcheck);
2289 }
2290
9fa01778
XL
2291 /// Runs "distcheck", a 'make check' from a tarball
2292 fn run(self, builder: &Builder<'_>) {
a1dfa0c6 2293 builder.info("Distcheck");
04454e1e 2294 let dir = builder.tempdir().join("distcheck");
2c00a5a8
XL
2295 let _ = fs::remove_dir_all(&dir);
2296 t!(fs::create_dir_all(&dir));
2297
2298 // Guarantee that these are built before we begin running.
2299 builder.ensure(dist::PlainSourceTarball);
2300 builder.ensure(dist::Src);
2301
2302 let mut cmd = Command::new("tar");
fc512014
XL
2303 cmd.arg("-xf")
2304 .arg(builder.ensure(dist::PlainSourceTarball).tarball())
94b46f34
XL
2305 .arg("--strip-components=1")
2306 .current_dir(&dir);
83c7162d 2307 builder.run(&mut cmd);
94b46f34
XL
2308 builder.run(
2309 Command::new("./configure")
2310 .args(&builder.config.configure_args)
2311 .arg("--enable-vendor")
2312 .current_dir(&dir),
2313 );
2314 builder.run(
5e7ed085 2315 Command::new(util::make(&builder.config.build.triple)).arg("check").current_dir(&dir),
94b46f34 2316 );
2c00a5a8
XL
2317
2318 // Now make sure that rust-src has all of libstd's dependencies
a1dfa0c6 2319 builder.info("Distcheck rust-src");
04454e1e 2320 let dir = builder.tempdir().join("distcheck-src");
2c00a5a8
XL
2321 let _ = fs::remove_dir_all(&dir);
2322 t!(fs::create_dir_all(&dir));
2323
2324 let mut cmd = Command::new("tar");
fc512014
XL
2325 cmd.arg("-xf")
2326 .arg(builder.ensure(dist::Src).tarball())
94b46f34
XL
2327 .arg("--strip-components=1")
2328 .current_dir(&dir);
83c7162d 2329 builder.run(&mut cmd);
2c00a5a8 2330
3dfed10e 2331 let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
94b46f34
XL
2332 builder.run(
2333 Command::new(&builder.initial_cargo)
2334 .arg("generate-lockfile")
2335 .arg("--manifest-path")
2336 .arg(&toml)
2337 .current_dir(&dir),
2338 );
2c00a5a8
XL
2339 }
2340}
2341
2342#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2343pub struct Bootstrap;
2344
2345impl Step for Bootstrap {
2346 type Output = ();
2347 const DEFAULT: bool = true;
2348 const ONLY_HOSTS: bool = true;
2c00a5a8 2349
9fa01778
XL
2350 /// Tests the build system itself.
2351 fn run(self, builder: &Builder<'_>) {
04454e1e
FG
2352 let mut check_bootstrap = Command::new(&builder.python());
2353 check_bootstrap.arg("bootstrap_test.py").current_dir(builder.src.join("src/bootstrap/"));
2354 try_run(builder, &mut check_bootstrap);
2355
83c7162d 2356 let mut cmd = Command::new(&builder.initial_cargo);
2c00a5a8 2357 cmd.arg("test")
94b46f34
XL
2358 .current_dir(builder.src.join("src/bootstrap"))
2359 .env("RUSTFLAGS", "-Cdebuginfo=2")
2360 .env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2361 .env("RUSTC_BOOTSTRAP", "1")
04454e1e 2362 .env("RUSTDOC", builder.rustdoc(builder.compiler(0, builder.build.build)))
94b46f34 2363 .env("RUSTC", &builder.initial_rustc);
0531ce1d
XL
2364 if let Some(flags) = option_env!("RUSTFLAGS") {
2365 // Use the same rustc flags for testing as for "normal" compilation,
2366 // so that Cargo doesn’t recompile the entire dependency graph every time:
2367 // https://github.com/rust-lang/rust/issues/49215
2368 cmd.env("RUSTFLAGS", flags);
2369 }
83c7162d 2370 if !builder.fail_fast {
2c00a5a8
XL
2371 cmd.arg("--no-fail-fast");
2372 }
04454e1e
FG
2373 match builder.doc_tests {
2374 DocTests::Only => {
2375 cmd.arg("--doc");
2376 }
2377 DocTests::No => {
2378 cmd.args(&["--lib", "--bins", "--examples", "--tests", "--benches"]);
2379 }
2380 DocTests::Yes => {}
2381 }
2382
83c7162d 2383 cmd.arg("--").args(&builder.config.cmd.test_args());
94b46f34
XL
2384 // rustbuild tests are racy on directory creation so just run them one at a time.
2385 // Since there's not many this shouldn't be a problem.
2386 cmd.arg("--test-threads=1");
83c7162d 2387 try_run(builder, &mut cmd);
2c00a5a8
XL
2388 }
2389
9fa01778 2390 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2c00a5a8
XL
2391 run.path("src/bootstrap")
2392 }
2393
9fa01778 2394 fn make_run(run: RunConfig<'_>) {
2c00a5a8
XL
2395 run.builder.ensure(Bootstrap);
2396 }
2397}
3dfed10e
XL
2398
2399#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2400pub struct TierCheck {
2401 pub compiler: Compiler,
3dfed10e
XL
2402}
2403
2404impl Step for TierCheck {
2405 type Output = ();
2406 const DEFAULT: bool = true;
2407 const ONLY_HOSTS: bool = true;
2408
2409 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2410 run.path("src/tools/tier-check")
2411 }
2412
2413 fn make_run(run: RunConfig<'_>) {
1b1a35ee
XL
2414 let compiler =
2415 run.builder.compiler_for(run.builder.top_stage, run.builder.build.build, run.target);
2416 run.builder.ensure(TierCheck { compiler });
3dfed10e
XL
2417 }
2418
2419 /// Tests the Platform Support page in the rustc book.
2420 fn run(self, builder: &Builder<'_>) {
1b1a35ee 2421 builder.ensure(compile::Std { compiler: self.compiler, target: self.compiler.host });
3dfed10e
XL
2422 let mut cargo = tool::prepare_tool_cargo(
2423 builder,
2424 self.compiler,
1b1a35ee
XL
2425 Mode::ToolStd,
2426 self.compiler.host,
3dfed10e
XL
2427 "run",
2428 "src/tools/tier-check",
2429 SourceType::InTree,
2430 &[],
2431 );
2432 cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2433 cargo.arg(&builder.rustc(self.compiler));
2434 if builder.is_verbose() {
2435 cargo.arg("--verbose");
2436 }
2437
2438 builder.info("platform support check");
2439 try_run(builder, &mut cargo.into());
2440 }
2441}
fc512014
XL
2442
2443#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2444pub struct LintDocs {
2445 pub compiler: Compiler,
2446 pub target: TargetSelection,
2447}
2448
2449impl Step for LintDocs {
2450 type Output = ();
2451 const DEFAULT: bool = true;
2452 const ONLY_HOSTS: bool = true;
2453
2454 fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2455 run.path("src/tools/lint-docs")
2456 }
2457
2458 fn make_run(run: RunConfig<'_>) {
2459 run.builder.ensure(LintDocs {
2460 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
2461 target: run.target,
2462 });
2463 }
2464
2465 /// Tests that the lint examples in the rustc book generate the correct
2466 /// lints and have the expected format.
2467 fn run(self, builder: &Builder<'_>) {
2468 builder.ensure(crate::doc::RustcBook {
2469 compiler: self.compiler,
2470 target: self.target,
2471 validate: true,
2472 });
2473 }
2474}