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

Function listAvailableDevices

src/cli/commands/setup.ts:740–787  ·  view source on GitHub ↗
(
  fileSystem: FileSystemExecutor,
  executor: CommandExecutor,
)

Source from the content-addressed store, hash-verified

738}
739
740async function listAvailableDevices(
741 fileSystem: FileSystemExecutor,
742 executor: CommandExecutor,
743): Promise<SetupDevice[]> {
744 let jsonPath: string | undefined;
745
746 try {
747 jsonPath = path.join(fileSystem.tmpdir(), `xcodebuildmcp-setup-devices-${Date.now()}.json`);
748
749 const result = await executor(
750 ['xcrun', 'devicectl', 'list', 'devices', '--json-output', jsonPath],
751 'List Devices (setup)',
752 false,
753 undefined,
754 );
755
756 if (result.success) {
757 const jsonContent = await fileSystem.readFile(jsonPath, 'utf8');
758 const devices = parseDeviceListResponse(JSON.parse(jsonContent));
759 if (devices.length > 0) {
760 return devices;
761 }
762 }
763 } catch {
764 // Fall back to xctrace below.
765 } finally {
766 if (jsonPath != null) {
767 await fileSystem.rm(jsonPath, { force: true }).catch(() => {});
768 }
769 }
770
771 try {
772 const fallbackResult = await executor(
773 ['xcrun', 'xctrace', 'list', 'devices'],
774 'List Devices (setup fallback)',
775 false,
776 undefined,
777 );
778
779 if (!fallbackResult.success) {
780 return [];
781 }
782
783 return parseXctraceDevices(fallbackResult.output);
784 } catch {
785 return [];
786 }
787}
788
789function getDefaultDeviceIndex(devices: SetupDevice[], existingDeviceId?: string): number {
790 if (existingDeviceId != null) {

Callers 1

selectDeviceFunction · 0.85

Calls 6

parseDeviceListResponseFunction · 0.85
parseXctraceDevicesFunction · 0.85
tmpdirMethod · 0.80
readFileMethod · 0.80
rmMethod · 0.80
executorFunction · 0.50

Tested by

no test coverage detected