]> git.proxmox.com Git - rustc.git/blob - src/bootstrap/builder/tests.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / bootstrap / builder / tests.rs
1 use super::*;
2 use crate::config::Config;
3 use std::thread;
4
5 use pretty_assertions::assert_eq;
6
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(
15 &thread::current()
16 .name()
17 .unwrap_or("unknown")
18 .replace(":", "-"),
19 );
20 t!(fs::create_dir_all(&dir));
21 config.out = dir;
22 config.build = INTERNER.intern_str("A");
23 config.hosts = vec![config.build]
24 .clone()
25 .into_iter()
26 .chain(host.iter().map(|s| INTERNER.intern_str(s)))
27 .collect::<Vec<_>>();
28 config.targets = config
29 .hosts
30 .clone()
31 .into_iter()
32 .chain(target.iter().map(|s| INTERNER.intern_str(s)))
33 .collect::<Vec<_>>();
34 config
35 }
36
37 fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
38 v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
39 }
40
41 #[test]
42 fn dist_baseline() {
43 let build = Build::new(configure(&[], &[]));
44 let mut builder = Builder::new(&build);
45 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
46
47 let a = INTERNER.intern_str("A");
48
49 assert_eq!(
50 first(builder.cache.all::<dist::Docs>()),
51 &[dist::Docs { host: a },]
52 );
53 assert_eq!(
54 first(builder.cache.all::<dist::Mingw>()),
55 &[dist::Mingw { host: a },]
56 );
57 assert_eq!(
58 first(builder.cache.all::<dist::Rustc>()),
59 &[dist::Rustc {
60 compiler: Compiler { host: a, stage: 2 }
61 },]
62 );
63 assert_eq!(
64 first(builder.cache.all::<dist::Std>()),
65 &[dist::Std {
66 compiler: Compiler { host: a, stage: 1 },
67 target: a,
68 },]
69 );
70 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
71 }
72
73 #[test]
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), &[]);
78
79 let a = INTERNER.intern_str("A");
80 let b = INTERNER.intern_str("B");
81
82 assert_eq!(
83 first(builder.cache.all::<dist::Docs>()),
84 &[
85 dist::Docs { host: a },
86 dist::Docs { host: b },
87 ]
88 );
89 assert_eq!(
90 first(builder.cache.all::<dist::Mingw>()),
91 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
92 );
93 assert_eq!(
94 first(builder.cache.all::<dist::Rustc>()),
95 &[dist::Rustc {
96 compiler: Compiler { host: a, stage: 2 }
97 },]
98 );
99 assert_eq!(
100 first(builder.cache.all::<dist::Std>()),
101 &[
102 dist::Std {
103 compiler: Compiler { host: a, stage: 1 },
104 target: a,
105 },
106 dist::Std {
107 compiler: Compiler { host: a, stage: 2 },
108 target: b,
109 },
110 ]
111 );
112 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
113 }
114
115 #[test]
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), &[]);
120
121 let a = INTERNER.intern_str("A");
122 let b = INTERNER.intern_str("B");
123
124 assert_eq!(
125 first(builder.cache.all::<dist::Docs>()),
126 &[
127 dist::Docs { host: a },
128 dist::Docs { host: b },
129 ]
130 );
131 assert_eq!(
132 first(builder.cache.all::<dist::Mingw>()),
133 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
134 );
135 assert_eq!(
136 first(builder.cache.all::<dist::Rustc>()),
137 &[
138 dist::Rustc {
139 compiler: Compiler { host: a, stage: 2 }
140 },
141 dist::Rustc {
142 compiler: Compiler { host: b, stage: 2 }
143 },
144 ]
145 );
146 assert_eq!(
147 first(builder.cache.all::<dist::Std>()),
148 &[
149 dist::Std {
150 compiler: Compiler { host: a, stage: 1 },
151 target: a,
152 },
153 dist::Std {
154 compiler: Compiler { host: a, stage: 1 },
155 target: b,
156 },
157 ]
158 );
159 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
160 }
161
162 #[test]
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), &[]);
172
173 assert_eq!(
174 first(builder.cache.all::<dist::Rustc>()),
175 &[
176 dist::Rustc {
177 compiler: Compiler { host: b, stage: 2 }
178 },
179 ]
180 );
181 assert_eq!(
182 first(builder.cache.all::<compile::Rustc>()),
183 &[
184 compile::Rustc {
185 compiler: Compiler { host: a, stage: 0 },
186 target: a,
187 },
188 compile::Rustc {
189 compiler: Compiler { host: a, stage: 1 },
190 target: b,
191 },
192 ]
193 );
194 }
195
196 #[test]
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), &[]);
201
202 let a = INTERNER.intern_str("A");
203 let b = INTERNER.intern_str("B");
204 let c = INTERNER.intern_str("C");
205
206 assert_eq!(
207 first(builder.cache.all::<dist::Docs>()),
208 &[
209 dist::Docs { host: a },
210 dist::Docs { host: b },
211 dist::Docs { host: c },
212 ]
213 );
214 assert_eq!(
215 first(builder.cache.all::<dist::Mingw>()),
216 &[
217 dist::Mingw { host: a },
218 dist::Mingw { host: b },
219 dist::Mingw { host: c },
220 ]
221 );
222 assert_eq!(
223 first(builder.cache.all::<dist::Rustc>()),
224 &[
225 dist::Rustc {
226 compiler: Compiler { host: a, stage: 2 }
227 },
228 dist::Rustc {
229 compiler: Compiler { host: b, stage: 2 }
230 },
231 ]
232 );
233 assert_eq!(
234 first(builder.cache.all::<dist::Std>()),
235 &[
236 dist::Std {
237 compiler: Compiler { host: a, stage: 1 },
238 target: a,
239 },
240 dist::Std {
241 compiler: Compiler { host: a, stage: 1 },
242 target: b,
243 },
244 dist::Std {
245 compiler: Compiler { host: a, stage: 2 },
246 target: c,
247 },
248 ]
249 );
250 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
251 }
252
253 #[test]
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), &[]);
260
261 let a = INTERNER.intern_str("A");
262 let b = INTERNER.intern_str("B");
263 let c = INTERNER.intern_str("C");
264
265 assert_eq!(
266 first(builder.cache.all::<dist::Docs>()),
267 &[
268 dist::Docs { host: a },
269 dist::Docs { host: b },
270 dist::Docs { host: c },
271 ]
272 );
273 assert_eq!(
274 first(builder.cache.all::<dist::Mingw>()),
275 &[
276 dist::Mingw { host: a },
277 dist::Mingw { host: b },
278 dist::Mingw { host: c },
279 ]
280 );
281 assert_eq!(first(builder.cache.all::<dist::Rustc>()), &[]);
282 assert_eq!(
283 first(builder.cache.all::<dist::Std>()),
284 &[
285 dist::Std {
286 compiler: Compiler { host: a, stage: 1 },
287 target: a,
288 },
289 dist::Std {
290 compiler: Compiler { host: a, stage: 1 },
291 target: b,
292 },
293 dist::Std {
294 compiler: Compiler { host: a, stage: 2 },
295 target: c,
296 },
297 ]
298 );
299 assert_eq!(first(builder.cache.all::<dist::Src>()), &[]);
300 }
301
302 #[test]
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), &[]);
307
308 let a = INTERNER.intern_str("A");
309 let b = INTERNER.intern_str("B");
310
311 assert_eq!(
312 first(builder.cache.all::<dist::Docs>()),
313 &[
314 dist::Docs { host: a },
315 dist::Docs { host: b },
316 ]
317 );
318 assert_eq!(
319 first(builder.cache.all::<dist::Mingw>()),
320 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
321 );
322 assert_eq!(
323 first(builder.cache.all::<dist::Rustc>()),
324 &[
325 dist::Rustc {
326 compiler: Compiler { host: a, stage: 2 }
327 },
328 dist::Rustc {
329 compiler: Compiler { host: b, stage: 2 }
330 },
331 ]
332 );
333 assert_eq!(
334 first(builder.cache.all::<dist::Std>()),
335 &[
336 dist::Std {
337 compiler: Compiler { host: a, stage: 1 },
338 target: a,
339 },
340 dist::Std {
341 compiler: Compiler { host: a, stage: 1 },
342 target: b,
343 },
344 ]
345 );
346 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
347 assert_eq!(
348 first(builder.cache.all::<compile::Std>()),
349 &[
350 compile::Std {
351 compiler: Compiler { host: a, stage: 0 },
352 target: a,
353 },
354 compile::Std {
355 compiler: Compiler { host: a, stage: 1 },
356 target: a,
357 },
358 compile::Std {
359 compiler: Compiler { host: a, stage: 2 },
360 target: a,
361 },
362 compile::Std {
363 compiler: Compiler { host: a, stage: 1 },
364 target: b,
365 },
366 ]
367 );
368 assert_eq!(
369 first(builder.cache.all::<compile::Test>()),
370 &[
371 compile::Test {
372 compiler: Compiler { host: a, stage: 0 },
373 target: a,
374 },
375 compile::Test {
376 compiler: Compiler { host: a, stage: 1 },
377 target: a,
378 },
379 compile::Test {
380 compiler: Compiler { host: a, stage: 2 },
381 target: a,
382 },
383 compile::Test {
384 compiler: Compiler { host: a, stage: 1 },
385 target: b,
386 },
387 ]
388 );
389 assert_eq!(
390 first(builder.cache.all::<compile::Assemble>()),
391 &[
392 compile::Assemble {
393 target_compiler: Compiler { host: a, stage: 0 },
394 },
395 compile::Assemble {
396 target_compiler: Compiler { host: a, stage: 1 },
397 },
398 compile::Assemble {
399 target_compiler: Compiler { host: a, stage: 2 },
400 },
401 compile::Assemble {
402 target_compiler: Compiler { host: b, stage: 2 },
403 },
404 ]
405 );
406 }
407
408 #[test]
409 fn build_default() {
410 let build = Build::new(configure(&["B"], &["C"]));
411 let mut builder = Builder::new(&build);
412 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
413
414 let a = INTERNER.intern_str("A");
415 let b = INTERNER.intern_str("B");
416 let c = INTERNER.intern_str("C");
417
418 assert!(!builder.cache.all::<compile::Std>().is_empty());
419 assert!(!builder.cache.all::<compile::Assemble>().is_empty());
420 assert_eq!(
421 first(builder.cache.all::<compile::Rustc>()),
422 &[
423 compile::Rustc {
424 compiler: Compiler { host: a, stage: 0 },
425 target: a,
426 },
427 compile::Rustc {
428 compiler: Compiler { host: a, stage: 1 },
429 target: a,
430 },
431 compile::Rustc {
432 compiler: Compiler { host: a, stage: 2 },
433 target: a,
434 },
435 compile::Rustc {
436 compiler: Compiler { host: b, stage: 2 },
437 target: a,
438 },
439 compile::Rustc {
440 compiler: Compiler { host: a, stage: 1 },
441 target: b,
442 },
443 compile::Rustc {
444 compiler: Compiler { host: a, stage: 2 },
445 target: b,
446 },
447 compile::Rustc {
448 compiler: Compiler { host: b, stage: 2 },
449 target: b,
450 },
451 ]
452 );
453
454 assert_eq!(
455 first(builder.cache.all::<compile::Test>()),
456 &[
457 compile::Test {
458 compiler: Compiler { host: a, stage: 0 },
459 target: a,
460 },
461 compile::Test {
462 compiler: Compiler { host: a, stage: 1 },
463 target: a,
464 },
465 compile::Test {
466 compiler: Compiler { host: a, stage: 2 },
467 target: a,
468 },
469 compile::Test {
470 compiler: Compiler { host: b, stage: 2 },
471 target: a,
472 },
473 compile::Test {
474 compiler: Compiler { host: a, stage: 1 },
475 target: b,
476 },
477 compile::Test {
478 compiler: Compiler { host: a, stage: 2 },
479 target: b,
480 },
481 compile::Test {
482 compiler: Compiler { host: b, stage: 2 },
483 target: b,
484 },
485 compile::Test {
486 compiler: Compiler { host: a, stage: 2 },
487 target: c,
488 },
489 compile::Test {
490 compiler: Compiler { host: b, stage: 2 },
491 target: c,
492 },
493 ]
494 );
495 }
496
497 #[test]
498 fn build_with_target_flag() {
499 let mut config = configure(&["B"], &["C"]);
500 config.skip_only_host_steps = true;
501 let build = Build::new(config);
502 let mut builder = Builder::new(&build);
503 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
504
505 let a = INTERNER.intern_str("A");
506 let b = INTERNER.intern_str("B");
507 let c = INTERNER.intern_str("C");
508
509 assert!(!builder.cache.all::<compile::Std>().is_empty());
510 assert_eq!(
511 first(builder.cache.all::<compile::Assemble>()),
512 &[
513 compile::Assemble {
514 target_compiler: Compiler { host: a, stage: 0 },
515 },
516 compile::Assemble {
517 target_compiler: Compiler { host: a, stage: 1 },
518 },
519 compile::Assemble {
520 target_compiler: Compiler { host: a, stage: 2 },
521 },
522 compile::Assemble {
523 target_compiler: Compiler { host: b, stage: 2 },
524 },
525 ]
526 );
527 assert_eq!(
528 first(builder.cache.all::<compile::Rustc>()),
529 &[
530 compile::Rustc {
531 compiler: Compiler { host: a, stage: 0 },
532 target: a,
533 },
534 compile::Rustc {
535 compiler: Compiler { host: a, stage: 1 },
536 target: a,
537 },
538 compile::Rustc {
539 compiler: Compiler { host: a, stage: 1 },
540 target: b,
541 },
542 ]
543 );
544
545 assert_eq!(
546 first(builder.cache.all::<compile::Test>()),
547 &[
548 compile::Test {
549 compiler: Compiler { host: a, stage: 0 },
550 target: a,
551 },
552 compile::Test {
553 compiler: Compiler { host: a, stage: 1 },
554 target: a,
555 },
556 compile::Test {
557 compiler: Compiler { host: a, stage: 2 },
558 target: a,
559 },
560 compile::Test {
561 compiler: Compiler { host: b, stage: 2 },
562 target: a,
563 },
564 compile::Test {
565 compiler: Compiler { host: a, stage: 1 },
566 target: b,
567 },
568 compile::Test {
569 compiler: Compiler { host: a, stage: 2 },
570 target: b,
571 },
572 compile::Test {
573 compiler: Compiler { host: b, stage: 2 },
574 target: b,
575 },
576 compile::Test {
577 compiler: Compiler { host: a, stage: 2 },
578 target: c,
579 },
580 compile::Test {
581 compiler: Compiler { host: b, stage: 2 },
582 target: c,
583 },
584 ]
585 );
586 }
587
588 #[test]
589 fn test_with_no_doc_stage0() {
590 let mut config = configure(&[], &[]);
591 config.stage = Some(0);
592 config.cmd = Subcommand::Test {
593 paths: vec!["src/libstd".into()],
594 test_args: vec![],
595 rustc_args: vec![],
596 fail_fast: true,
597 doc_tests: DocTests::No,
598 bless: false,
599 compare_mode: None,
600 rustfix_coverage: false,
601 pass: None,
602 };
603
604 let build = Build::new(config);
605 let mut builder = Builder::new(&build);
606
607 let host = INTERNER.intern_str("A");
608
609 builder.run_step_descriptions(
610 &[StepDescription::from::<test::Crate>()],
611 &["src/libstd".into()],
612 );
613
614 // Ensure we don't build any compiler artifacts.
615 assert!(!builder.cache.contains::<compile::Rustc>());
616 assert_eq!(
617 first(builder.cache.all::<test::Crate>()),
618 &[test::Crate {
619 compiler: Compiler { host, stage: 0 },
620 target: host,
621 mode: Mode::Std,
622 test_kind: test::TestKind::Test,
623 krate: INTERNER.intern_str("std"),
624 },]
625 );
626 }
627
628 #[test]
629 fn test_exclude() {
630 let mut config = configure(&[], &[]);
631 config.exclude = vec![
632 "src/tools/tidy".into(),
633 ];
634 config.cmd = Subcommand::Test {
635 paths: Vec::new(),
636 test_args: Vec::new(),
637 rustc_args: Vec::new(),
638 fail_fast: true,
639 doc_tests: DocTests::No,
640 bless: false,
641 compare_mode: None,
642 rustfix_coverage: false,
643 pass: None,
644 };
645
646 let build = Build::new(config);
647 let builder = Builder::new(&build);
648 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
649
650 // Ensure we have really excluded tidy
651 assert!(!builder.cache.contains::<test::Tidy>());
652
653 // Ensure other tests are not affected.
654 assert!(builder.cache.contains::<test::RustdocUi>());
655 }