Make simulator detection work with Xcode 11

Beta version of Xcode 11 changes the format of the json object
returned by simctl and used to detect running simulators.

While multiple versions of Xcode can coexist on the same system,
they share the same simulator infrastructure so installing
Xcode 11 Beta affects projects using previous versions.

Change-Id: Icf06a794aa5ba3624163ace2ce827c0ecf97c38c
Reviewed-by: Frank Osterfeld <frank.osterfeld@kdab.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Mike Krus 2019-07-19 16:00:57 +01:00
parent 857e4881c6
commit b202d45026

View File

@ -46,11 +46,17 @@ import json
import subprocess
from distutils.version import StrictVersion
def is_available(object):
if "isAvailable" in object:
return object["isAvailable"] # introduced in Xcode 11
else:
return "unavailable" not in object["availability"]
def is_suitable_runtime(runtimes, runtime_name, platform, min_version):
for runtime in runtimes:
identifier = runtime["identifier"]
if (runtime["name"] == runtime_name or identifier == runtime_name) \
and "unavailable" not in runtime["availability"] \
and is_available(runtime) \
and identifier.startswith("com.apple.CoreSimulator.SimRuntime.{}".format(platform)) \
and StrictVersion(runtime["version"]) >= min_version:
return True
@ -77,6 +83,6 @@ if __name__ == "__main__":
for runtime_name in device_dict:
if is_suitable_runtime(runtimes, runtime_name, args.platform, args.minimum_deployment_target):
for device in device_dict[runtime_name]:
if "unavailable" not in device["availability"] \
if is_available(device) \
and (args.state is None or device["state"].lower() in args.state):
print(device["udid"])