@@ -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 ( & [ ] ) ;
@@ -306,7 +307,7 @@ impl Step for Cargo {
306
307
let compiler = builder. compiler ( self . stage , self . host ) ;
307
308
308
309
builder. ensure ( tool:: Cargo { compiler, target : self . host } ) ;
309
- let mut cargo = tool:: prepare_tool_cargo (
310
+ let cargo = tool:: prepare_tool_cargo (
310
311
builder,
311
312
compiler,
312
313
Mode :: ToolRustc ,
@@ -317,21 +318,19 @@ 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 ( ) ) ;
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) ;
324
323
325
324
// Don't run cross-compile tests, we may not have cross-compiled libstd libs
326
325
// available.
327
326
cargo. env ( "CFG_DISABLE_CROSS_TESTS" , "1" ) ;
328
327
// Forcibly disable tests using nightly features since any changes to
329
328
// those features won't be able to land.
330
329
cargo. env ( "CARGO_TEST_DISABLE_NIGHTLY" , "1" ) ;
331
-
332
330
cargo. env ( "PATH" , & path_for_cargo ( builder, compiler) ) ;
333
331
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) ;
335
334
}
336
335
}
337
336
@@ -388,9 +387,7 @@ impl Step for RustAnalyzer {
388
387
cargo. env ( "SKIP_SLOW_TESTS" , "1" ) ;
389
388
390
389
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) ;
394
391
}
395
392
}
396
393
@@ -433,17 +430,13 @@ impl Step for Rustfmt {
433
430
& [ ] ,
434
431
) ;
435
432
436
- if !builder. fail_fast {
437
- cargo. arg ( "--no-fail-fast" ) ;
438
- }
439
-
440
433
let dir = testdir ( builder, compiler. host ) ;
441
434
t ! ( fs:: create_dir_all( & dir) ) ;
442
435
cargo. env ( "RUSTFMT_TEST_DIR" , dir) ;
443
436
444
437
cargo. add_rustc_lib_path ( builder, compiler) ;
445
438
446
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
439
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
447
440
}
448
441
}
449
442
@@ -489,12 +482,9 @@ impl Step for RustDemangler {
489
482
t ! ( fs:: create_dir_all( & dir) ) ;
490
483
491
484
cargo. env ( "RUST_DEMANGLER_DRIVER_PATH" , rust_demangler) ;
492
-
493
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
494
-
495
485
cargo. add_rustc_lib_path ( builder, compiler) ;
496
486
497
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
487
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , host , builder ) ;
498
488
}
499
489
}
500
490
@@ -617,10 +607,6 @@ impl Step for Miri {
617
607
) ;
618
608
cargo. add_rustc_lib_path ( builder, compiler) ;
619
609
620
- if !builder. fail_fast {
621
- cargo. arg ( "--no-fail-fast" ) ;
622
- }
623
-
624
610
// miri tests need to know about the stage sysroot
625
611
cargo. env ( "MIRI_SYSROOT" , & miri_sysroot) ;
626
612
cargo. env ( "MIRI_HOST_SYSROOT" , sysroot) ;
@@ -632,13 +618,14 @@ impl Step for Miri {
632
618
633
619
// Set the target.
634
620
cargo. env ( "MIRI_TEST_TARGET" , target. rustc_target_arg ( ) ) ;
635
- // Forward test filters.
636
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
637
621
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
+ }
642
629
643
630
// # Run `cargo miri test`.
644
631
// 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 {
671
658
cargo. env ( "RUST_BACKTRACE" , "1" ) ;
672
659
673
660
let mut cargo = Command :: from ( cargo) ;
661
+ let _time = util:: timeit ( & builder) ;
674
662
builder. run ( & mut cargo) ;
675
663
}
676
664
}
@@ -710,8 +698,7 @@ impl Step for CompiletestTest {
710
698
& [ ] ,
711
699
) ;
712
700
cargo. allow_features ( "test" ) ;
713
-
714
- add_flags_and_try_run_tests ( builder, & mut cargo. into ( ) ) ;
701
+ run_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
715
702
}
716
703
}
717
704
@@ -763,11 +750,10 @@ impl Step for Clippy {
763
750
let host_libs = builder. stage_out ( compiler, Mode :: ToolRustc ) . join ( builder. cargo_dir ( ) ) ;
764
751
cargo. env ( "HOST_LIBS" , host_libs) ;
765
752
766
- cargo. arg ( "--" ) . args ( builder. config . cmd . test_args ( ) ) ;
767
-
768
753
cargo. add_rustc_lib_path ( builder, compiler) ;
754
+ let mut cargo = prepare_cargo_test ( cargo, & [ ] , & [ ] , compiler, host, builder) ;
769
755
770
- if builder. try_run ( & mut cargo. into ( ) ) {
756
+ if builder. try_run ( & mut cargo) {
771
757
// The tests succeeded; nothing to do.
772
758
return ;
773
759
}
@@ -1195,7 +1181,7 @@ impl Step for TidySelfTest {
1195
1181
SourceType :: InTree ,
1196
1182
& [ ] ,
1197
1183
) ;
1198
- add_flags_and_try_run_tests ( builder , & mut cargo . into ( ) ) ;
1184
+ run_cargo_test ( cargo , & [ ] , & [ ] , compiler , bootstrap_host , builder ) ;
1199
1185
}
1200
1186
}
1201
1187
@@ -2108,8 +2094,31 @@ impl Step for CrateLibrustc {
2108
2094
}
2109
2095
}
2110
2096
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 {
2113
2122
let mut cargo = cargo. into ( ) ;
2114
2123
2115
2124
// 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
2132
2141
cargo. arg ( "-p" ) . arg ( krate) ;
2133
2142
}
2134
2143
2144
+ cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2145
+ if !builder. config . verbose_tests {
2146
+ cargo. arg ( "--quiet" ) ;
2147
+ }
2148
+
2135
2149
// The tests are going to run with the *target* libraries, so we need to
2136
2150
// ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2137
2151
//
@@ -2157,9 +2171,7 @@ fn run_cargo_test(cargo: impl Into<Command>, libtest_args: &[&str], crates: &[In
2157
2171
) ;
2158
2172
}
2159
2173
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
2163
2175
}
2164
2176
2165
2177
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -2281,24 +2293,6 @@ impl Step for CrateRustdoc {
2281
2293
SourceType :: InTree ,
2282
2294
& [ ] ,
2283
2295
) ;
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
-
2302
2296
if self . host . contains ( "musl" ) {
2303
2297
cargo. arg ( "'-Ctarget-feature=-crt-static'" ) ;
2304
2298
}
@@ -2338,15 +2332,15 @@ impl Step for CrateRustdoc {
2338
2332
dylib_path. insert ( 0 , PathBuf :: from ( & * libdir) ) ;
2339
2333
cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
2340
2334
2341
- if !builder. config . verbose_tests {
2342
- cargo. arg ( "--quiet" ) ;
2343
- }
2344
-
2345
2335
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
+ ) ;
2350
2344
}
2351
2345
}
2352
2346
@@ -2380,7 +2374,7 @@ impl Step for CrateRustdocJsonTypes {
2380
2374
let compiler = builder. compiler_for ( builder. top_stage , target, target) ;
2381
2375
builder. ensure ( compile:: Rustc :: new ( compiler, target) ) ;
2382
2376
2383
- let mut cargo = tool:: prepare_tool_cargo (
2377
+ let cargo = tool:: prepare_tool_cargo (
2384
2378
builder,
2385
2379
compiler,
2386
2380
Mode :: ToolRustc ,
@@ -2390,24 +2384,24 @@ impl Step for CrateRustdocJsonTypes {
2390
2384
SourceType :: InTree ,
2391
2385
& [ ] ,
2392
2386
) ;
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" ) ;
2398
2387
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
+ } ;
2405
2394
2406
2395
let _guard =
2407
2396
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
+ ) ;
2411
2405
}
2412
2406
}
2413
2407
0 commit comments