( params: InferPlatformParams, executor: CommandExecutor = getDefaultCommandExecutor(), )
| 227 | } |
| 228 | |
| 229 | export async function inferPlatform( |
| 230 | params: InferPlatformParams, |
| 231 | executor: CommandExecutor = getDefaultCommandExecutor(), |
| 232 | ): Promise<InferPlatformResult> { |
| 233 | const cachedPlatform = resolveCachedPlatform(params); |
| 234 | if (cachedPlatform) { |
| 235 | return { platform: cachedPlatform, source: 'simulator-platform-cache' }; |
| 236 | } |
| 237 | |
| 238 | const { simulatorId, simulatorName } = inferSimulatorSelectorForTool({ |
| 239 | simulatorId: params.simulatorId, |
| 240 | simulatorName: params.simulatorName, |
| 241 | sessionDefaults: params.sessionDefaults, |
| 242 | }); |
| 243 | |
| 244 | let simulatorIdForLookup = simulatorId; |
| 245 | let simulatorNameForLookup = simulatorName; |
| 246 | if (!simulatorIdForLookup && simulatorName && UUID_REGEX.test(simulatorName)) { |
| 247 | simulatorIdForLookup = simulatorName; |
| 248 | simulatorNameForLookup = undefined; |
| 249 | } |
| 250 | |
| 251 | const inferredFromRuntime = await inferPlatformFromSimctl( |
| 252 | simulatorIdForLookup, |
| 253 | simulatorNameForLookup, |
| 254 | executor, |
| 255 | ); |
| 256 | if (inferredFromRuntime) { |
| 257 | return { platform: inferredFromRuntime, source: 'simulator-runtime' }; |
| 258 | } |
| 259 | |
| 260 | if (simulatorNameForLookup) { |
| 261 | const inferredFromName = inferPlatformFromSimulatorName(simulatorNameForLookup); |
| 262 | if (inferredFromName) { |
| 263 | return { platform: inferredFromName, source: 'simulator-name' }; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | const { projectPath, workspacePath, scheme } = resolveProjectFromSession(params); |
| 268 | if (scheme && (projectPath || workspacePath)) { |
| 269 | const detection = await detectPlatformFromScheme(projectPath, workspacePath, scheme, executor); |
| 270 | if (detection.platform) { |
| 271 | return { platform: detection.platform, source: 'build-settings' }; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | return { platform: XcodePlatform.iOSSimulator, source: 'default' }; |
| 276 | } |
no test coverage detected