iOS: Simplify starting simulator

We do not need different code paths for Xcode < 9 nowadays.
Just tell simctl too boot the requested device and make sure the
Simulator app is running.

This also fixes an issue if for some reason a different device is already
booted without the Simulator app running, e.g.

1. make sure Simulator is not running
2. boot a device from the command line with
   `xcrun simctl boot <deviceID>` (get the device ID from the Devices &
   Simulators window in Xcode)
3. start Qt Creator and run an application on a *different* simulator
   device

Without this patch Simulator app opens with the device from (2) and
deployment of the application fails for the different device.
With this patch the device for (3) is booted and the application
deployed and run.

Change-Id: Ifce8c470f2d4d646295ca4e47fbd92308f87adf8
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Eike Ziller
2024-07-24 08:43:28 +02:00
parent 5cd35e33b3
commit 959f5fa3a2

View File

@@ -108,23 +108,16 @@ static expected_str<void> launchSimulator(const QString &simUdid, std::function<
const FilePath simulatorAppPath = IosConfigurations::developerPath()
.pathAppended("Applications/Simulator.app/Contents/MacOS/Simulator");
if (IosConfigurations::xcodeVersion() >= QVersionNumber(9)) {
// For XCode 9 boot the second device instead of launching simulator app twice.
QString psOutput;
expected_str<void> result = runCommand({"ps", {"-A", "-o", "comm"}}, &psOutput, shouldStop);
if (!result)
return result;
// boot the requested simulator device
const expected_str<void> bootResult = runSimCtlCommand({"boot", simUdid}, nullptr, shouldStop);
if (!bootResult)
return bootResult;
for (const QString &comm : psOutput.split('\n')) {
if (comm == simulatorAppPath.toString())
return runSimCtlCommand({"boot", simUdid}, nullptr, shouldStop);
}
}
const bool started = Process::startDetached(
{simulatorAppPath, {"--args", "-CurrentDeviceUDID", simUdid}});
if (!started)
return make_unexpected(Tr::tr("Failed to start simulator app."));
return {};
// open Simulator.app if not running yet
return runCommand(
{"/usr/bin/open",
{IosConfigurations::developerPath().pathAppended("Applications/Simulator.app").nativePath()}},
nullptr);
}
static bool isAvailable(const QJsonObject &object)