@@ -575,35 +575,39 @@ impl OsRebuildArgs {
575575 let target_specialisation = if self . no_specialisation {
576576 None
577577 } else {
578- current_specialisation . or_else ( || self . specialisation . clone ( ) )
578+ self . specialisation . clone ( ) . or ( current_specialisation )
579579 } ;
580580
581581 debug ! ( "Target specialisation: {target_specialisation:?}" ) ;
582582
583- let target_profile = target_specialisation. as_ref ( ) . map_or_else (
584- || out_path. to_path_buf ( ) ,
585- |spec| out_path. join ( "specialisation" ) . join ( spec) ,
586- ) ;
583+ // Determine target profile, falling back to base if specialisation doesn't
584+ // exist
585+ let target_profile = match & target_specialisation {
586+ None => out_path. to_path_buf ( ) ,
587+ Some ( spec) => {
588+ let spec_path = out_path. join ( "specialisation" ) . join ( spec) ;
589+
590+ // For local builds, check if specialisation exists and fall back if not
591+ if out_path. exists ( ) && !spec_path. exists ( ) {
592+ bail ! (
593+ "Specialisation '{}' does not exist in the built configuration" ,
594+ spec
595+ ) ;
596+ }
597+
598+ spec_path
599+ } ,
600+ } ;
587601
588602 debug ! ( "Output path: {out_path:?}" ) ;
589603 debug ! ( "Target profile path: {}" , target_profile. display( ) ) ;
590604
591- // If out_path doesn't exist locally, assume it's remote and skip existence
592- // check
593- if out_path. exists ( ) {
594- debug ! ( "Target profile exists: {}" , target_profile. exists( ) ) ;
595-
596- if !target_profile
597- . try_exists ( )
598- . context ( "Failed to check if target profile exists" ) ?
599- {
600- return Err ( eyre ! (
601- "Target profile path does not exist: {}" ,
602- target_profile. display( )
603- ) ) ;
604- }
605- } else {
606- debug ! ( "Output path is remote, skipping local existence check" ) ;
605+ // Validate the final target profile exists if it's a local build
606+ if out_path. exists ( ) && !target_profile. exists ( ) {
607+ return Err ( eyre ! (
608+ "Target profile path does not exist: {}" ,
609+ target_profile. display( )
610+ ) ) ;
607611 }
608612
609613 Ok ( target_profile)
0 commit comments