From 837534c05d68d4ec95d153d54a3c050763386380 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Mon, 2 Dec 2024 11:24:43 -0800 Subject: [PATCH] IOSHelper: fix `lime test ios` with Xcode 16 or newer The ios-deploy tool no longer works with new iOS SDKs that don't have DeveloperDiskImage.dmg, but Xcode added new commands that can be used in the terminal to install and launch on connected devices. --- src/lime/tools/IOSHelper.hx | 53 ++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/lime/tools/IOSHelper.hx b/src/lime/tools/IOSHelper.hx index a8321a082a..b7c7edf4aa 100644 --- a/src/lime/tools/IOSHelper.hx +++ b/src/lime/tools/IOSHelper.hx @@ -359,21 +359,44 @@ class IOSHelper applicationPath = workingDirectory + "/build/" + configuration + "-iphoneos/" + project.app.file + ".app"; } - var templatePaths = [ - Path.combine(Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)), #if lime "templates" #else "" #end) - ].concat(project.templatePaths); - var launcher = System.findTemplate(templatePaths, "bin/ios-deploy"); - Sys.command("chmod", ["+x", launcher]); - - // var xcodeVersion = getXcodeVersion (); - - System.runCommand("", launcher, [ - "install", - "--noninteractive", - "--debug", - "--bundle", - FileSystem.fullPath(applicationPath) - ]); + var xcodeVersion = Std.parseFloat(getXcodeVersion()); + if (!Math.isNaN(xcodeVersion) && xcodeVersion >= 16) { + // ios-deploy doesn't work with newer iOS SDKs where it can't + // find DeveloperDiskImage.dmg. however, Xcode 16 adds new + // commands for installing and launching apps on connected + // devices, so we'll prefer those, if available. + var listDevicesOutput = System.runProcess("", "xcrun", ["devicectl", "list", "devices", "--hide-default-columns", "--columns", "Identifier", "--filter", "Platform == 'iOS' AND State == 'connected'"]); + var deviceUUID:String = null; + var ready = false; + for (line in listDevicesOutput.split("\n")) { + if (!ready) { + ready = StringTools.startsWith(line, "----"); + continue; + } + deviceUUID = line; + break; + } + if (deviceUUID == null || deviceUUID.length == 0) { + Log.error("No device connected"); + return; + } + System.runCommand("", "xcrun", ["devicectl", "device", "install", "app", "--device", deviceUUID, FileSystem.fullPath(applicationPath)]); + System.runCommand("", "xcrun", ["devicectl", "device", "process", "launch", "--console", "--device", deviceUUID, project.meta.packageName]); + } else { + var templatePaths = [ + Path.combine(Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)), #if lime "templates" #else "" #end) + ].concat(project.templatePaths); + var launcher = System.findTemplate(templatePaths, "bin/ios-deploy"); + Sys.command("chmod", ["+x", launcher]); + + System.runCommand("", launcher, [ + "install", + "--noninteractive", + "--debug", + "--bundle", + FileSystem.fullPath(applicationPath) + ]); + } } }