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
]
23 .chain(host
.iter().map(|s
| INTERNER
.intern_str(s
)))
25 config
.targets
= config
29 .chain(target
.iter().map(|s
| INTERNER
.intern_str(s
)))
34 fn first
<A
, B
>(v
: Vec
<(A
, B
)>) -> Vec
<A
> {
35 v
.into_iter().map(|(a
, _
)| a
).collect
::<Vec
<_
>>()
40 let build
= Build
::new(configure(&[], &[]));
41 let mut builder
= Builder
::new(&build
);
42 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
44 let a
= INTERNER
.intern_str("A");
46 assert_eq
!(first(builder
.cache
.all
::<dist
::Docs
>()), &[dist
::Docs { host: a }
,]);
47 assert_eq
!(first(builder
.cache
.all
::<dist
::Mingw
>()), &[dist
::Mingw { host: a }
,]);
49 first(builder
.cache
.all
::<dist
::Rustc
>()),
50 &[dist
::Rustc { compiler: Compiler { host: a, stage: 2 }
},]
53 first(builder
.cache
.all
::<dist
::Std
>()),
54 &[dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},]
56 assert_eq
!(first(builder
.cache
.all
::<dist
::Src
>()), &[dist
::Src
]);
57 // Make sure rustdoc is only built once.
59 first(builder
.cache
.all
::<tool
::Rustdoc
>()),
60 &[tool
::Rustdoc { compiler: Compiler { host: a, stage: 2 }
},]
65 fn dist_with_targets() {
66 let build
= Build
::new(configure(&[], &["B"]));
67 let mut builder
= Builder
::new(&build
);
68 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
70 let a
= INTERNER
.intern_str("A");
71 let b
= INTERNER
.intern_str("B");
74 first(builder
.cache
.all
::<dist
::Docs
>()),
75 &[dist
::Docs { host: a }
, dist
::Docs { host: b }
,]
78 first(builder
.cache
.all
::<dist
::Mingw
>()),
79 &[dist
::Mingw { host: a }
, dist
::Mingw { host: b }
,]
82 first(builder
.cache
.all
::<dist
::Rustc
>()),
83 &[dist
::Rustc { compiler: Compiler { host: a, stage: 2 }
},]
86 first(builder
.cache
.all
::<dist
::Std
>()),
88 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
89 dist
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: b
},
92 assert_eq
!(first(builder
.cache
.all
::<dist
::Src
>()), &[dist
::Src
]);
96 fn dist_with_hosts() {
97 let build
= Build
::new(configure(&["B"], &[]));
98 let mut builder
= Builder
::new(&build
);
99 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
101 let a
= INTERNER
.intern_str("A");
102 let b
= INTERNER
.intern_str("B");
105 first(builder
.cache
.all
::<dist
::Docs
>()),
106 &[dist
::Docs { host: a }
, dist
::Docs { host: b }
,]
109 first(builder
.cache
.all
::<dist
::Mingw
>()),
110 &[dist
::Mingw { host: a }
, dist
::Mingw { host: b }
,]
113 first(builder
.cache
.all
::<dist
::Rustc
>()),
115 dist
::Rustc { compiler: Compiler { host: a, stage: 2 }
},
116 dist
::Rustc { compiler: Compiler { host: b, stage: 2 }
},
120 first(builder
.cache
.all
::<dist
::Std
>()),
122 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
123 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
126 assert_eq
!(first(builder
.cache
.all
::<dist
::Src
>()), &[dist
::Src
]);
130 fn dist_only_cross_host() {
131 let a
= INTERNER
.intern_str("A");
132 let b
= INTERNER
.intern_str("B");
133 let mut build
= Build
::new(configure(&["B"], &[]));
134 build
.config
.docs
= false;
135 build
.config
.extended
= true;
136 build
.hosts
= vec
![b
];
137 let mut builder
= Builder
::new(&build
);
138 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
141 first(builder
.cache
.all
::<dist
::Rustc
>()),
142 &[dist
::Rustc { compiler: Compiler { host: b, stage: 2 }
},]
145 first(builder
.cache
.all
::<compile
::Rustc
>()),
147 compile
::Rustc { compiler: Compiler { host: a, stage: 0 }
, target
: a
},
148 compile
::Rustc { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
154 fn dist_with_targets_and_hosts() {
155 let build
= Build
::new(configure(&["B"], &["C"]));
156 let mut builder
= Builder
::new(&build
);
157 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
159 let a
= INTERNER
.intern_str("A");
160 let b
= INTERNER
.intern_str("B");
161 let c
= INTERNER
.intern_str("C");
164 first(builder
.cache
.all
::<dist
::Docs
>()),
165 &[dist
::Docs { host: a }
, dist
::Docs { host: b }
, dist
::Docs { host: c }
,]
168 first(builder
.cache
.all
::<dist
::Mingw
>()),
169 &[dist
::Mingw { host: a }
, dist
::Mingw { host: b }
, dist
::Mingw { host: c }
,]
172 first(builder
.cache
.all
::<dist
::Rustc
>()),
174 dist
::Rustc { compiler: Compiler { host: a, stage: 2 }
},
175 dist
::Rustc { compiler: Compiler { host: b, 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: 1 }
, target
: b
},
183 dist
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: c
},
186 assert_eq
!(first(builder
.cache
.all
::<dist
::Src
>()), &[dist
::Src
]);
190 fn dist_with_target_flag() {
191 let mut config
= configure(&["B"], &["C"]);
192 config
.skip_only_host_steps
= true; // as-if --target=C was passed
193 let build
= Build
::new(config
);
194 let mut builder
= Builder
::new(&build
);
195 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
197 let a
= INTERNER
.intern_str("A");
198 let b
= INTERNER
.intern_str("B");
199 let c
= INTERNER
.intern_str("C");
202 first(builder
.cache
.all
::<dist
::Docs
>()),
203 &[dist
::Docs { host: a }
, dist
::Docs { host: b }
, dist
::Docs { host: c }
,]
206 first(builder
.cache
.all
::<dist
::Mingw
>()),
207 &[dist
::Mingw { host: a }
, dist
::Mingw { host: b }
, dist
::Mingw { host: c }
,]
209 assert_eq
!(first(builder
.cache
.all
::<dist
::Rustc
>()), &[]);
211 first(builder
.cache
.all
::<dist
::Std
>()),
213 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
214 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
215 dist
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: c
},
218 assert_eq
!(first(builder
.cache
.all
::<dist
::Src
>()), &[]);
222 fn dist_with_same_targets_and_hosts() {
223 let build
= Build
::new(configure(&["B"], &["B"]));
224 let mut builder
= Builder
::new(&build
);
225 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Dist
), &[]);
227 let a
= INTERNER
.intern_str("A");
228 let b
= INTERNER
.intern_str("B");
231 first(builder
.cache
.all
::<dist
::Docs
>()),
232 &[dist
::Docs { host: a }
, dist
::Docs { host: b }
,]
235 first(builder
.cache
.all
::<dist
::Mingw
>()),
236 &[dist
::Mingw { host: a }
, dist
::Mingw { host: b }
,]
239 first(builder
.cache
.all
::<dist
::Rustc
>()),
241 dist
::Rustc { compiler: Compiler { host: a, stage: 2 }
},
242 dist
::Rustc { compiler: Compiler { host: b, stage: 2 }
},
246 first(builder
.cache
.all
::<dist
::Std
>()),
248 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
249 dist
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
252 assert_eq
!(first(builder
.cache
.all
::<dist
::Src
>()), &[dist
::Src
]);
254 first(builder
.cache
.all
::<compile
::Std
>()),
256 compile
::Std { compiler: Compiler { host: a, stage: 0 }
, target
: a
},
257 compile
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
258 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: a
},
259 compile
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
260 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: b
},
264 first(builder
.cache
.all
::<compile
::Assemble
>()),
266 compile
::Assemble { target_compiler: Compiler { host: a, stage: 0 }
},
267 compile
::Assemble { target_compiler: Compiler { host: a, stage: 1 }
},
268 compile
::Assemble { target_compiler: Compiler { host: a, stage: 2 }
},
269 compile
::Assemble { target_compiler: Compiler { host: b, stage: 2 }
},
276 let build
= Build
::new(configure(&["B"], &["C"]));
277 let mut builder
= Builder
::new(&build
);
278 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Build
), &[]);
280 let a
= INTERNER
.intern_str("A");
281 let b
= INTERNER
.intern_str("B");
282 let c
= INTERNER
.intern_str("C");
285 first(builder
.cache
.all
::<compile
::Std
>()),
287 compile
::Std { compiler: Compiler { host: a, stage: 0 }
, target
: a
},
288 compile
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
289 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: a
},
290 compile
::Std { compiler: Compiler { host: b, stage: 2 }
, target
: a
},
291 compile
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
292 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: b
},
293 compile
::Std { compiler: Compiler { host: b, stage: 2 }
, target
: b
},
294 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: c
},
295 compile
::Std { compiler: Compiler { host: b, stage: 2 }
, target
: c
},
298 assert
!(!builder
.cache
.all
::<compile
::Assemble
>().is_empty());
300 first(builder
.cache
.all
::<compile
::Rustc
>()),
302 compile
::Rustc { compiler: Compiler { host: a, stage: 0 }
, target
: a
},
303 compile
::Rustc { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
304 compile
::Rustc { compiler: Compiler { host: a, stage: 2 }
, target
: a
},
305 compile
::Rustc { compiler: Compiler { host: b, stage: 2 }
, target
: a
},
306 compile
::Rustc { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
307 compile
::Rustc { compiler: Compiler { host: a, stage: 2 }
, target
: b
},
308 compile
::Rustc { compiler: Compiler { host: b, stage: 2 }
, target
: b
},
314 fn build_with_target_flag() {
315 let mut config
= configure(&["B"], &["C"]);
316 config
.skip_only_host_steps
= true;
317 let build
= Build
::new(config
);
318 let mut builder
= Builder
::new(&build
);
319 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Build
), &[]);
321 let a
= INTERNER
.intern_str("A");
322 let b
= INTERNER
.intern_str("B");
323 let c
= INTERNER
.intern_str("C");
326 first(builder
.cache
.all
::<compile
::Std
>()),
328 compile
::Std { compiler: Compiler { host: a, stage: 0 }
, target
: a
},
329 compile
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
330 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: a
},
331 compile
::Std { compiler: Compiler { host: b, stage: 2 }
, target
: a
},
332 compile
::Std { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
333 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: b
},
334 compile
::Std { compiler: Compiler { host: b, stage: 2 }
, target
: b
},
335 compile
::Std { compiler: Compiler { host: a, stage: 2 }
, target
: c
},
336 compile
::Std { compiler: Compiler { host: b, stage: 2 }
, target
: c
},
340 first(builder
.cache
.all
::<compile
::Assemble
>()),
342 compile
::Assemble { target_compiler: Compiler { host: a, stage: 0 }
},
343 compile
::Assemble { target_compiler: Compiler { host: a, stage: 1 }
},
344 compile
::Assemble { target_compiler: Compiler { host: a, stage: 2 }
},
345 compile
::Assemble { target_compiler: Compiler { host: b, stage: 2 }
},
349 first(builder
.cache
.all
::<compile
::Rustc
>()),
351 compile
::Rustc { compiler: Compiler { host: a, stage: 0 }
, target
: a
},
352 compile
::Rustc { compiler: Compiler { host: a, stage: 1 }
, target
: a
},
353 compile
::Rustc { compiler: Compiler { host: a, stage: 1 }
, target
: b
},
359 fn test_with_no_doc_stage0() {
360 let mut config
= configure(&[], &[]);
361 config
.stage
= Some(0);
362 config
.cmd
= Subcommand
::Test
{
363 paths
: vec
!["src/libstd".into()],
367 doc_tests
: DocTests
::No
,
370 rustfix_coverage
: false,
374 let build
= Build
::new(config
);
375 let mut builder
= Builder
::new(&build
);
377 let host
= INTERNER
.intern_str("A");
380 .run_step_descriptions(&[StepDescription
::from
::<test
::Crate
>()], &["src/libstd".into()]);
382 // Ensure we don't build any compiler artifacts.
383 assert
!(!builder
.cache
.contains
::<compile
::Rustc
>());
385 first(builder
.cache
.all
::<test
::Crate
>()),
387 compiler
: Compiler { host, stage: 0 }
,
390 test_kind
: test
::TestKind
::Test
,
391 krate
: INTERNER
.intern_str("std"),
398 let mut config
= configure(&[], &[]);
399 config
.exclude
= vec
!["src/tools/tidy".into()];
400 config
.cmd
= Subcommand
::Test
{
402 test_args
: Vec
::new(),
403 rustc_args
: Vec
::new(),
405 doc_tests
: DocTests
::No
,
408 rustfix_coverage
: false,
412 let build
= Build
::new(config
);
413 let builder
= Builder
::new(&build
);
414 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Test
), &[]);
416 // Ensure we have really excluded tidy
417 assert
!(!builder
.cache
.contains
::<test
::Tidy
>());
419 // Ensure other tests are not affected.
420 assert
!(builder
.cache
.contains
::<test
::RustdocUi
>());
425 let mut config
= configure(&[], &[]);
426 config
.compiler_docs
= true;
427 config
.cmd
= Subcommand
::Doc { paths: Vec::new(), open: false }
;
428 let build
= Build
::new(config
);
429 let mut builder
= Builder
::new(&build
);
430 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Doc
), &[]);
431 let a
= INTERNER
.intern_str("A");
433 // error_index_generator uses stage 1 to share rustdoc artifacts with the
436 first(builder
.cache
.all
::<doc
::ErrorIndex
>()),
437 &[doc
::ErrorIndex { compiler: Compiler { host: a, stage: 1 }
, target
: a
},]
440 first(builder
.cache
.all
::<tool
::ErrorIndex
>()),
441 &[tool
::ErrorIndex { compiler: Compiler { host: a, stage: 1 }
}]
443 // This is actually stage 1, but Rustdoc::run swaps out the compiler with
444 // stage minus 1 if --stage is not 0. Very confusing!
446 first(builder
.cache
.all
::<tool
::Rustdoc
>()),
447 &[tool
::Rustdoc { compiler: Compiler { host: a, stage: 2 }
},]
453 // Behavior of `x.py test` doing various documentation tests.
454 let mut config
= configure(&[], &[]);
455 config
.cmd
= Subcommand
::Test
{
460 doc_tests
: DocTests
::Yes
,
463 rustfix_coverage
: false,
466 let build
= Build
::new(config
);
467 let mut builder
= Builder
::new(&build
);
468 builder
.run_step_descriptions(&Builder
::get_step_descriptions(Kind
::Test
), &[]);
469 let a
= INTERNER
.intern_str("A");
471 // error_index_generator uses stage 1 to share rustdoc artifacts with the
474 first(builder
.cache
.all
::<doc
::ErrorIndex
>()),
475 &[doc
::ErrorIndex { compiler: Compiler { host: a, stage: 1 }
, target
: a
},]
478 first(builder
.cache
.all
::<tool
::ErrorIndex
>()),
479 &[tool
::ErrorIndex { compiler: Compiler { host: a, stage: 1 }
}]
481 // Unfortunately rustdoc is built twice. Once from stage1 for compiletest
482 // (and other things), and once from stage0 for std crates. Ideally it
483 // would only be built once. If someone wants to fix this, it might be
484 // worth investigating if it would be possible to test std from stage1.
485 // Note that the stages here are +1 than what they actually are because
486 // Rustdoc::run swaps out the compiler with stage minus 1 if --stage is
489 first(builder
.cache
.all
::<tool
::Rustdoc
>()),
491 tool
::Rustdoc { compiler: Compiler { host: a, stage: 1 }
},
492 tool
::Rustdoc { compiler: Compiler { host: a, stage: 2 }
},