]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/builder/tests.rs
Simplify Cache wrapper to single type, impl Deref on it, fix all compilation errors...
[rust.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::Assemble>()),
370         &[
371             compile::Assemble {
372                 target_compiler: Compiler { host: a, stage: 0 },
373             },
374             compile::Assemble {
375                 target_compiler: Compiler { host: a, stage: 1 },
376             },
377             compile::Assemble {
378                 target_compiler: Compiler { host: a, stage: 2 },
379             },
380             compile::Assemble {
381                 target_compiler: Compiler { host: b, stage: 2 },
382             },
383         ]
384     );
385 }
386
387 #[test]
388 fn build_default() {
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), &[]);
392
393     let a = INTERNER.intern_str("A");
394     let b = INTERNER.intern_str("B");
395     let c = INTERNER.intern_str("C");
396
397     assert_eq!(
398         first(builder.cache.all::<compile::Std>()),
399         &[
400             compile::Std {
401                 compiler: Compiler { host: a, stage: 0 },
402                 target: a,
403             },
404             compile::Std {
405                 compiler: Compiler { host: a, stage: 1 },
406                 target: a,
407             },
408             compile::Std {
409                 compiler: Compiler { host: a, stage: 2 },
410                 target: a,
411             },
412             compile::Std {
413                 compiler: Compiler { host: b, stage: 2 },
414                 target: a,
415             },
416             compile::Std {
417                 compiler: Compiler { host: a, stage: 1 },
418                 target: b,
419             },
420             compile::Std {
421                 compiler: Compiler { host: a, stage: 2 },
422                 target: b,
423             },
424             compile::Std {
425                 compiler: Compiler { host: b, stage: 2 },
426                 target: b,
427             },
428             compile::Std {
429                 compiler: Compiler { host: a, stage: 2 },
430                 target: c,
431             },
432             compile::Std {
433                 compiler: Compiler { host: b, stage: 2 },
434                 target: c,
435             },
436         ]
437     );
438     assert!(!builder.cache.all::<compile::Assemble>().is_empty());
439     assert_eq!(
440         first(builder.cache.all::<compile::Rustc>()),
441         &[
442             compile::Rustc {
443                 compiler: Compiler { host: a, stage: 0 },
444                 target: a,
445             },
446             compile::Rustc {
447                 compiler: Compiler { host: a, stage: 1 },
448                 target: a,
449             },
450             compile::Rustc {
451                 compiler: Compiler { host: a, stage: 2 },
452                 target: a,
453             },
454             compile::Rustc {
455                 compiler: Compiler { host: b, stage: 2 },
456                 target: a,
457             },
458             compile::Rustc {
459                 compiler: Compiler { host: a, stage: 1 },
460                 target: b,
461             },
462             compile::Rustc {
463                 compiler: Compiler { host: a, stage: 2 },
464                 target: b,
465             },
466             compile::Rustc {
467                 compiler: Compiler { host: b, stage: 2 },
468                 target: b,
469             },
470         ]
471     );
472 }
473
474 #[test]
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), &[]);
481
482     let a = INTERNER.intern_str("A");
483     let b = INTERNER.intern_str("B");
484     let c = INTERNER.intern_str("C");
485
486     assert_eq!(
487         first(builder.cache.all::<compile::Std>()),
488         &[
489             compile::Std {
490                 compiler: Compiler { host: a, stage: 0 },
491                 target: a,
492             },
493             compile::Std {
494                 compiler: Compiler { host: a, stage: 1 },
495                 target: a,
496             },
497             compile::Std {
498                 compiler: Compiler { host: a, stage: 2 },
499                 target: a,
500             },
501             compile::Std {
502                 compiler: Compiler { host: b, stage: 2 },
503                 target: a,
504             },
505             compile::Std {
506                 compiler: Compiler { host: a, stage: 1 },
507                 target: b,
508             },
509             compile::Std {
510                 compiler: Compiler { host: a, stage: 2 },
511                 target: b,
512             },
513             compile::Std {
514                 compiler: Compiler { host: b, stage: 2 },
515                 target: b,
516             },
517             compile::Std {
518                 compiler: Compiler { host: a, stage: 2 },
519                 target: c,
520             },
521             compile::Std {
522                 compiler: Compiler { host: b, stage: 2 },
523                 target: c,
524             },
525         ]
526     );
527     assert_eq!(
528         first(builder.cache.all::<compile::Assemble>()),
529         &[
530             compile::Assemble {
531                 target_compiler: Compiler { host: a, stage: 0 },
532             },
533             compile::Assemble {
534                 target_compiler: Compiler { host: a, stage: 1 },
535             },
536             compile::Assemble {
537                 target_compiler: Compiler { host: a, stage: 2 },
538             },
539             compile::Assemble {
540                 target_compiler: Compiler { host: b, stage: 2 },
541             },
542         ]
543     );
544     assert_eq!(
545         first(builder.cache.all::<compile::Rustc>()),
546         &[
547             compile::Rustc {
548                 compiler: Compiler { host: a, stage: 0 },
549                 target: a,
550             },
551             compile::Rustc {
552                 compiler: Compiler { host: a, stage: 1 },
553                 target: a,
554             },
555             compile::Rustc {
556                 compiler: Compiler { host: a, stage: 1 },
557                 target: b,
558             },
559         ]
560     );
561 }
562
563 #[test]
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()],
569         test_args: vec![],
570         rustc_args: vec![],
571         fail_fast: true,
572         doc_tests: DocTests::No,
573         bless: false,
574         compare_mode: None,
575         rustfix_coverage: false,
576         pass: None,
577     };
578
579     let build = Build::new(config);
580     let mut builder = Builder::new(&build);
581
582     let host = INTERNER.intern_str("A");
583
584     builder.run_step_descriptions(
585         &[StepDescription::from::<test::Crate>()],
586         &["src/libstd".into()],
587     );
588
589     // Ensure we don't build any compiler artifacts.
590     assert!(!builder.cache.contains::<compile::Rustc>());
591     assert_eq!(
592         first(builder.cache.all::<test::Crate>()),
593         &[test::Crate {
594             compiler: Compiler { host, stage: 0 },
595             target: host,
596             mode: Mode::Std,
597             test_kind: test::TestKind::Test,
598             krate: INTERNER.intern_str("std"),
599         },]
600     );
601 }
602
603 #[test]
604 fn test_exclude() {
605     let mut config = configure(&[], &[]);
606     config.exclude = vec![
607         "src/tools/tidy".into(),
608     ];
609     config.cmd = Subcommand::Test {
610         paths: Vec::new(),
611         test_args: Vec::new(),
612         rustc_args: Vec::new(),
613         fail_fast: true,
614         doc_tests: DocTests::No,
615         bless: false,
616         compare_mode: None,
617         rustfix_coverage: false,
618         pass: None,
619     };
620
621     let build = Build::new(config);
622     let builder = Builder::new(&build);
623     builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
624
625     // Ensure we have really excluded tidy
626     assert!(!builder.cache.contains::<test::Tidy>());
627
628     // Ensure other tests are not affected.
629     assert!(builder.cache.contains::<test::RustdocUi>());
630 }