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