2 use crate::config::Config;
5 use pretty_assertions::assert_eq;
7 fn configure(host: &[&str], target: &[&str]) -> Config {
8 let mut config = Config::default_opts();
9 // don't save toolstates
10 config.save_toolstates = None;
11 config.skip_only_host_steps = false;
12 config.dry_run = true;
13 // try to avoid spurious failures in dist where we create/delete each others file
14 let dir = config.out.join("tmp-rustbuild-tests").join(
20 t!(fs::create_dir_all(&dir));
22 config.build = INTERNER.intern_str("A");
23 config.hosts = vec![config.build]
26 .chain(host.iter().map(|s| INTERNER.intern_str(s)))
28 config.targets = config
32 .chain(target.iter().map(|s| INTERNER.intern_str(s)))
37 fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
38 v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
43 let build = Build::new(configure(&[], &[]));
44 let mut builder = Builder::new(&build);
45 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
47 let a = INTERNER.intern_str("A");
50 first(builder.cache.all::<dist::Docs>()),
51 &[dist::Docs { host: a },]
54 first(builder.cache.all::<dist::Mingw>()),
55 &[dist::Mingw { host: a },]
58 first(builder.cache.all::<dist::Rustc>()),
60 compiler: Compiler { host: a, stage: 2 }
64 first(builder.cache.all::<dist::Std>()),
66 compiler: Compiler { host: a, stage: 1 },
70 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
74 fn dist_with_targets() {
75 let build = Build::new(configure(&[], &["B"]));
76 let mut builder = Builder::new(&build);
77 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
79 let a = INTERNER.intern_str("A");
80 let b = INTERNER.intern_str("B");
83 first(builder.cache.all::<dist::Docs>()),
85 dist::Docs { host: a },
86 dist::Docs { host: b },
90 first(builder.cache.all::<dist::Mingw>()),
91 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
94 first(builder.cache.all::<dist::Rustc>()),
96 compiler: Compiler { host: a, stage: 2 }
100 first(builder.cache.all::<dist::Std>()),
103 compiler: Compiler { host: a, stage: 1 },
107 compiler: Compiler { host: a, stage: 2 },
112 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
116 fn dist_with_hosts() {
117 let build = Build::new(configure(&["B"], &[]));
118 let mut builder = Builder::new(&build);
119 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
121 let a = INTERNER.intern_str("A");
122 let b = INTERNER.intern_str("B");
125 first(builder.cache.all::<dist::Docs>()),
127 dist::Docs { host: a },
128 dist::Docs { host: b },
132 first(builder.cache.all::<dist::Mingw>()),
133 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
136 first(builder.cache.all::<dist::Rustc>()),
139 compiler: Compiler { host: a, stage: 2 }
142 compiler: Compiler { host: b, stage: 2 }
147 first(builder.cache.all::<dist::Std>()),
150 compiler: Compiler { host: a, stage: 1 },
154 compiler: Compiler { host: a, stage: 1 },
159 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
163 fn dist_only_cross_host() {
164 let a = INTERNER.intern_str("A");
165 let b = INTERNER.intern_str("B");
166 let mut build = Build::new(configure(&["B"], &[]));
167 build.config.docs = false;
168 build.config.extended = true;
169 build.hosts = vec![b];
170 let mut builder = Builder::new(&build);
171 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
174 first(builder.cache.all::<dist::Rustc>()),
177 compiler: Compiler { host: b, stage: 2 }
182 first(builder.cache.all::<compile::Rustc>()),
185 compiler: Compiler { host: a, stage: 0 },
189 compiler: Compiler { host: a, stage: 1 },
197 fn dist_with_targets_and_hosts() {
198 let build = Build::new(configure(&["B"], &["C"]));
199 let mut builder = Builder::new(&build);
200 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
202 let a = INTERNER.intern_str("A");
203 let b = INTERNER.intern_str("B");
204 let c = INTERNER.intern_str("C");
207 first(builder.cache.all::<dist::Docs>()),
209 dist::Docs { host: a },
210 dist::Docs { host: b },
211 dist::Docs { host: c },
215 first(builder.cache.all::<dist::Mingw>()),
217 dist::Mingw { host: a },
218 dist::Mingw { host: b },
219 dist::Mingw { host: c },
223 first(builder.cache.all::<dist::Rustc>()),
226 compiler: Compiler { host: a, stage: 2 }
229 compiler: Compiler { host: b, stage: 2 }
234 first(builder.cache.all::<dist::Std>()),
237 compiler: Compiler { host: a, stage: 1 },
241 compiler: Compiler { host: a, stage: 1 },
245 compiler: Compiler { host: a, stage: 2 },
250 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
254 fn dist_with_target_flag() {
255 let mut config = configure(&["B"], &["C"]);
256 config.skip_only_host_steps = true; // as-if --target=C was passed
257 let build = Build::new(config);
258 let mut builder = Builder::new(&build);
259 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
261 let a = INTERNER.intern_str("A");
262 let b = INTERNER.intern_str("B");
263 let c = INTERNER.intern_str("C");
266 first(builder.cache.all::<dist::Docs>()),
268 dist::Docs { host: a },
269 dist::Docs { host: b },
270 dist::Docs { host: c },
274 first(builder.cache.all::<dist::Mingw>()),
276 dist::Mingw { host: a },
277 dist::Mingw { host: b },
278 dist::Mingw { host: c },
281 assert_eq!(first(builder.cache.all::<dist::Rustc>()), &[]);
283 first(builder.cache.all::<dist::Std>()),
286 compiler: Compiler { host: a, stage: 1 },
290 compiler: Compiler { host: a, stage: 1 },
294 compiler: Compiler { host: a, stage: 2 },
299 assert_eq!(first(builder.cache.all::<dist::Src>()), &[]);
303 fn dist_with_same_targets_and_hosts() {
304 let build = Build::new(configure(&["B"], &["B"]));
305 let mut builder = Builder::new(&build);
306 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
308 let a = INTERNER.intern_str("A");
309 let b = INTERNER.intern_str("B");
312 first(builder.cache.all::<dist::Docs>()),
314 dist::Docs { host: a },
315 dist::Docs { host: b },
319 first(builder.cache.all::<dist::Mingw>()),
320 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
323 first(builder.cache.all::<dist::Rustc>()),
326 compiler: Compiler { host: a, stage: 2 }
329 compiler: Compiler { host: b, stage: 2 }
334 first(builder.cache.all::<dist::Std>()),
337 compiler: Compiler { host: a, stage: 1 },
341 compiler: Compiler { host: a, stage: 1 },
346 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
348 first(builder.cache.all::<compile::Std>()),
351 compiler: Compiler { host: a, stage: 0 },
355 compiler: Compiler { host: a, stage: 1 },
359 compiler: Compiler { host: a, stage: 2 },
363 compiler: Compiler { host: a, stage: 1 },
369 first(builder.cache.all::<compile::Assemble>()),
372 target_compiler: Compiler { host: a, stage: 0 },
375 target_compiler: Compiler { host: a, stage: 1 },
378 target_compiler: Compiler { host: a, stage: 2 },
381 target_compiler: Compiler { host: b, stage: 2 },
389 let build = Build::new(configure(&["B"], &["C"]));
390 let mut builder = Builder::new(&build);
391 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
393 let a = INTERNER.intern_str("A");
394 let b = INTERNER.intern_str("B");
395 let c = INTERNER.intern_str("C");
398 first(builder.cache.all::<compile::Std>()),
401 compiler: Compiler { host: a, stage: 0 },
405 compiler: Compiler { host: a, stage: 1 },
409 compiler: Compiler { host: a, stage: 2 },
413 compiler: Compiler { host: b, stage: 2 },
417 compiler: Compiler { host: a, stage: 1 },
421 compiler: Compiler { host: a, stage: 2 },
425 compiler: Compiler { host: b, stage: 2 },
429 compiler: Compiler { host: a, stage: 2 },
433 compiler: Compiler { host: b, stage: 2 },
438 assert!(!builder.cache.all::<compile::Assemble>().is_empty());
440 first(builder.cache.all::<compile::Rustc>()),
443 compiler: Compiler { host: a, stage: 0 },
447 compiler: Compiler { host: a, stage: 1 },
451 compiler: Compiler { host: a, stage: 2 },
455 compiler: Compiler { host: b, stage: 2 },
459 compiler: Compiler { host: a, stage: 1 },
463 compiler: Compiler { host: a, stage: 2 },
467 compiler: Compiler { host: b, stage: 2 },
475 fn build_with_target_flag() {
476 let mut config = configure(&["B"], &["C"]);
477 config.skip_only_host_steps = true;
478 let build = Build::new(config);
479 let mut builder = Builder::new(&build);
480 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
482 let a = INTERNER.intern_str("A");
483 let b = INTERNER.intern_str("B");
484 let c = INTERNER.intern_str("C");
487 first(builder.cache.all::<compile::Std>()),
490 compiler: Compiler { host: a, stage: 0 },
494 compiler: Compiler { host: a, stage: 1 },
498 compiler: Compiler { host: a, stage: 2 },
502 compiler: Compiler { host: b, stage: 2 },
506 compiler: Compiler { host: a, stage: 1 },
510 compiler: Compiler { host: a, stage: 2 },
514 compiler: Compiler { host: b, stage: 2 },
518 compiler: Compiler { host: a, stage: 2 },
522 compiler: Compiler { host: b, stage: 2 },
528 first(builder.cache.all::<compile::Assemble>()),
531 target_compiler: Compiler { host: a, stage: 0 },
534 target_compiler: Compiler { host: a, stage: 1 },
537 target_compiler: Compiler { host: a, stage: 2 },
540 target_compiler: Compiler { host: b, stage: 2 },
545 first(builder.cache.all::<compile::Rustc>()),
548 compiler: Compiler { host: a, stage: 0 },
552 compiler: Compiler { host: a, stage: 1 },
556 compiler: Compiler { host: a, stage: 1 },
564 fn test_with_no_doc_stage0() {
565 let mut config = configure(&[], &[]);
566 config.stage = Some(0);
567 config.cmd = Subcommand::Test {
568 paths: vec!["src/libstd".into()],
572 doc_tests: DocTests::No,
575 rustfix_coverage: false,
579 let build = Build::new(config);
580 let mut builder = Builder::new(&build);
582 let host = INTERNER.intern_str("A");
584 builder.run_step_descriptions(
585 &[StepDescription::from::<test::Crate>()],
586 &["src/libstd".into()],
589 // Ensure we don't build any compiler artifacts.
590 assert!(!builder.cache.contains::<compile::Rustc>());
592 first(builder.cache.all::<test::Crate>()),
594 compiler: Compiler { host, stage: 0 },
597 test_kind: test::TestKind::Test,
598 krate: INTERNER.intern_str("std"),
605 let mut config = configure(&[], &[]);
606 config.exclude = vec![
607 "src/tools/tidy".into(),
609 config.cmd = Subcommand::Test {
611 test_args: Vec::new(),
612 rustc_args: Vec::new(),
614 doc_tests: DocTests::No,
617 rustfix_coverage: false,
621 let build = Build::new(config);
622 let builder = Builder::new(&build);
623 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
625 // Ensure we have really excluded tidy
626 assert!(!builder.cache.contains::<test::Tidy>());
628 // Ensure other tests are not affected.
629 assert!(builder.cache.contains::<test::RustdocUi>());