@@ -228,7 +228,7 @@ impl Step for HtmlCheck {
228228/// order to test cargo.
229229#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
230230pub struct Cargotest {
231- stage : u32 ,
231+ build_compiler : Compiler ,
232232 host : TargetSelection ,
233233}
234234
@@ -241,17 +241,26 @@ impl Step for Cargotest {
241241 }
242242
243243 fn make_run ( run : RunConfig < ' _ > ) {
244- run. builder . ensure ( Cargotest { stage : run. builder . top_stage , host : run. target } ) ;
244+ // FIXME: support testing stage 0 cargo?
245+ assert ! ( run. builder. top_stage > 0 ) ;
246+ run. builder . ensure ( Cargotest {
247+ build_compiler : run. builder . compiler ( run. builder . top_stage - 1 , run. target ) ,
248+ host : run. target ,
249+ } ) ;
245250 }
246251
247252 /// Runs the `cargotest` tool as compiled in `stage` by the `host` compiler.
248253 ///
249254 /// This tool in `src/tools` will check out a few Rust projects and run `cargo
250255 /// test` to ensure that we don't regress the test suites there.
251256 fn run ( self , builder : & Builder < ' _ > ) {
252- let compiler = builder. compiler ( self . stage , self . host ) ;
253- builder. ensure ( compile:: Rustc :: new ( compiler, compiler. host ) ) ;
254- let cargo = builder. ensure ( tool:: Cargo { compiler, target : compiler. host } ) ;
257+ // Here we need to ensure that we run cargo with an in-tree compiler, because we test
258+ // both their behavior together.
259+ // We can build cargo with the earlier stage compiler though.
260+ let cargo =
261+ builder. ensure ( tool:: Cargo { compiler : self . build_compiler , target : self . host } ) ;
262+ let tested_compiler = builder. compiler ( self . build_compiler . stage + 1 , self . host ) ;
263+ builder. std ( tested_compiler, self . host ) ;
255264
256265 // Note that this is a short, cryptic, and not scoped directory name. This
257266 // is currently to minimize the length of path on Windows where we otherwise
@@ -264,17 +273,21 @@ impl Step for Cargotest {
264273 cmd. arg ( & cargo. tool_path )
265274 . arg ( & out_dir)
266275 . args ( builder. config . test_args ( ) )
267- . env ( "RUSTC" , builder. rustc ( compiler ) )
268- . env ( "RUSTDOC" , builder. rustdoc_for_compiler ( compiler ) ) ;
276+ . env ( "RUSTC" , builder. rustc ( tested_compiler ) )
277+ . env ( "RUSTDOC" , builder. rustdoc_for_compiler ( tested_compiler ) ) ;
269278 add_rustdoc_cargo_linker_args (
270279 & mut cmd,
271280 builder,
272- compiler . host ,
281+ tested_compiler . host ,
273282 LldThreads :: No ,
274- compiler . stage ,
283+ tested_compiler . stage ,
275284 ) ;
276285 cmd. delay_failure ( ) . run ( builder) ;
277286 }
287+
288+ fn metadata ( & self ) -> Option < StepMetadata > {
289+ Some ( StepMetadata :: test ( "cargotest" , self . host ) . stage ( self . build_compiler . stage + 1 ) )
290+ }
278291}
279292
280293/// Runs `cargo test` for cargo itself.
0 commit comments