2 use crate::config::{Config, TargetSelection};
5 fn configure(host: &[&str], target: &[&str]) -> Config {
6 let mut config = Config::default_opts();
7 // don't save toolstates
8 config.save_toolstates = None;
9 config.skip_only_host_steps = false;
10 config.dry_run = true;
11 // try to avoid spurious failures in dist where we create/delete each others file
14 .join("tmp-rustbuild-tests")
15 .join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
16 t!(fs::create_dir_all(&dir));
18 config.build = TargetSelection::from_user("A");
19 config.hosts = vec![config.build]
21 .chain(host.iter().map(|s| TargetSelection::from_user(s)))
23 config.targets = config
27 .chain(target.iter().map(|s| TargetSelection::from_user(s)))
32 fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
33 v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
37 use super::{configure, first};
38 use crate::builder::*;
40 use pretty_assertions::assert_eq;
44 let build = Build::new(configure(&[], &[]));
45 let mut builder = Builder::new(&build);
46 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
48 let a = TargetSelection::from_user("A");
50 first(builder.cache.all::<compile::Std>()),
52 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
53 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
56 assert!(!builder.cache.all::<compile::Assemble>().is_empty());
57 // Make sure rustdoc is only built once.
59 first(builder.cache.all::<tool::Rustdoc>()),
60 // Recall that rustdoc stages are off-by-one
61 // - this is the compiler it's _linked_ to, not built with.
62 &[tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } }],
65 first(builder.cache.all::<compile::Rustc>()),
66 &[compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },]
72 let config = Config { stage: Some(0), ..configure(&[], &[]) };
73 let build = Build::new(config);
74 let mut builder = Builder::new(&build);
75 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
77 let a = TargetSelection::from_user("A");
79 first(builder.cache.all::<compile::Std>()),
80 &[compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },]
82 assert!(!builder.cache.all::<compile::Assemble>().is_empty());
84 first(builder.cache.all::<tool::Rustdoc>()),
85 // This is the beta rustdoc.
86 // Add an assert here to make sure this is the only rustdoc built.
87 &[tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } }],
89 assert!(builder.cache.all::<compile::Rustc>().is_empty());
94 let mut config = configure(&[], &[]);
95 config.compiler_docs = true;
96 config.cmd = Subcommand::Doc { paths: Vec::new(), open: false };
97 let build = Build::new(config);
98 let mut builder = Builder::new(&build);
99 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
100 let a = TargetSelection::from_user("A");
102 // error_index_generator uses stage 0 to share rustdoc artifacts with the
105 first(builder.cache.all::<doc::ErrorIndex>()),
106 &[doc::ErrorIndex { compiler: Compiler { host: a, stage: 0 }, target: a },]
109 first(builder.cache.all::<tool::ErrorIndex>()),
110 &[tool::ErrorIndex { compiler: Compiler { host: a, stage: 0 } }]
112 // docs should be built with the beta compiler, not with the stage0 artifacts.
113 // recall that rustdoc is off-by-one: `stage` is the compiler rustdoc is _linked_ to,
114 // not the one it was built by.
116 first(builder.cache.all::<tool::Rustdoc>()),
117 &[tool::Rustdoc { compiler: Compiler { host: a, stage: 0 } },]
123 use super::{first, Config};
124 use crate::builder::*;
125 use pretty_assertions::assert_eq;
127 fn configure(host: &[&str], target: &[&str]) -> Config {
128 Config { stage: Some(2), ..super::configure(host, target) }
133 let build = Build::new(configure(&[], &[]));
134 let mut builder = Builder::new(&build);
135 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
137 let a = TargetSelection::from_user("A");
139 assert_eq!(first(builder.cache.all::<dist::Docs>()), &[dist::Docs { host: a },]);
140 assert_eq!(first(builder.cache.all::<dist::Mingw>()), &[dist::Mingw { host: a },]);
142 first(builder.cache.all::<dist::Rustc>()),
143 &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
146 first(builder.cache.all::<dist::Std>()),
147 &[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },]
149 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
150 // Make sure rustdoc is only built once.
152 first(builder.cache.all::<tool::Rustdoc>()),
153 &[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
158 fn dist_with_targets() {
159 let build = Build::new(configure(&[], &["B"]));
160 let mut builder = Builder::new(&build);
161 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
163 let a = TargetSelection::from_user("A");
164 let b = TargetSelection::from_user("B");
167 first(builder.cache.all::<dist::Docs>()),
168 &[dist::Docs { host: a }, dist::Docs { host: b },]
171 first(builder.cache.all::<dist::Mingw>()),
172 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
175 first(builder.cache.all::<dist::Rustc>()),
176 &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
179 first(builder.cache.all::<dist::Std>()),
181 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
182 dist::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
185 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
189 fn dist_with_hosts() {
190 let build = Build::new(configure(&["B"], &[]));
191 let mut builder = Builder::new(&build);
192 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
194 let a = TargetSelection::from_user("A");
195 let b = TargetSelection::from_user("B");
198 first(builder.cache.all::<dist::Docs>()),
199 &[dist::Docs { host: a }, dist::Docs { host: b },]
202 first(builder.cache.all::<dist::Mingw>()),
203 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
206 first(builder.cache.all::<dist::Rustc>()),
208 dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
209 dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
213 first(builder.cache.all::<dist::Std>()),
215 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
216 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
219 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
223 fn dist_only_cross_host() {
224 let a = TargetSelection::from_user("A");
225 let b = TargetSelection::from_user("B");
226 let mut build = Build::new(configure(&["B"], &[]));
227 build.config.docs = false;
228 build.config.extended = true;
229 build.hosts = vec![b];
230 let mut builder = Builder::new(&build);
231 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
234 first(builder.cache.all::<dist::Rustc>()),
235 &[dist::Rustc { compiler: Compiler { host: b, stage: 2 } },]
238 first(builder.cache.all::<compile::Rustc>()),
240 compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
241 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
247 fn dist_with_targets_and_hosts() {
248 let build = Build::new(configure(&["B"], &["C"]));
249 let mut builder = Builder::new(&build);
250 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
252 let a = TargetSelection::from_user("A");
253 let b = TargetSelection::from_user("B");
254 let c = TargetSelection::from_user("C");
257 first(builder.cache.all::<dist::Docs>()),
258 &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },]
261 first(builder.cache.all::<dist::Mingw>()),
262 &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },]
265 first(builder.cache.all::<dist::Rustc>()),
267 dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
268 dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
272 first(builder.cache.all::<dist::Std>()),
274 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
275 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
276 dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
279 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
283 fn dist_with_target_flag() {
284 let mut config = configure(&["B"], &["C"]);
285 config.skip_only_host_steps = true; // as-if --target=C was passed
286 let build = Build::new(config);
287 let mut builder = Builder::new(&build);
288 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
290 let a = TargetSelection::from_user("A");
291 let b = TargetSelection::from_user("B");
292 let c = TargetSelection::from_user("C");
295 first(builder.cache.all::<dist::Docs>()),
296 &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },]
299 first(builder.cache.all::<dist::Mingw>()),
300 &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },]
302 assert_eq!(first(builder.cache.all::<dist::Rustc>()), &[]);
304 first(builder.cache.all::<dist::Std>()),
306 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
307 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
308 dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
311 assert_eq!(first(builder.cache.all::<dist::Src>()), &[]);
315 fn dist_with_same_targets_and_hosts() {
316 let build = Build::new(configure(&["B"], &["B"]));
317 let mut builder = Builder::new(&build);
318 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
320 let a = TargetSelection::from_user("A");
321 let b = TargetSelection::from_user("B");
324 first(builder.cache.all::<dist::Docs>()),
325 &[dist::Docs { host: a }, dist::Docs { host: b },]
328 first(builder.cache.all::<dist::Mingw>()),
329 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
332 first(builder.cache.all::<dist::Rustc>()),
334 dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
335 dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
339 first(builder.cache.all::<dist::Std>()),
341 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
342 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
345 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
347 first(builder.cache.all::<compile::Std>()),
349 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
350 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
351 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
352 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
353 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
357 first(builder.cache.all::<compile::Assemble>()),
359 compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
360 compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
361 compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
362 compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
369 let build = Build::new(configure(&["B"], &["C"]));
370 let mut builder = Builder::new(&build);
371 builder.run_step_descriptions(
372 &Builder::get_step_descriptions(Kind::Build),
373 &["src/rustc".into(), "library/std".into()],
376 let a = TargetSelection::from_user("A");
377 let b = TargetSelection::from_user("B");
378 let c = TargetSelection::from_user("C");
381 first(builder.cache.all::<compile::Std>()),
383 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
384 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
385 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
386 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a },
387 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
388 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
389 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b },
390 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
391 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c },
394 assert!(!builder.cache.all::<compile::Assemble>().is_empty());
396 first(builder.cache.all::<compile::Rustc>()),
398 compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
399 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
400 compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: a },
401 compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: a },
402 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
403 compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: b },
404 compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: b },
410 fn build_with_target_flag() {
411 let mut config = configure(&["B"], &["C"]);
412 config.skip_only_host_steps = true;
413 let build = Build::new(config);
414 let mut builder = Builder::new(&build);
415 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
417 let a = TargetSelection::from_user("A");
418 let b = TargetSelection::from_user("B");
419 let c = TargetSelection::from_user("C");
422 first(builder.cache.all::<compile::Std>()),
424 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
425 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
426 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
427 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a },
428 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
429 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
430 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b },
431 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
432 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c },
436 first(builder.cache.all::<compile::Assemble>()),
438 compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
439 compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
440 compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
441 compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
445 first(builder.cache.all::<compile::Rustc>()),
447 compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
448 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
449 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
455 fn test_with_no_doc_stage0() {
456 let mut config = configure(&[], &[]);
457 config.stage = Some(0);
458 config.cmd = Subcommand::Test {
459 paths: vec!["library/std".into()],
463 doc_tests: DocTests::No,
466 rustfix_coverage: false,
470 let build = Build::new(config);
471 let mut builder = Builder::new(&build);
473 let host = TargetSelection::from_user("A");
475 builder.run_step_descriptions(
476 &[StepDescription::from::<test::Crate>()],
477 &["library/std".into()],
480 // Ensure we don't build any compiler artifacts.
481 assert!(!builder.cache.contains::<compile::Rustc>());
483 first(builder.cache.all::<test::Crate>()),
485 compiler: Compiler { host, stage: 0 },
488 test_kind: test::TestKind::Test,
489 krate: INTERNER.intern_str("std"),
496 let mut config = configure(&[], &[]);
497 config.exclude = vec!["src/tools/tidy".into()];
498 config.cmd = Subcommand::Test {
500 test_args: Vec::new(),
501 rustc_args: Vec::new(),
503 doc_tests: DocTests::No,
506 rustfix_coverage: false,
510 let build = Build::new(config);
511 let builder = Builder::new(&build);
512 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
514 // Ensure we have really excluded tidy
515 assert!(!builder.cache.contains::<test::Tidy>());
517 // Ensure other tests are not affected.
518 assert!(builder.cache.contains::<test::RustdocUi>());
523 let mut config = configure(&[], &[]);
524 config.compiler_docs = true;
525 config.cmd = Subcommand::Doc { paths: Vec::new(), open: false };
526 let build = Build::new(config);
527 let mut builder = Builder::new(&build);
528 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Doc), &[]);
529 let a = TargetSelection::from_user("A");
531 // error_index_generator uses stage 1 to share rustdoc artifacts with the
534 first(builder.cache.all::<doc::ErrorIndex>()),
535 &[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
538 first(builder.cache.all::<tool::ErrorIndex>()),
539 &[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
541 // This is actually stage 1, but Rustdoc::run swaps out the compiler with
542 // stage minus 1 if --stage is not 0. Very confusing!
544 first(builder.cache.all::<tool::Rustdoc>()),
545 &[tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },]
551 // Behavior of `x.py test` doing various documentation tests.
552 let mut config = configure(&[], &[]);
553 config.cmd = Subcommand::Test {
558 doc_tests: DocTests::Yes,
561 rustfix_coverage: false,
564 let build = Build::new(config);
565 let mut builder = Builder::new(&build);
566 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
567 let a = TargetSelection::from_user("A");
569 // error_index_generator uses stage 1 to share rustdoc artifacts with the
572 first(builder.cache.all::<doc::ErrorIndex>()),
573 &[doc::ErrorIndex { compiler: Compiler { host: a, stage: 1 }, target: a },]
576 first(builder.cache.all::<tool::ErrorIndex>()),
577 &[tool::ErrorIndex { compiler: Compiler { host: a, stage: 1 } }]
579 // Unfortunately rustdoc is built twice. Once from stage1 for compiletest
580 // (and other things), and once from stage0 for std crates. Ideally it
581 // would only be built once. If someone wants to fix this, it might be
582 // worth investigating if it would be possible to test std from stage1.
583 // Note that the stages here are +1 than what they actually are because
584 // Rustdoc::run swaps out the compiler with stage minus 1 if --stage is
587 first(builder.cache.all::<tool::Rustdoc>()),
589 tool::Rustdoc { compiler: Compiler { host: a, stage: 1 } },
590 tool::Rustdoc { compiler: Compiler { host: a, stage: 2 } },