diff options
Diffstat (limited to 'xmake/rules/xcode/application/run.lua')
| -rw-r--r-- | xmake/rules/xcode/application/run.lua | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/xmake/rules/xcode/application/run.lua b/xmake/rules/xcode/application/run.lua index 38f96f330..d9a25e4a5 100644 --- a/xmake/rules/xcode/application/run.lua +++ b/xmake/rules/xcode/application/run.lua @@ -23,17 +23,12 @@ import("core.base.option") import("devel.debugger") import("private.action.run.make_runenvs") --- main entry -function main (target, opt) +-- run on macosx +function _run_on_macosx(target, opt) -- get the runable target file local contentsdir = path.absolute(target:data("xcode.bundle.contentsdir")) - local binarydir = contentsdir - if is_plat("macosx") then - binarydir = path.join(contentsdir, "MacOS") - else - raise("we can only run macOS application!") - end + local binarydir = path.join(contentsdir, "MacOS") local targetfile = path.join(binarydir, path.filename(target:targetfile())) -- get the run directory of target @@ -62,4 +57,45 @@ function main (target, opt) os.cd(oldir) end +-- run on simulator +function _run_on_simulator(target, opt) + + -- get devices list + local list = try { function () return os.iorun("xcrun simctl list") end} + assert(list, "simulator devices not found!") + + -- find the booted devices + local devices = {} + for _, line in ipairs(list:split('\n', {plain = true})) do + if line:find("(Booted)", 1, true) then + line = line:trim() + local name, deviceid = line:match("(.-)%s+%(([%w%-]+)%)") + if name and deviceid then + devices[name] = deviceid + end + end + end + + -- do launch on first simulator device + local bundle_identifier = target:values("xcode.bundle_identifier") or get_config("xcode_bundle_identifier") or "io.xmake." .. target:name() + if bundle_identifier then + for name, deviceid in pairs(devices) do + print("running %s application on %s (%s) ..", target:name(), name, deviceid) + os.execv("xcrun", {"simctl", "launch", "--console", deviceid, bundle_identifier}) + break + end + end +end + +-- main entry +function main (target, opt) + if is_plat("macosx") then + _run_on_macosx(target, opt) + elseif is_plat("iphoneos") and is_arch("x86_64", "i386") then + _run_on_simulator(target, opt) + else + raise("we can only run application on macOS or simulator!") + end +end + |
