@@ -9,6 +9,7 @@ use crate::Flags;
9
9
use crate :: core:: build_steps:: doc:: DocumentationFormat ;
10
10
use crate :: core:: config:: Config ;
11
11
use crate :: utils:: cache:: ExecutedStep ;
12
+ use crate :: utils:: helpers:: get_host_target;
12
13
use crate :: utils:: tests:: git:: { GitCtx , git_test} ;
13
14
14
15
static TEST_TRIPLE_1 : & str = "i686-unknown-haiku" ;
@@ -1236,29 +1237,47 @@ fn any_debug() {
1236
1237
/// The staging tests use insta for snapshot testing.
1237
1238
/// See bootstrap's README on how to bless the snapshots.
1238
1239
mod staging {
1240
+ use crate :: Build ;
1241
+ use crate :: core:: builder:: Builder ;
1239
1242
use crate :: core:: builder:: tests:: {
1240
1243
TEST_TRIPLE_1 , configure, configure_with_args, render_steps, run_build,
1241
1244
} ;
1245
+ use crate :: utils:: tests:: ConfigBuilder ;
1242
1246
1243
1247
#[ test]
1244
1248
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
+ insta:: assert_snapshot!(
1250
+ ConfigBuilder :: build( )
1251
+ . path( "compiler" )
1252
+ . stage( 1 )
1253
+ . get_steps( ) , @r"
1254
+ [build] rustc 0 <host> -> std 0 <host>
1255
+ [build] llvm <host>
1256
+ [build] rustc 0 <host> -> rustc 1 <host>
1257
+ [build] rustc 0 <host> -> rustc 1 <host>
1255
1258
" ) ;
1256
1259
}
1260
+
1261
+ impl ConfigBuilder {
1262
+ fn get_steps ( self ) -> String {
1263
+ let config = self . create_config ( ) ;
1264
+
1265
+ let kind = config. cmd . kind ( ) ;
1266
+ let build = Build :: new ( config) ;
1267
+ let builder = Builder :: new ( & build) ;
1268
+ builder. run_step_descriptions ( & Builder :: get_step_descriptions ( kind) , & builder. paths ) ;
1269
+ render_steps ( & builder. cache . into_executed_steps ( ) )
1270
+ }
1271
+ }
1257
1272
}
1258
1273
1259
1274
/// Renders the executed bootstrap steps for usage in snapshot tests with insta.
1260
1275
/// Only renders certain important steps.
1261
1276
/// Each value in `steps` should be a tuple of (Step, step output).
1277
+ ///
1278
+ /// The arrow in the rendered output (`X -> Y`) means `X builds Y`.
1279
+ /// This is similar to the output printed by bootstrap to stdout, but here it is
1280
+ /// generated purely for the purpose of tests.
1262
1281
fn render_steps ( steps : & [ ExecutedStep ] ) -> String {
1263
1282
steps
1264
1283
. iter ( )
@@ -1275,18 +1294,17 @@ fn render_steps(steps: &[ExecutedStep]) -> String {
1275
1294
}
1276
1295
let stage =
1277
1296
if let Some ( stage) = metadata. stage { format ! ( "{stage} " ) } else { "" . to_string ( ) } ;
1278
- write ! ( record, "{} {stage}<{}>" , metadata. name, metadata. target) ;
1297
+ write ! ( record, "{} {stage}<{}>" , metadata. name, normalize_target ( metadata. target) ) ;
1279
1298
Some ( record)
1280
1299
} )
1281
- . map ( |line| {
1282
- line. replace ( TEST_TRIPLE_1 , "target1" )
1283
- . replace ( TEST_TRIPLE_2 , "target2" )
1284
- . replace ( TEST_TRIPLE_3 , "target3" )
1285
- } )
1286
1300
. collect :: < Vec < _ > > ( )
1287
1301
. join ( "\n " )
1288
1302
}
1289
1303
1304
+ fn normalize_target ( target : TargetSelection ) -> String {
1305
+ target. to_string ( ) . replace ( & get_host_target ( ) . to_string ( ) , "host" )
1306
+ }
1307
+
1290
1308
fn render_compiler ( compiler : Compiler ) -> String {
1291
- format ! ( "rustc {} <{}>" , compiler. stage, compiler. host)
1309
+ format ! ( "rustc {} <{}>" , compiler. stage, normalize_target ( compiler. host) )
1292
1310
}
0 commit comments