@@ -13,6 +13,7 @@ use std::process::{Command, Stdio};
13
13
use crate :: builder:: crate_description;
14
14
use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
15
15
use crate :: cache:: Interned ;
16
+ use crate :: cache:: INTERNER ;
16
17
use crate :: compile;
17
18
use crate :: config:: TargetSelection ;
18
19
use crate :: dist;
@@ -85,7 +86,7 @@ impl Step for CrateJsonDocLint {
85
86
SourceType :: InTree ,
86
87
& [ ] ,
87
88
) ;
88
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
89
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
89
90
}
90
91
}
91
92
@@ -111,7 +112,7 @@ impl Step for SuggestTestsCrate {
111
112
let bootstrap_host = builder. config . build ;
112
113
let compiler = builder. compiler ( 0 , bootstrap_host) ;
113
114
114
- let suggest_tests = tool:: prepare_tool_cargo (
115
+ let cargo = tool:: prepare_tool_cargo (
115
116
builder,
116
117
compiler,
117
118
Mode :: ToolBootstrap ,
@@ -121,7 +122,7 @@ impl Step for SuggestTestsCrate {
121
122
SourceType :: InTree ,
122
123
& [ ] ,
123
124
) ;
124
- add_flags_and_try_run_tests ( builder , & mut suggest_tests . into ( ) ) ;
125
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
125
126
}
126
127
}
127
128
@@ -170,7 +171,7 @@ You can skip linkcheck with --exclude src/tools/linkchecker"
170
171
SourceType :: InTree ,
171
172
& [ ] ,
172
173
) ;
173
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
174
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
174
175
175
176
// Build all the default documentation.
176
177
builder. default_doc ( & [ ] ) ;
@@ -317,21 +318,15 @@ impl Step for Cargo {
317
318
& [ ] ,
318
319
) ;
319
320
320
- if !builder. fail_fast {
321
- cargo. arg ( "--no-fail-fast" ) ;
322
- }
323
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
324
-
325
321
// Don't run cross-compile tests, we may not have cross-compiled libstd libs
326
322
// available.
327
323
cargo. env ( "CFG_DISABLE_CROSS_TESTS" , "1" ) ;
328
324
// Forcibly disable tests using nightly features since any changes to
329
325
// those features won't be able to land.
330
326
cargo. env ( "CARGO_TEST_DISABLE_NIGHTLY" , "1" ) ;
331
-
332
327
cargo. env ( "PATH" , & path_for_cargo ( builder, compiler) ) ;
333
328
334
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
329
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , self . host , builder ) ;
335
330
}
336
331
}
337
332
@@ -388,9 +383,7 @@ impl Step for RustAnalyzer {
388
383
cargo. env ( "SKIP_SLOW_TESTS" , "1" ) ;
389
384
390
385
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) ;
394
387
}
395
388
}
396
389
@@ -433,17 +426,13 @@ impl Step for Rustfmt {
433
426
& [ ] ,
434
427
) ;
435
428
436
- if !builder. fail_fast {
437
- cargo. arg ( "--no-fail-fast" ) ;
438
- }
439
-
440
429
let dir = testdir ( builder, compiler. host ) ;
441
430
t ! ( fs:: create_dir_all( & dir) ) ;
442
431
cargo. env ( "RUSTFMT_TEST_DIR" , dir) ;
443
432
444
433
cargo. add_rustc_lib_path ( builder, compiler) ;
445
434
446
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
435
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
447
436
}
448
437
}
449
438
@@ -489,12 +478,9 @@ impl Step for RustDemangler {
489
478
t ! ( fs:: create_dir_all( & dir) ) ;
490
479
491
480
cargo. env ( "RUST_DEMANGLER_DRIVER_PATH" , rust_demangler) ;
492
-
493
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
494
-
495
481
cargo. add_rustc_lib_path ( builder, compiler) ;
496
482
497
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
483
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
498
484
}
499
485
}
500
486
@@ -617,10 +603,6 @@ impl Step for Miri {
617
603
) ;
618
604
cargo. add_rustc_lib_path ( builder, compiler) ;
619
605
620
- if !builder. fail_fast {
621
- cargo. arg ( "--no-fail-fast" ) ;
622
- }
623
-
624
606
// miri tests need to know about the stage sysroot
625
607
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
626
608
cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
@@ -632,13 +614,14 @@ impl Step for Miri {
632
614
633
615
// Set the target.
634
616
cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
635
- // Forward test filters.
636
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
637
617
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
+ }
642
625
643
626
// # Run `cargo miri test`.
644
627
// 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 {
671
654
cargo. env ( "RUST_BACKTRACE" , "1" ) ;
672
655
673
656
let mut cargo = Command :: from ( cargo) ;
657
+ let _time = util:: timeit ( & builder) ;
674
658
builder. run ( & mut cargo) ;
675
659
}
676
660
}
@@ -710,8 +694,7 @@ impl Step for CompiletestTest {
710
694
& [ ] ,
711
695
) ;
712
696
cargo. allow_features ( "test" ) ;
713
-
714
- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
697
+ run_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
715
698
}
716
699
}
717
700
@@ -763,11 +746,10 @@ impl Step for Clippy {
763
746
let host_libs = builder. stage_out ( compiler, Mode :: ToolRustc ) . join ( builder. cargo_dir ( ) ) ;
764
747
cargo. env ( "HOST_LIBS" , host_libs) ;
765
748
766
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
767
-
768
749
cargo. add_rustc_lib_path ( builder, compiler) ;
750
+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
769
751
770
- if builder. try_run ( & mut cargo. into ( ) ) {
752
+ if builder. try_run ( & mut cargo) {
771
753
// The tests succeeded; nothing to do.
772
754
return ;
773
755
}
@@ -1195,7 +1177,7 @@ impl Step for TidySelfTest {
1195
1177
SourceType :: InTree ,
1196
1178
& [ ] ,
1197
1179
) ;
1198
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
1180
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
1199
1181
}
1200
1182
}
1201
1183
@@ -2101,8 +2083,31 @@ impl Step for CrateLibrustc {
2101
2083
}
2102
2084
}
2103
2085
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 {
2106
2111
let mut cargo = cargo. into ( ) ;
2107
2112
2108
2113
// 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
2125
2130
cargo. arg ( "-p" ) . arg ( krate) ;
2126
2131
}
2127
2132
2133
+ cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2134
+ if !builder. config . verbose_tests {
2135
+ cargo. arg ( "--quiet" ) ;
2136
+ }
2137
+
2128
2138
// The tests are going to run with the *target* libraries, so we need to
2129
2139
// ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2130
2140
//
@@ -2150,9 +2160,7 @@ fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[In
2150
2160
) ;
2151
2161
}
2152
2162
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
2156
2164
}
2157
2165
2158
2166
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -2275,24 +2283,6 @@ impl Step for CrateRustdoc {
2275
2283
SourceType :: InTree ,
2276
2284
& [ ] ,
2277
2285
) ;
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
-
2296
2286
if self . host . contains ( "musl" ) {
2297
2287
cargo. arg ( "'-Ctarget-feature=-crt-static'" ) ;
2298
2288
}
@@ -2332,20 +2322,21 @@ impl Step for CrateRustdoc {
2332
2322
dylib_path. insert ( 0 , PathBuf :: from ( & * libdir) ) ;
2333
2323
cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
2334
2324
2335
- if !builder. config . verbose_tests {
2336
- cargo. arg ( "--quiet" ) ;
2337
- }
2338
-
2339
2325
builder. info ( & format ! (
2340
2326
"{} rustdoc stage{} ({} -> {})" ,
2341
2327
builder. kind. test_description( ) ,
2342
2328
compiler. stage,
2343
2329
& compiler. host,
2344
2330
target
2345
2331
) ) ;
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
+ ) ;
2349
2340
}
2350
2341
}
2351
2342
@@ -2379,7 +2370,7 @@ impl Step for CrateRustdocJsonTypes {
2379
2370
let compiler = builder. compiler_for ( builder. top_stage , target, target) ;
2380
2371
builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
2381
2372
2382
- let mut cargo = tool:: prepare_tool_cargo (
2373
+ let cargo = tool:: prepare_tool_cargo (
2383
2374
builder,
2384
2375
compiler,
2385
2376
Mode :: ToolRustc ,
@@ -2389,18 +2380,13 @@ impl Step for CrateRustdocJsonTypes {
2389
2380
SourceType :: InTree ,
2390
2381
& [ ] ,
2391
2382
) ;
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" ) ;
2397
2383
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
+ } ;
2404
2390
2405
2391
builder. info ( & format ! (
2406
2392
"{} rustdoc-json-types stage{} ({} -> {})" ,
@@ -2409,9 +2395,14 @@ impl Step for CrateRustdocJsonTypes {
2409
2395
& compiler. host,
2410
2396
target
2411
2397
) ) ;
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
+ ) ;
2415
2406
}
2416
2407
}
2417
2408
0 commit comments