@@ -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 ( & [ ] ) ;
@@ -317,21 +318,15 @@ 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 ( ) ) ;
324-
325321 // Don't run cross-compile tests, we may not have cross-compiled libstd libs
326322 // available.
327323 cargo. env ( "CFG_DISABLE_CROSS_TESTS" , "1" ) ;
328324 // Forcibly disable tests using nightly features since any changes to
329325 // those features won't be able to land.
330326 cargo. env ( "CARGO_TEST_DISABLE_NIGHTLY" , "1" ) ;
331-
332327 cargo. env ( "PATH" , & path_for_cargo ( builder, compiler) ) ;
333328
334- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
329+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , self . host , builder ) ;
335330 }
336331}
337332
@@ -388,9 +383,7 @@ impl Step for RustAnalyzer {
388383 cargo. env ( "SKIP_SLOW_TESTS" , "1" ) ;
389384
390385 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 ( ) ) ;
386+ run_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
394387 }
395388}
396389
@@ -433,17 +426,13 @@ impl Step for Rustfmt {
433426 & [ ] ,
434427 ) ;
435428
436- if !builder. fail_fast {
437- cargo. arg ( "--no-fail-fast" ) ;
438- }
439-
440429 let dir = testdir ( builder, compiler. host ) ;
441430 t ! ( fs:: create_dir_all( & dir) ) ;
442431 cargo. env ( "RUSTFMT_TEST_DIR" , dir) ;
443432
444433 cargo. add_rustc_lib_path ( builder, compiler) ;
445434
446- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
435+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
447436 }
448437}
449438
@@ -489,12 +478,9 @@ impl Step for RustDemangler {
489478 t ! ( fs:: create_dir_all( & dir) ) ;
490479
491480 cargo. env ( "RUST_DEMANGLER_DRIVER_PATH" , rust_demangler) ;
492-
493- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
494-
495481 cargo. add_rustc_lib_path ( builder, compiler) ;
496482
497- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
483+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
498484 }
499485}
500486
@@ -617,10 +603,6 @@ impl Step for Miri {
617603 ) ;
618604 cargo. add_rustc_lib_path ( builder, compiler) ;
619605
620- if !builder. fail_fast {
621- cargo. arg ( "--no-fail-fast" ) ;
622- }
623-
624606 // miri tests need to know about the stage sysroot
625607 cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
626608 cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
@@ -632,13 +614,14 @@ impl Step for Miri {
632614
633615 // Set the target.
634616 cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
635- // Forward test filters.
636- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
637617
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) ;
618+ // This can NOT be `run_cargo_test` since the Miri test runner
619+ // does not understand the flags added by `add_flags_and_try_run_test`.
620+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, target, builder) ;
621+ {
622+ let _time = util:: timeit ( & builder) ;
623+ builder. run ( & mut cargo) ;
624+ }
642625
643626 // # Run `cargo miri test`.
644627 // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures
@@ -671,6 +654,7 @@ impl Step for Miri {
671654 cargo. env ( "RUST_BACKTRACE" , "1" ) ;
672655
673656 let mut cargo = Command :: from ( cargo) ;
657+ let _time = util:: timeit ( & builder) ;
674658 builder. run ( & mut cargo) ;
675659 }
676660}
@@ -710,8 +694,7 @@ impl Step for CompiletestTest {
710694 & [ ] ,
711695 ) ;
712696 cargo. allow_features ( "test" ) ;
713-
714- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
697+ run_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
715698 }
716699}
717700
@@ -763,11 +746,10 @@ impl Step for Clippy {
763746 let host_libs = builder. stage_out ( compiler, Mode :: ToolRustc ) . join ( builder. cargo_dir ( ) ) ;
764747 cargo. env ( "HOST_LIBS" , host_libs) ;
765748
766- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
767-
768749 cargo. add_rustc_lib_path ( builder, compiler) ;
750+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
769751
770- if builder. try_run ( & mut cargo. into ( ) ) {
752+ if builder. try_run ( & mut cargo) {
771753 // The tests succeeded; nothing to do.
772754 return ;
773755 }
@@ -1195,7 +1177,7 @@ impl Step for TidySelfTest {
11951177 SourceType :: InTree ,
11961178 & [ ] ,
11971179 ) ;
1198- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
1180+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
11991181 }
12001182}
12011183
@@ -2101,8 +2083,31 @@ impl Step for CrateLibrustc {
21012083 }
21022084}
21032085
2104- // Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2105- fn run_cargo_test ( cargo : impl Into < Command > , libtest_args : & [ & str ] , crates : & [ Interned < String > ] , compiler : Compiler , target : TargetSelection , builder : & Builder < ' _ > ) {
2086+ /// Given a `cargo test` subcommand, add the appropriate flags and run it.
2087+ ///
2088+ /// Returns whether the test succeeded.
2089+ fn run_cargo_test (
2090+ cargo : impl Into < Command > ,
2091+ libtest_args : & [ & str ] ,
2092+ crates : & [ Interned < String > ] ,
2093+ compiler : Compiler ,
2094+ target : TargetSelection ,
2095+ builder : & Builder < ' _ > ,
2096+ ) -> bool {
2097+ let mut cargo = prepare_cargo_test ( cargo, libtest_args, crates, compiler, target, builder) ;
2098+ let _time = util:: timeit ( & builder) ;
2099+ add_flags_and_try_run_tests ( builder, & mut cargo)
2100+ }
2101+
2102+ /// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2103+ fn prepare_cargo_test (
2104+ cargo : impl Into < Command > ,
2105+ libtest_args : & [ & str ] ,
2106+ crates : & [ Interned < String > ] ,
2107+ compiler : Compiler ,
2108+ target : TargetSelection ,
2109+ builder : & Builder < ' _ > ,
2110+ ) -> Command {
21062111 let mut cargo = cargo. into ( ) ;
21072112
21082113 // Pass in some standard flags then iterate over the graph we've discovered
@@ -2125,6 +2130,11 @@ fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[In
21252130 cargo. arg ( "-p" ) . arg ( krate) ;
21262131 }
21272132
2133+ cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2134+ if !builder. config . verbose_tests {
2135+ cargo. arg ( "--quiet" ) ;
2136+ }
2137+
21282138 // The tests are going to run with the *target* libraries, so we need to
21292139 // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
21302140 //
@@ -2150,9 +2160,7 @@ fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[In
21502160 ) ;
21512161 }
21522162
2153- cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2154- let _time = util:: timeit ( & builder) ;
2155- add_flags_and_try_run_tests ( builder, & mut cargo) ;
2163+ cargo
21562164}
21572165
21582166#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -2275,24 +2283,6 @@ impl Step for CrateRustdoc {
22752283 SourceType :: InTree ,
22762284 & [ ] ,
22772285 ) ;
2278- if builder. kind == Kind :: Test && !builder. fail_fast {
2279- cargo. arg ( "--no-fail-fast" ) ;
2280- }
2281- match builder. doc_tests {
2282- DocTests :: Only => {
2283- cargo. arg ( "--doc" ) ;
2284- }
2285- DocTests :: No => {
2286- cargo. args ( & [ "--lib" , "--bins" , "--examples" , "--tests" , "--benches" ] ) ;
2287- }
2288- DocTests :: Yes => { }
2289- }
2290-
2291- cargo. arg ( "-p" ) . arg ( "rustdoc:0.0.0" ) ;
2292-
2293- cargo. arg ( "--" ) ;
2294- cargo. args ( & builder. config . cmd . test_args ( ) ) ;
2295-
22962286 if self . host . contains ( "musl" ) {
22972287 cargo. arg ( "'-Ctarget-feature=-crt-static'" ) ;
22982288 }
@@ -2332,20 +2322,21 @@ impl Step for CrateRustdoc {
23322322 dylib_path. insert ( 0 , PathBuf :: from ( & * libdir) ) ;
23332323 cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
23342324
2335- if !builder. config . verbose_tests {
2336- cargo. arg ( "--quiet" ) ;
2337- }
2338-
23392325 builder. info ( & format ! (
23402326 "{} rustdoc stage{} ({} -> {})" ,
23412327 builder. kind. test_description( ) ,
23422328 compiler. stage,
23432329 & compiler. host,
23442330 target
23452331 ) ) ;
2346- let _time = util:: timeit ( & builder) ;
2347-
2348- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
2332+ run_cargo_test (
2333+ cargo,
2334+ & [ ] ,
2335+ & [ INTERNER . intern_str ( "rustdoc:0.0.0" ) ] ,
2336+ compiler,
2337+ target,
2338+ builder,
2339+ ) ;
23492340 }
23502341}
23512342
@@ -2379,7 +2370,7 @@ impl Step for CrateRustdocJsonTypes {
23792370 let compiler = builder. compiler_for ( builder. top_stage , target, target) ;
23802371 builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
23812372
2382- let mut cargo = tool:: prepare_tool_cargo (
2373+ let cargo = tool:: prepare_tool_cargo (
23832374 builder,
23842375 compiler,
23852376 Mode :: ToolRustc ,
@@ -2389,18 +2380,13 @@ impl Step for CrateRustdocJsonTypes {
23892380 SourceType :: InTree ,
23902381 & [ ] ,
23912382 ) ;
2392- if builder. kind == Kind :: Test && !builder. fail_fast {
2393- cargo. arg ( "--no-fail-fast" ) ;
2394- }
2395-
2396- cargo. arg ( "-p" ) . arg ( "rustdoc-json-types" ) ;
23972383
2398- cargo . arg ( "--" ) ;
2399- cargo . args ( & builder . config . cmd . test_args ( ) ) ;
2400-
2401- if self . host . contains ( "musl" ) {
2402- cargo . arg ( "'-Ctarget-feature=-crt-static'" ) ;
2403- }
2384+ // FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are fishy.
2385+ let libtest_args = if self . host . contains ( "musl" ) {
2386+ [ "'-Ctarget-feature=-crt-static'" ] . as_slice ( )
2387+ } else {
2388+ & [ ]
2389+ } ;
24042390
24052391 builder. info ( & format ! (
24062392 "{} rustdoc-json-types stage{} ({} -> {})" ,
@@ -2409,9 +2395,14 @@ impl Step for CrateRustdocJsonTypes {
24092395 & compiler. host,
24102396 target
24112397 ) ) ;
2412- let _time = util:: timeit ( & builder) ;
2413-
2414- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
2398+ run_cargo_test (
2399+ cargo,
2400+ libtest_args,
2401+ & [ INTERNER . intern_str ( "rustdoc-json-types" ) ] ,
2402+ compiler,
2403+ target,
2404+ builder,
2405+ ) ;
24152406 }
24162407}
24172408
0 commit comments