MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / detectPlatformFromScheme

Function detectPlatformFromScheme

src/utils/platform-detection.ts:53–129  ·  view source on GitHub ↗
(
  projectPath: string | undefined,
  workspacePath: string | undefined,
  scheme: string,
  executor: CommandExecutor = getDefaultCommandExecutor(),
)

Source from the content-addressed store, hash-verified

51}
52
53export async function detectPlatformFromScheme(
54 projectPath: string | undefined,
55 workspacePath: string | undefined,
56 scheme: string,
57 executor: CommandExecutor = getDefaultCommandExecutor(),
58): Promise<PlatformDetectionResult> {
59 const command = ['xcodebuild', '-showBuildSettings', '-scheme', scheme];
60
61 if (projectPath && workspacePath) {
62 return {
63 platform: null,
64 sdkroot: null,
65 supportedPlatforms: [],
66 error: 'projectPath and workspacePath are mutually exclusive for platform detection',
67 };
68 }
69
70 if (projectPath) {
71 command.push('-project', projectPath);
72 } else if (workspacePath) {
73 command.push('-workspace', workspacePath);
74 } else {
75 return {
76 platform: null,
77 sdkroot: null,
78 supportedPlatforms: [],
79 error: 'Either projectPath or workspacePath is required for platform detection',
80 };
81 }
82
83 try {
84 const result = await executor(command, 'Platform Detection', true);
85 if (!result.success) {
86 return {
87 platform: null,
88 sdkroot: null,
89 supportedPlatforms: [],
90 error: result.error ?? 'xcodebuild -showBuildSettings failed',
91 };
92 }
93
94 const output = result.output ?? '';
95 const sdkroots = extractBuildSettingValues(output, 'SDKROOT');
96 const supportedPlatforms = extractBuildSettingValues(output, 'SUPPORTED_PLATFORMS').flatMap(
97 (value) => value.split(/\s+/),
98 );
99
100 let sdkroot: string | null = null;
101 let platform: SimulatorPlatform | null = null;
102
103 for (const sdkrootValue of sdkroots) {
104 const detected = sdkrootToSimulatorPlatform(sdkrootValue);
105 if (detected) {
106 platform = detected;
107 sdkroot = sdkrootValue;
108 break;
109 }
110 }

Callers 2

inferPlatformFunction · 0.90

Calls 7

logFunction · 0.90
pushMethod · 0.80
executorFunction · 0.50

Tested by

no test coverage detected