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
16 .join("tmp-rustbuild-tests")
17 .join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
18 t!(fs::create_dir_all(&dir));
20 config.build = INTERNER.intern_str("A");
21 config.hosts = vec![config.build]
24 .chain(host.iter().map(|s| INTERNER.intern_str(s)))
26 config.targets = config
30 .chain(target.iter().map(|s| INTERNER.intern_str(s)))
35 fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
36 v.into_iter().map(|(a, _)| a).collect::<Vec<_>>()
41 let build = Build::new(configure(&[], &[]));
42 let mut builder = Builder::new(&build);
43 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
45 let a = INTERNER.intern_str("A");
47 assert_eq!(first(builder.cache.all::<dist::Docs>()), &[dist::Docs { host: a },]);
48 assert_eq!(first(builder.cache.all::<dist::Mingw>()), &[dist::Mingw { host: a },]);
50 first(builder.cache.all::<dist::Rustc>()),
51 &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
54 first(builder.cache.all::<dist::Std>()),
55 &[dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },]
57 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
61 fn dist_with_targets() {
62 let build = Build::new(configure(&[], &["B"]));
63 let mut builder = Builder::new(&build);
64 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
66 let a = INTERNER.intern_str("A");
67 let b = INTERNER.intern_str("B");
70 first(builder.cache.all::<dist::Docs>()),
71 &[dist::Docs { host: a }, dist::Docs { host: b },]
74 first(builder.cache.all::<dist::Mingw>()),
75 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
78 first(builder.cache.all::<dist::Rustc>()),
79 &[dist::Rustc { compiler: Compiler { host: a, stage: 2 } },]
82 first(builder.cache.all::<dist::Std>()),
84 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
85 dist::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
88 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
92 fn dist_with_hosts() {
93 let build = Build::new(configure(&["B"], &[]));
94 let mut builder = Builder::new(&build);
95 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
97 let a = INTERNER.intern_str("A");
98 let b = INTERNER.intern_str("B");
101 first(builder.cache.all::<dist::Docs>()),
102 &[dist::Docs { host: a }, dist::Docs { host: b },]
105 first(builder.cache.all::<dist::Mingw>()),
106 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
109 first(builder.cache.all::<dist::Rustc>()),
111 dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
112 dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
116 first(builder.cache.all::<dist::Std>()),
118 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
119 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
122 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
126 fn dist_only_cross_host() {
127 let a = INTERNER.intern_str("A");
128 let b = INTERNER.intern_str("B");
129 let mut build = Build::new(configure(&["B"], &[]));
130 build.config.docs = false;
131 build.config.extended = true;
132 build.hosts = vec![b];
133 let mut builder = Builder::new(&build);
134 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
137 first(builder.cache.all::<dist::Rustc>()),
138 &[dist::Rustc { compiler: Compiler { host: b, stage: 2 } },]
141 first(builder.cache.all::<compile::Rustc>()),
143 compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
144 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
150 fn dist_with_targets_and_hosts() {
151 let build = Build::new(configure(&["B"], &["C"]));
152 let mut builder = Builder::new(&build);
153 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
155 let a = INTERNER.intern_str("A");
156 let b = INTERNER.intern_str("B");
157 let c = INTERNER.intern_str("C");
160 first(builder.cache.all::<dist::Docs>()),
161 &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },]
164 first(builder.cache.all::<dist::Mingw>()),
165 &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },]
168 first(builder.cache.all::<dist::Rustc>()),
170 dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
171 dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
175 first(builder.cache.all::<dist::Std>()),
177 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
178 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
179 dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
182 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
186 fn dist_with_target_flag() {
187 let mut config = configure(&["B"], &["C"]);
188 config.skip_only_host_steps = true; // as-if --target=C was passed
189 let build = Build::new(config);
190 let mut builder = Builder::new(&build);
191 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
193 let a = INTERNER.intern_str("A");
194 let b = INTERNER.intern_str("B");
195 let c = INTERNER.intern_str("C");
198 first(builder.cache.all::<dist::Docs>()),
199 &[dist::Docs { host: a }, dist::Docs { host: b }, dist::Docs { host: c },]
202 first(builder.cache.all::<dist::Mingw>()),
203 &[dist::Mingw { host: a }, dist::Mingw { host: b }, dist::Mingw { host: c },]
205 assert_eq!(first(builder.cache.all::<dist::Rustc>()), &[]);
207 first(builder.cache.all::<dist::Std>()),
209 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
210 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
211 dist::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
214 assert_eq!(first(builder.cache.all::<dist::Src>()), &[]);
218 fn dist_with_same_targets_and_hosts() {
219 let build = Build::new(configure(&["B"], &["B"]));
220 let mut builder = Builder::new(&build);
221 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]);
223 let a = INTERNER.intern_str("A");
224 let b = INTERNER.intern_str("B");
227 first(builder.cache.all::<dist::Docs>()),
228 &[dist::Docs { host: a }, dist::Docs { host: b },]
231 first(builder.cache.all::<dist::Mingw>()),
232 &[dist::Mingw { host: a }, dist::Mingw { host: b },]
235 first(builder.cache.all::<dist::Rustc>()),
237 dist::Rustc { compiler: Compiler { host: a, stage: 2 } },
238 dist::Rustc { compiler: Compiler { host: b, stage: 2 } },
242 first(builder.cache.all::<dist::Std>()),
244 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
245 dist::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
248 assert_eq!(first(builder.cache.all::<dist::Src>()), &[dist::Src]);
250 first(builder.cache.all::<compile::Std>()),
252 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
253 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
254 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
255 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
256 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
260 first(builder.cache.all::<compile::Assemble>()),
262 compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
263 compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
264 compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
265 compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
272 let build = Build::new(configure(&["B"], &["C"]));
273 let mut builder = Builder::new(&build);
274 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
276 let a = INTERNER.intern_str("A");
277 let b = INTERNER.intern_str("B");
278 let c = INTERNER.intern_str("C");
281 first(builder.cache.all::<compile::Std>()),
283 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
284 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
285 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
286 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a },
287 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
288 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
289 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b },
290 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
291 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c },
294 assert!(!builder.cache.all::<compile::Assemble>().is_empty());
296 first(builder.cache.all::<compile::Rustc>()),
298 compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
299 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
300 compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: a },
301 compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: a },
302 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
303 compile::Rustc { compiler: Compiler { host: a, stage: 2 }, target: b },
304 compile::Rustc { compiler: Compiler { host: b, stage: 2 }, target: b },
310 fn build_with_target_flag() {
311 let mut config = configure(&["B"], &["C"]);
312 config.skip_only_host_steps = true;
313 let build = Build::new(config);
314 let mut builder = Builder::new(&build);
315 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Build), &[]);
317 let a = INTERNER.intern_str("A");
318 let b = INTERNER.intern_str("B");
319 let c = INTERNER.intern_str("C");
322 first(builder.cache.all::<compile::Std>()),
324 compile::Std { compiler: Compiler { host: a, stage: 0 }, target: a },
325 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: a },
326 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: a },
327 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: a },
328 compile::Std { compiler: Compiler { host: a, stage: 1 }, target: b },
329 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: b },
330 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: b },
331 compile::Std { compiler: Compiler { host: a, stage: 2 }, target: c },
332 compile::Std { compiler: Compiler { host: b, stage: 2 }, target: c },
336 first(builder.cache.all::<compile::Assemble>()),
338 compile::Assemble { target_compiler: Compiler { host: a, stage: 0 } },
339 compile::Assemble { target_compiler: Compiler { host: a, stage: 1 } },
340 compile::Assemble { target_compiler: Compiler { host: a, stage: 2 } },
341 compile::Assemble { target_compiler: Compiler { host: b, stage: 2 } },
345 first(builder.cache.all::<compile::Rustc>()),
347 compile::Rustc { compiler: Compiler { host: a, stage: 0 }, target: a },
348 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: a },
349 compile::Rustc { compiler: Compiler { host: a, stage: 1 }, target: b },
355 fn test_with_no_doc_stage0() {
356 let mut config = configure(&[], &[]);
357 config.stage = Some(0);
358 config.cmd = Subcommand::Test {
359 paths: vec!["src/libstd".into()],
363 doc_tests: DocTests::No,
366 rustfix_coverage: false,
370 let build = Build::new(config);
371 let mut builder = Builder::new(&build);
373 let host = INTERNER.intern_str("A");
376 .run_step_descriptions(&[StepDescription::from::<test::Crate>()], &["src/libstd".into()]);
378 // Ensure we don't build any compiler artifacts.
379 assert!(!builder.cache.contains::<compile::Rustc>());
381 first(builder.cache.all::<test::Crate>()),
383 compiler: Compiler { host, stage: 0 },
386 test_kind: test::TestKind::Test,
387 krate: INTERNER.intern_str("std"),
394 let mut config = configure(&[], &[]);
395 config.exclude = vec!["src/tools/tidy".into()];
396 config.cmd = Subcommand::Test {
398 test_args: Vec::new(),
399 rustc_args: Vec::new(),
401 doc_tests: DocTests::No,
404 rustfix_coverage: false,
408 let build = Build::new(config);
409 let builder = Builder::new(&build);
410 builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Test), &[]);
412 // Ensure we have really excluded tidy
413 assert!(!builder.cache.contains::<test::Tidy>());
415 // Ensure other tests are not affected.
416 assert!(builder.cache.contains::<test::RustdocUi>());