@@ -9,6 +9,7 @@ use crate::Flags;
99use crate :: core:: build_steps:: doc:: DocumentationFormat ;
1010use crate :: core:: config:: Config ;
1111use crate :: utils:: cache:: ExecutedStep ;
12+ use crate :: utils:: helpers:: get_host_target;
1213use crate :: utils:: tests:: git:: { GitCtx , git_test} ;
1314
1415static TEST_TRIPLE_1 : & str = "i686-unknown-haiku" ;
@@ -1236,29 +1237,48 @@ fn any_debug() {
12361237/// The staging tests use insta for snapshot testing.
12371238/// See bootstrap's README on how to bless the snapshots.
12381239mod staging {
1240+ use crate :: Build ;
1241+ use crate :: core:: builder:: Builder ;
12391242 use crate :: core:: builder:: tests:: {
12401243 TEST_TRIPLE_1 , configure, configure_with_args, render_steps, run_build,
12411244 } ;
1245+ use crate :: utils:: tests:: { ConfigBuilder , TestCtx } ;
12421246
12431247 #[ test]
12441248 fn build_compiler_stage_1 ( ) {
1245- let mut cache = run_build (
1246- & [ "compiler" . into ( ) ] ,
1247- configure_with_args ( & [ "build" , "--stage" , "1" ] , & [ TEST_TRIPLE_1 ] , & [ TEST_TRIPLE_1 ] ) ,
1248- ) ;
1249- let steps = cache . into_executed_steps ( ) ;
1250- insta :: assert_snapshot! ( render_steps ( & steps ) , @r"
1251- [build] rustc 0 <target1 > -> std 0 <target1 >
1252- [build] llvm <target1 >
1253- [build] rustc 0 <target1 > -> rustc 1 <target1 >
1254- [build] rustc 0 <target1 > -> rustc 1 <target1 >
1249+ let ctx = TestCtx :: new ( ) ;
1250+ insta :: assert_snapshot! (
1251+ ctx . config ( "build" )
1252+ . path ( "compiler" )
1253+ . stage ( 1 )
1254+ . get_steps ( ) , @r"
1255+ [build] rustc 0 <host > -> std 0 <host >
1256+ [build] llvm <host >
1257+ [build] rustc 0 <host > -> rustc 1 <host >
1258+ [build] rustc 0 <host > -> rustc 1 <host >
12551259 " ) ;
12561260 }
1261+
1262+ impl ConfigBuilder {
1263+ fn get_steps ( self ) -> String {
1264+ let config = self . create_config ( ) ;
1265+
1266+ let kind = config. cmd . kind ( ) ;
1267+ let build = Build :: new ( config) ;
1268+ let builder = Builder :: new ( & build) ;
1269+ builder. run_step_descriptions ( & Builder :: get_step_descriptions ( kind) , & builder. paths ) ;
1270+ render_steps ( & builder. cache . into_executed_steps ( ) )
1271+ }
1272+ }
12571273}
12581274
12591275/// Renders the executed bootstrap steps for usage in snapshot tests with insta.
12601276/// Only renders certain important steps.
12611277/// Each value in `steps` should be a tuple of (Step, step output).
1278+ ///
1279+ /// The arrow in the rendered output (`X -> Y`) means `X builds Y`.
1280+ /// This is similar to the output printed by bootstrap to stdout, but here it is
1281+ /// generated purely for the purpose of tests.
12621282fn render_steps ( steps : & [ ExecutedStep ] ) -> String {
12631283 steps
12641284 . iter ( )
@@ -1275,18 +1295,17 @@ fn render_steps(steps: &[ExecutedStep]) -> String {
12751295 }
12761296 let stage =
12771297 if let Some ( stage) = metadata. stage { format ! ( "{stage} " ) } else { "" . to_string ( ) } ;
1278- write ! ( record, "{} {stage}<{}>" , metadata. name, metadata. target) ;
1298+ write ! ( record, "{} {stage}<{}>" , metadata. name, normalize_target ( metadata. target) ) ;
12791299 Some ( record)
12801300 } )
1281- . map ( |line| {
1282- line. replace ( TEST_TRIPLE_1 , "target1" )
1283- . replace ( TEST_TRIPLE_2 , "target2" )
1284- . replace ( TEST_TRIPLE_3 , "target3" )
1285- } )
12861301 . collect :: < Vec < _ > > ( )
12871302 . join ( "\n " )
12881303}
12891304
1305+ fn normalize_target ( target : TargetSelection ) -> String {
1306+ target. to_string ( ) . replace ( & get_host_target ( ) . to_string ( ) , "host" )
1307+ }
1308+
12901309fn render_compiler ( compiler : Compiler ) -> String {
1291- format ! ( "rustc {} <{}>" , compiler. stage, compiler. host)
1310+ format ! ( "rustc {} <{}>" , compiler. stage, normalize_target ( compiler. host) )
12921311}
0 commit comments