Skip to content

Prefer currently booted iOS Simulator #1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

gregdenness
Copy link

This PR updates XCodeHelper.getSimulatorID to first check if a simulator is already running and use that device's UDID, if there are no simulators running it will fall back to original behaviour.

This improves usability when switching simulators manually via the Simulator app, as users may wish to switch simulators multiple times during testing. For example if I open an "iPad 11 inch" simulator specifically and then build I'd expect it to be installed and run on that simulator.

This change is non-breaking and falls back to the existing logic if no simulator is currently running.

Updated XCodeHelper.getSimulatorID to check for a currently booted simulator via `xcrun simctl list devices booted` before falling back to project target flags or default logic. This improves behavior when switching simulators manually in the Simulator app.
// Match a line like: " iPhone 15 Pro (E5B048F6-BE70-498E-B5F6-B84B8594DDBF) (Booted)"
var match = ~/.*\(([A-F0-9\-]{36})\)\s+\(Booted\)/;
if (match.match(line)) {
return match.matched(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with the rest of the code in this class, can you tweak this to use the existing getSimulatorID() method that we're using elsewhere? You can probably simplify the initial match as line.indexOf("(Booted)") in that case.

@@ -173,6 +188,15 @@ class XCodeHelper

public static function getSimulatorID(project:HXProject):String
{
// try and get the simulator which is currently open and running
// if there are none running then fall back to getting the selected simulator
var booted = getBootedSimulatorID();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also modify getSimulatorName() to also return the booted simulator name? Both getSimulatorID() and getSimulatorName() are expected to return the same simulator.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yeah sure no problem. I'll do this next week. Thanks for the quick reply.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! It's a good enhancement.

gregdenness and others added 2 commits March 31, 2025 12:18
getBootedSimulator now uses the same logic to match simulator name as elsewhere and also returns SimulatorInfo.
getSimulatorName now returns the booted simulator name.
It appears that modern simulators have started adding their CPU types to their names, "like iPad Air (M4)" which was causing the exiting code to return the incorrect string for the ID (it would return 'M4' as the ID in that case). I fixed this by searching for ID's which are specifically 36 chars long which is the format the ID's follow.

I think this probably would have affected the code in the current release version of lime?
@gregdenness
Copy link
Author

I have updated the code to be consistent with the existing code as requested. I then encountered a strange issue where it wasn't working on certain simulators - those which had the cpu type in their names - such as "iPad air (M2)" - the (M2) part was breaking the extractSimulatorID function because of the parenthesis. I changed extractSimulatorID so that it looks for a 36 digit ID (all simulator IDs are). This is probably affecting the current lime release, though obviously only simulators which have the CPU type in their names.

@joshtynjala
Copy link
Member

Thanks! I'll test a bit and get it merged when I have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants