]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133131: Discover an appropriate iOS simulator rather than hard-coding iPhone SE...
authorRussell Keith-Magee <russell@keith-magee.com>
Tue, 29 Apr 2025 21:35:36 +0000 (05:35 +0800)
committerGitHub <noreply@github.com>
Tue, 29 Apr 2025 21:35:36 +0000 (05:35 +0800)
Determines a candidate simulator at runtime rather than hardcoding iPhone SE.

Misc/NEWS.d/next/Tests/2025-04-29-14-56-37.gh-issue-133131.1pchjl.rst [new file with mode: 0644]
iOS/testbed/__main__.py

diff --git a/Misc/NEWS.d/next/Tests/2025-04-29-14-56-37.gh-issue-133131.1pchjl.rst b/Misc/NEWS.d/next/Tests/2025-04-29-14-56-37.gh-issue-133131.1pchjl.rst
new file mode 100644 (file)
index 0000000..30b0f18
--- /dev/null
@@ -0,0 +1,2 @@
+The iOS testbed will now select the most recently released "SE-class" device
+for testing if a device isn't explicitly specified.
index b436c9af99d2c45f91723286072e6596bbeac0c0..c05497ede3aa6151bacbd75e013a5e012d146684 100644 (file)
@@ -123,6 +123,36 @@ async def async_check_output(*args, **kwargs):
             )
 
 
+# Select a simulator device to use.
+async def select_simulator_device():
+    # List the testing simulators, in JSON format
+    raw_json = await async_check_output(
+        "xcrun", "simctl", "--set", "testing", "list", "-j"
+    )
+    json_data = json.loads(raw_json)
+
+    # Any device will do; we'll look for "SE" devices - but the name isn't
+    # consistent over time. Older Xcode versions will use "iPhone SE (Nth
+    # generation)"; As of 2025, they've started using "iPhone 16e".
+    #
+    # When Xcode is updated after a new release, new devices will be available
+    # and old ones will be dropped from the set available on the latest iOS
+    # version. Select the one with the highest minimum runtime version - this
+    # is an indicator of the "newest" released device, which should always be
+    # supported on the "most recent" iOS version.
+    se_simulators = sorted(
+        (devicetype["minRuntimeVersion"], devicetype["name"])
+        for devicetype in json_data["devicetypes"]
+        if devicetype["productFamily"] == "iPhone"
+        and (
+            ("iPhone " in devicetype["name"] and devicetype["name"].endswith("e"))
+            or "iPhone SE " in devicetype["name"]
+        )
+    )
+
+    return se_simulators[-1][1]
+
+
 # Return a list of UDIDs associated with booted simulators
 async def list_devices():
     try:
@@ -371,12 +401,16 @@ def update_plist(testbed_path, args):
         plistlib.dump(info, f)
 
 
-async def run_testbed(simulator: str, args: list[str], verbose: bool=False):
+async def run_testbed(simulator: str | None, args: list[str], verbose: bool=False):
     location = Path(__file__).parent
     print("Updating plist...", end="", flush=True)
     update_plist(location, args)
     print(" done.", flush=True)
 
+    if simulator is None:
+        simulator = await select_simulator_device()
+    print(f"Running test on {simulator}", flush=True)
+
     # We need to get an exclusive lock on simulator creation, to avoid issues
     # with multiple simulators starting and being unable to tell which
     # simulator is due to which testbed instance. See
@@ -453,8 +487,10 @@ def main():
     )
     run.add_argument(
         "--simulator",
-        default="iPhone SE (3rd Generation)",
-        help="The name of the simulator to use (default: 'iPhone SE (3rd Generation)')",
+        help=(
+            "The name of the simulator to use (eg: 'iPhone 16e'). Defaults to ",
+            "the most recently released 'entry level' iPhone device."
+        )
     )
     run.add_argument(
         "-v", "--verbose",