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