@@ -2109,8 +2109,13 @@ impl Step for CrateLibrustc {
21092109}
21102110
21112111// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2112- fn cargo_test_args ( cargo : & mut Command , libtest_args : & [ & str ] , _crates : & [ & str ] , builder : & Builder < ' _ > ) {
2113- if !builder. fail_fast {
2112+ fn run_cargo_test ( cargo : impl Into < Command > , libtest_args : & [ & str ] , crates : & [ Interned < String > ] , compiler : Compiler , target : TargetSelection , builder : & Builder < ' _ > ) {
2113+ let mut cargo = cargo. into ( ) ;
2114+
2115+ // Pass in some standard flags then iterate over the graph we've discovered
2116+ // in `cargo metadata` with the maps above and figure out what `-p`
2117+ // arguments need to get passed.
2118+ if builder. kind == Kind :: Test && !builder. fail_fast {
21142119 cargo. arg ( "--no-fail-fast" ) ;
21152120 }
21162121 match builder. doc_tests {
@@ -2123,8 +2128,38 @@ fn cargo_test_args(cargo: &mut Command, libtest_args: &[&str], _crates: &[&str],
21232128 DocTests :: Yes => { }
21242129 }
21252130
2131+ for & krate in crates {
2132+ cargo. arg ( "-p" ) . arg ( krate) ;
2133+ }
2134+
2135+ // The tests are going to run with the *target* libraries, so we need to
2136+ // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2137+ //
2138+ // Note that to run the compiler we need to run with the *host* libraries,
2139+ // but our wrapper scripts arrange for that to be the case anyway.
2140+ let mut dylib_path = dylib_path ( ) ;
2141+ dylib_path. insert ( 0 , PathBuf :: from ( & * builder. sysroot_libdir ( compiler, target) ) ) ;
2142+ cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
2143+
2144+ if target. contains ( "emscripten" ) {
2145+ cargo. env (
2146+ format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) ,
2147+ builder. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ,
2148+ ) ;
2149+ } else if target. starts_with ( "wasm32" ) {
2150+ let node = builder. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ;
2151+ let runner = format ! ( "{} {}/src/etc/wasm32-shim.js" , node. display( ) , builder. src. display( ) ) ;
2152+ cargo. env ( format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) , & runner) ;
2153+ } else if builder. remote_tested ( target) {
2154+ cargo. env (
2155+ format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) ,
2156+ format ! ( "{} run 0" , builder. tool_exe( Tool :: RemoteTestClient ) . display( ) ) ,
2157+ ) ;
2158+ }
2159+
21262160 cargo. arg ( "--" ) . args ( & builder. config . cmd . test_args ( ) ) . args ( libtest_args) ;
2127- add_flags_and_try_run_tests ( builder, cargo) ;
2161+ let _time = util:: timeit ( & builder) ;
2162+ add_flags_and_try_run_tests ( builder, & mut cargo) ;
21282163}
21292164
21302165#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -2190,69 +2225,14 @@ impl Step for Crate {
21902225 _ => panic ! ( "can only test libraries" ) ,
21912226 } ;
21922227
2193- // Build up the base `cargo test` command.
2194- //
2195- // Pass in some standard flags then iterate over the graph we've discovered
2196- // in `cargo metadata` with the maps above and figure out what `-p`
2197- // arguments need to get passed.
2198- if builder. kind == Kind :: Test && !builder. fail_fast {
2199- cargo. arg ( "--no-fail-fast" ) ;
2200- }
2201- match builder. doc_tests {
2202- DocTests :: Only => {
2203- cargo. arg ( "--doc" ) ;
2204- }
2205- DocTests :: No => {
2206- cargo. args ( & [ "--lib" , "--bins" , "--examples" , "--tests" , "--benches" ] ) ;
2207- }
2208- DocTests :: Yes => { }
2209- }
2210-
2211- for krate in & self . crates {
2212- cargo. arg ( "-p" ) . arg ( krate) ;
2213- }
2214-
2215- // The tests are going to run with the *target* libraries, so we need to
2216- // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2217- //
2218- // Note that to run the compiler we need to run with the *host* libraries,
2219- // but our wrapper scripts arrange for that to be the case anyway.
2220- let mut dylib_path = dylib_path ( ) ;
2221- dylib_path. insert ( 0 , PathBuf :: from ( & * builder. sysroot_libdir ( compiler, target) ) ) ;
2222- cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
2223-
2224- cargo. arg ( "--" ) ;
2225- cargo. args ( & builder. config . cmd . test_args ( ) ) ;
2226-
2227- cargo. arg ( "-Z" ) . arg ( "unstable-options" ) ;
2228- cargo. arg ( "--format" ) . arg ( "json" ) ;
2229-
2230- if target. contains ( "emscripten" ) {
2231- cargo. env (
2232- format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) ,
2233- builder. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ,
2234- ) ;
2235- } else if target. starts_with ( "wasm32" ) {
2236- let node = builder. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ;
2237- let runner =
2238- format ! ( "{} {}/src/etc/wasm32-shim.js" , node. display( ) , builder. src. display( ) ) ;
2239- cargo. env ( format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) , & runner) ;
2240- } else if builder. remote_tested ( target) {
2241- cargo. env (
2242- format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) ,
2243- format ! ( "{} run 0" , builder. tool_exe( Tool :: RemoteTestClient ) . display( ) ) ,
2244- ) ;
2245- }
2246-
22472228 let _guard = builder. msg (
22482229 builder. kind ,
22492230 compiler. stage ,
22502231 crate_description ( & self . crates ) ,
22512232 compiler. host ,
22522233 target,
22532234 ) ;
2254- let _time = util:: timeit ( & builder) ;
2255- crate :: render_tests:: try_run_tests ( builder, & mut cargo. into ( ) ) ;
2235+ run_cargo_test ( cargo, & [ ] , & self . crates , compiler, target, builder) ;
22562236 }
22572237}
22582238
@@ -2565,13 +2545,15 @@ impl Step for Bootstrap {
25652545 check_bootstrap. arg ( "bootstrap_test.py" ) . current_dir ( builder. src . join ( "src/bootstrap/" ) ) ;
25662546 try_run ( builder, & mut check_bootstrap) ;
25672547
2548+ let host = builder. config . build ;
2549+ let compiler = builder. compiler ( 0 , host) ;
25682550 let mut cmd = Command :: new ( & builder. initial_cargo ) ;
25692551 cmd. arg ( "test" )
25702552 . current_dir ( builder. src . join ( "src/bootstrap" ) )
25712553 . env ( "RUSTFLAGS" , "-Cdebuginfo=2" )
25722554 . env ( "CARGO_TARGET_DIR" , builder. out . join ( "bootstrap" ) )
25732555 . env ( "RUSTC_BOOTSTRAP" , "1" )
2574- . env ( "RUSTDOC" , builder. rustdoc ( builder . compiler ( 0 , builder . build . build ) ) )
2556+ . env ( "RUSTDOC" , builder. rustdoc ( compiler) )
25752557 . env ( "RUSTC" , & builder. initial_rustc ) ;
25762558 if let Some ( flags) = option_env ! ( "RUSTFLAGS" ) {
25772559 // Use the same rustc flags for testing as for "normal" compilation,
@@ -2581,7 +2563,7 @@ impl Step for Bootstrap {
25812563 }
25822564 // rustbuild tests are racy on directory creation so just run them one at a time.
25832565 // Since there's not many this shouldn't be a problem.
2584- cargo_test_args ( & mut cmd, & [ "--test-threads=1" ] , & [ ] , builder) ;
2566+ run_cargo_test ( cmd, & [ "--test-threads=1" ] , & [ ] , compiler , host , builder) ;
25852567 }
25862568
25872569 fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
0 commit comments