@@ -20,6 +20,7 @@ import { executeXcodeBuildCommand } from '../../../utils/build/index.ts';
2020import type { CommandExecutor } from '../../../utils/execution/index.ts' ;
2121import { determineSimulatorUuid } from '../../../utils/simulator-utils.ts' ;
2222import { nullifyEmptyStrings } from '../../../utils/schema-helpers.ts' ;
23+ import { inferPlatform } from '../../../utils/infer-platform.ts' ;
2324
2425// Unified schema: XOR between projectPath and workspacePath, and XOR between simulatorId and simulatorName
2526const baseOptions = {
@@ -82,7 +83,7 @@ async function _handleSimulatorBuildLogic(
8283 params : BuildRunSimulatorParams ,
8384 executor : CommandExecutor ,
8485 executeXcodeBuildCommandFn : typeof executeXcodeBuildCommand = executeXcodeBuildCommand ,
85- ) : Promise < ToolResponse > {
86+ ) : Promise < { response : ToolResponse ; detectedPlatform : XcodePlatform } > {
8687 const projectType = params . projectPath ? 'project' : 'workspace' ;
8788 const filePath = params . projectPath ?? params . workspacePath ;
8889
@@ -94,10 +95,22 @@ async function _handleSimulatorBuildLogic(
9495 ) ;
9596 }
9697
97- log (
98- 'info' ,
99- `Starting iOS Simulator build for scheme ${ params . scheme } from ${ projectType } : ${ filePath } ` ,
98+ const inferred = await inferPlatform (
99+ {
100+ projectPath : params . projectPath ,
101+ workspacePath : params . workspacePath ,
102+ scheme : params . scheme ,
103+ simulatorId : params . simulatorId ,
104+ simulatorName : params . simulatorName ,
105+ } ,
106+ executor ,
100107 ) ;
108+ const detectedPlatform = inferred . platform ;
109+ const platformName = detectedPlatform . replace ( ' Simulator' , '' ) ;
110+ const logPrefix = `${ platformName } Simulator Build` ;
111+
112+ log ( 'info' , `Starting ${ logPrefix } for scheme ${ params . scheme } from ${ projectType } : ${ filePath } ` ) ;
113+ log ( 'info' , `Inferred simulator platform: ${ detectedPlatform } (source: ${ inferred . source } )` ) ;
101114
102115 // Create SharedBuildParams object with required configuration property
103116 const sharedBuildParams : SharedBuildParams = {
@@ -109,19 +122,21 @@ async function _handleSimulatorBuildLogic(
109122 extraArgs : params . extraArgs ,
110123 } ;
111124
112- return executeXcodeBuildCommandFn (
125+ const response = await executeXcodeBuildCommandFn (
113126 sharedBuildParams ,
114127 {
115- platform : XcodePlatform . iOSSimulator ,
128+ platform : detectedPlatform ,
116129 simulatorId : params . simulatorId ,
117130 simulatorName : params . simulatorName ,
118131 useLatestOS : params . simulatorId ? false : params . useLatestOS ,
119- logPrefix : 'iOS Simulator Build' ,
132+ logPrefix,
120133 } ,
121134 params . preferXcodebuild as boolean ,
122135 'build' ,
123136 executor ,
124137 ) ;
138+
139+ return { response, detectedPlatform } ;
125140}
126141
127142// Exported business logic function for building and running iOS Simulator apps.
@@ -135,12 +150,12 @@ export async function build_run_simLogic(
135150
136151 log (
137152 'info' ,
138- `Starting iOS Simulator build and run for scheme ${ params . scheme } from ${ projectType } : ${ filePath } ` ,
153+ `Starting Simulator build and run for scheme ${ params . scheme } from ${ projectType } : ${ filePath } ` ,
139154 ) ;
140155
141156 try {
142157 // --- Build Step ---
143- const buildResult = await _handleSimulatorBuildLogic (
158+ const { response : buildResult , detectedPlatform } = await _handleSimulatorBuildLogic (
144159 params ,
145160 executor ,
146161 executeXcodeBuildCommandFn ,
@@ -150,6 +165,9 @@ export async function build_run_simLogic(
150165 return buildResult ; // Return the build error
151166 }
152167
168+ const platformDestination = detectedPlatform ;
169+ const platformName = detectedPlatform . replace ( ' Simulator' , '' ) ;
170+
153171 // --- Get App Path Step ---
154172 // Create the command array for xcodebuild with -showBuildSettings option
155173 const command = [ 'xcodebuild' , '-showBuildSettings' ] ;
@@ -168,12 +186,12 @@ export async function build_run_simLogic(
168186 // Handle destination for simulator
169187 let destinationString : string ;
170188 if ( params . simulatorId ) {
171- destinationString = `platform=iOS Simulator ,id=${ params . simulatorId } ` ;
189+ destinationString = `platform=${ platformDestination } ,id=${ params . simulatorId } ` ;
172190 } else if ( params . simulatorName ) {
173- destinationString = `platform=iOS Simulator ,name=${ params . simulatorName } ${ ( params . useLatestOS ?? true ) ? ',OS=latest' : '' } ` ;
191+ destinationString = `platform=${ platformDestination } ,name=${ params . simulatorName } ${ ( params . useLatestOS ?? true ) ? ',OS=latest' : '' } ` ;
174192 } else {
175193 // This shouldn't happen due to validation, but handle it
176- destinationString = ' platform=iOS Simulator' ;
194+ destinationString = ` platform=${ platformDestination } ` ;
177195 }
178196 command . push ( '-destination' , destinationString ) ;
179197
@@ -450,7 +468,7 @@ export async function build_run_simLogic(
450468 }
451469
452470 // --- Success ---
453- log ( 'info' , '✅ iOS simulator build & run succeeded.' ) ;
471+ log ( 'info' , `✅ ${ platformName } simulator build & run succeeded.` ) ;
454472
455473 const target = params . simulatorId
456474 ? `simulator UUID '${ params . simulatorId } '`
@@ -462,7 +480,7 @@ export async function build_run_simLogic(
462480 content : [
463481 {
464482 type : 'text' ,
465- text : `✅ iOS simulator build and run succeeded for scheme ${ params . scheme } from ${ sourceType } ${ sourcePath } targeting ${ target } .\n\nThe app (${ bundleId } ) is now running in the iOS Simulator.\nIf you don't see the simulator window, it may be hidden behind other windows. The Simulator app should be open.` ,
483+ text : `✅ ${ platformName } simulator build and run succeeded for scheme ${ params . scheme } from ${ sourceType } ${ sourcePath } targeting ${ target } .\n\nThe app (${ bundleId } ) is now running in the ${ platformName } Simulator.\nIf you don't see the simulator window, it may be hidden behind other windows. The Simulator app should be open.` ,
466484 } ,
467485 ] ,
468486 nextSteps : [
@@ -489,8 +507,8 @@ export async function build_run_simLogic(
489507 } ;
490508 } catch ( error ) {
491509 const errorMessage = error instanceof Error ? error . message : String ( error ) ;
492- log ( 'error' , `Error in iOS Simulator build and run: ${ errorMessage } ` ) ;
493- return createTextResponse ( `Error in iOS Simulator build and run: ${ errorMessage } ` , true ) ;
510+ log ( 'error' , `Error in Simulator build and run: ${ errorMessage } ` ) ;
511+ return createTextResponse ( `Error in Simulator build and run: ${ errorMessage } ` , true ) ;
494512 }
495513}
496514
0 commit comments