@@ -13,6 +13,7 @@ use std::process::{Command, Stdio};
1313use crate :: builder:: crate_description;
1414use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
1515use crate :: cache:: Interned ;
16+ use crate :: cache:: INTERNER ;
1617use crate :: compile;
1718use crate :: config:: TargetSelection ;
1819use crate :: dist;
@@ -85,7 +86,7 @@ impl Step for CrateJsonDocLint {
8586 SourceType :: InTree ,
8687 & [ ] ,
8788 ) ;
88- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
89+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
8990 }
9091}
9192
@@ -111,7 +112,7 @@ impl Step for SuggestTestsCrate {
111112 let bootstrap_host = builder. config . build ;
112113 let compiler = builder. compiler ( 0 , bootstrap_host) ;
113114
114- let suggest_tests = tool:: prepare_tool_cargo (
115+ let cargo = tool:: prepare_tool_cargo (
115116 builder,
116117 compiler,
117118 Mode :: ToolBootstrap ,
@@ -121,7 +122,7 @@ impl Step for SuggestTestsCrate {
121122 SourceType :: InTree ,
122123 & [ ] ,
123124 ) ;
124- add_flags_and_try_run_tests ( builder , & mut suggest_tests . into ( ) ) ;
125+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
125126 }
126127}
127128
@@ -170,7 +171,7 @@ You can skip linkcheck with --exclude src/tools/linkchecker"
170171 SourceType :: InTree ,
171172 & [ ] ,
172173 ) ;
173- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
174+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
174175
175176 // Build all the default documentation.
176177 builder. default_doc ( & [ ] ) ;
@@ -306,7 +307,7 @@ impl Step for Cargo {
306307 let compiler = builder. compiler ( self . stage , self . host ) ;
307308
308309 builder. ensure ( tool:: Cargo { compiler, target : self . host } ) ;
309- let mut cargo = tool:: prepare_tool_cargo (
310+ let cargo = tool:: prepare_tool_cargo (
310311 builder,
311312 compiler,
312313 Mode :: ToolRustc ,
@@ -317,21 +318,19 @@ impl Step for Cargo {
317318 & [ ] ,
318319 ) ;
319320
320- if !builder. fail_fast {
321- cargo. arg ( "--no-fail-fast" ) ;
322- }
323- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
321+ // NOTE: can't use `run_cargo_test` because we need to overwrite `PATH`
322+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, self . host , builder) ;
324323
325324 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
326325 // available.
327326 cargo. env ( "CFG_DISABLE_CROSS_TESTS" , "1" ) ;
328327 // Forcibly disable tests using nightly features since any changes to
329328 // those features won't be able to land.
330329 cargo. env ( "CARGO_TEST_DISABLE_NIGHTLY" , "1" ) ;
331-
332330 cargo. env ( "PATH" , & path_for_cargo ( builder, compiler) ) ;
333331
334- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
332+ let _time = util:: timeit ( & builder) ;
333+ add_flags_and_try_run_tests ( builder, & mut cargo) ;
335334 }
336335}
337336
@@ -388,9 +387,7 @@ impl Step for RustAnalyzer {
388387 cargo. env ( "SKIP_SLOW_TESTS" , "1" ) ;
389388
390389 cargo. add_rustc_lib_path ( builder, compiler) ;
391- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
392-
393- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
390+ run_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
394391 }
395392}
396393
@@ -433,17 +430,13 @@ impl Step for Rustfmt {
433430 & [ ] ,
434431 ) ;
435432
436- if !builder. fail_fast {
437- cargo. arg ( "--no-fail-fast" ) ;
438- }
439-
440433 let dir = testdir ( builder, compiler. host ) ;
441434 t ! ( fs:: create_dir_all( & dir) ) ;
442435 cargo. env ( "RUSTFMT_TEST_DIR" , dir) ;
443436
444437 cargo. add_rustc_lib_path ( builder, compiler) ;
445438
446- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
439+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
447440 }
448441}
449442
@@ -489,12 +482,9 @@ impl Step for RustDemangler {
489482 t ! ( fs:: create_dir_all( & dir) ) ;
490483
491484 cargo. env ( "RUST_DEMANGLER_DRIVER_PATH" , rust_demangler) ;
492-
493- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
494-
495485 cargo. add_rustc_lib_path ( builder, compiler) ;
496486
497- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
487+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
498488 }
499489}
500490
@@ -617,10 +607,6 @@ impl Step for Miri {
617607 ) ;
618608 cargo. add_rustc_lib_path ( builder, compiler) ;
619609
620- if !builder. fail_fast {
621- cargo. arg ( "--no-fail-fast" ) ;
622- }
623-
624610 // miri tests need to know about the stage sysroot
625611 cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
626612 cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
@@ -632,13 +618,14 @@ impl Step for Miri {
632618
633619 // Set the target.
634620 cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
635- // Forward test filters.
636- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
637621
638- // This can NOT be `add_flags_and_try_run_tests` since the Miri test runner
639- // does not understand those flags!
640- let mut cargo = Command :: from ( cargo) ;
641- builder. run ( & mut cargo) ;
622+ // This can NOT be `run_cargo_test` since the Miri test runner
623+ // does not understand the flags added by `add_flags_and_try_run_test`.
624+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, target, builder) ;
625+ {
626+ let _time = util:: timeit ( & builder) ;
627+ builder. run ( & mut cargo) ;
628+ }
642629
643630 // # Run `cargo miri test`.
644631 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
@@ -671,6 +658,7 @@ impl Step for Miri {
671658 cargo. env ( "RUST_BACKTRACE" , "1" ) ;
672659
673660 let mut cargo = Command :: from ( cargo) ;
661+ let _time = util:: timeit ( & builder) ;
674662 builder. run ( & mut cargo) ;
675663 }
676664}
@@ -710,8 +698,7 @@ impl Step for CompiletestTest {
710698 & [ ] ,
711699 ) ;
712700 cargo. allow_features ( "test" ) ;
713-
714- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
701+ run_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
715702 }
716703}
717704
@@ -763,11 +750,10 @@ impl Step for Clippy {
763750 let host_libs = builder. stage_out ( compiler, Mode :: ToolRustc ) . join ( builder. cargo_dir ( ) ) ;
764751 cargo. env ( "HOST_LIBS" , host_libs) ;
765752
766- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
767-
768753 cargo. add_rustc_lib_path ( builder, compiler) ;
754+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
769755
770- if builder. try_run ( & mut cargo. into ( ) ) {
756+ if builder. try_run ( & mut cargo) {
771757 // The tests succeeded; nothing to do.
772758 return ;
773759 }
@@ -1195,7 +1181,7 @@ impl Step for TidySelfTest {
11951181 SourceType :: InTree ,
11961182 & [ ] ,
11971183 ) ;
1198- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
1184+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
11991185 }
12001186}
12011187
@@ -2108,8 +2094,31 @@ impl Step for CrateLibrustc {
21082094 }
21092095}
21102096
2111- // Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2112- fn run_cargo_test ( cargo : impl Into < Command > , libtest_args : & [ & str ] , crates : & [ Interned < String > ] , compiler : Compiler , target : TargetSelection , builder : & Builder < ' _ > ) {
2097+ /// Given a `cargo test` subcommand, add the appropriate flags and run it.
2098+ ///
2099+ /// Returns whether the test succeeded.
2100+ fn run_cargo_test (
2101+ cargo : impl Into < Command > ,
2102+ libtest_args : & [ & str ] ,
2103+ crates : & [ Interned < String > ] ,
2104+ compiler : Compiler ,
2105+ target : TargetSelection ,
2106+ builder : & Builder < ' _ > ,
2107+ ) -> bool {
2108+ let mut cargo = prepare_cargo_test ( cargo, libtest_args, crates, compiler, target, builder) ;
2109+ let _time = util:: timeit ( & builder) ;
2110+ add_flags_and_try_run_tests ( builder, & mut cargo)
2111+ }
2112+
2113+ /// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2114+ fn prepare_cargo_test (
2115+ cargo : impl Into < Command > ,
2116+ libtest_args : & [ & str ] ,
2117+ crates : & [ Interned < String > ] ,
2118+ compiler : Compiler ,
2119+ target : TargetSelection ,
2120+ builder : & Builder < ' _ > ,
2121+ ) -> Command {
21132122 let mut cargo = cargo. into ( ) ;
21142123
21152124 // Pass in some standard flags then iterate over the graph we've discovered
@@ -2132,6 +2141,11 @@ fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[In
21322141 cargo. arg ( "-p" ) . arg ( krate) ;
21332142 }
21342143
2144+ cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2145+ if !builder. config . verbose_tests {
2146+ cargo. arg ( "--quiet" ) ;
2147+ }
2148+
21352149 // The tests are going to run with the *target* libraries, so we need to
21362150 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
21372151 //
@@ -2157,9 +2171,7 @@ fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[In
21572171 ) ;
21582172 }
21592173
2160- cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2161- let _time = util:: timeit ( & builder) ;
2162- add_flags_and_try_run_tests ( builder, & mut cargo) ;
2174+ cargo
21632175}
21642176
21652177#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -2281,24 +2293,6 @@ impl Step for CrateRustdoc {
22812293 SourceType :: InTree ,
22822294 & [ ] ,
22832295 ) ;
2284- if builder. kind == Kind :: Test && !builder. fail_fast {
2285- cargo. arg ( "--no-fail-fast" ) ;
2286- }
2287- match builder. doc_tests {
2288- DocTests :: Only => {
2289- cargo. arg ( "--doc" ) ;
2290- }
2291- DocTests :: No => {
2292- cargo. args ( & [ "--lib" , "--bins" , "--examples" , "--tests" , "--benches" ] ) ;
2293- }
2294- DocTests :: Yes => { }
2295- }
2296-
2297- cargo. arg ( "-p" ) . arg ( "rustdoc:0.0.0" ) ;
2298-
2299- cargo. arg ( "--" ) ;
2300- cargo. args ( & builder. config . cmd . test_args ( ) ) ;
2301-
23022296 if self . host . contains ( "musl" ) {
23032297 cargo. arg ( "'-Ctarget-feature=-crt-static'" ) ;
23042298 }
@@ -2338,15 +2332,15 @@ impl Step for CrateRustdoc {
23382332 dylib_path. insert ( 0 , PathBuf :: from ( & * libdir) ) ;
23392333 cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
23402334
2341- if !builder. config . verbose_tests {
2342- cargo. arg ( "--quiet" ) ;
2343- }
2344-
23452335 let _guard = builder. msg ( builder. kind , compiler. stage , "rustdoc" , compiler. host , target) ;
2346-
2347- let _time = util:: timeit ( & builder) ;
2348-
2349- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
2336+ run_cargo_test (
2337+ cargo,
2338+ & [ ] ,
2339+ & [ INTERNER . intern_str ( "rustdoc:0.0.0" ) ] ,
2340+ compiler,
2341+ target,
2342+ builder,
2343+ ) ;
23502344 }
23512345}
23522346
@@ -2380,7 +2374,7 @@ impl Step for CrateRustdocJsonTypes {
23802374 let compiler = builder. compiler_for ( builder. top_stage , target, target) ;
23812375 builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
23822376
2383- let mut cargo = tool:: prepare_tool_cargo (
2377+ let cargo = tool:: prepare_tool_cargo (
23842378 builder,
23852379 compiler,
23862380 Mode :: ToolRustc ,
@@ -2390,24 +2384,24 @@ impl Step for CrateRustdocJsonTypes {
23902384 SourceType :: InTree ,
23912385 & [ ] ,
23922386 ) ;
2393- if builder. kind == Kind :: Test && !builder. fail_fast {
2394- cargo. arg ( "--no-fail-fast" ) ;
2395- }
2396-
2397- cargo. arg ( "-p" ) . arg ( "rustdoc-json-types" ) ;
23982387
2399- cargo . arg ( "--" ) ;
2400- cargo . args ( & builder . config . cmd . test_args ( ) ) ;
2401-
2402- if self . host . contains ( "musl" ) {
2403- cargo . arg ( "'-Ctarget-feature=-crt-static'" ) ;
2404- }
2388+ // FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are fishy.
2389+ let libtest_args = if self . host . contains ( "musl" ) {
2390+ [ "'-Ctarget-feature=-crt-static'" ] . as_slice ( )
2391+ } else {
2392+ & [ ]
2393+ } ;
24052394
24062395 let _guard =
24072396 builder. msg ( builder. kind , compiler. stage , "rustdoc-json-types" , compiler. host , target) ;
2408- let _time = util:: timeit ( & builder) ;
2409-
2410- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
2397+ run_cargo_test (
2398+ cargo,
2399+ libtest_args,
2400+ & [ INTERNER . intern_str ( "rustdoc-json-types" ) ] ,
2401+ compiler,
2402+ target,
2403+ builder,
2404+ ) ;
24112405 }
24122406}
24132407
0 commit comments