iOS: Move app URL gathering from devicectl to a function

And add a test to document what we expect from devicectl.

Change-Id: I2f5312ebadef60239b77308acb7114f1d55143b4
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Eike Ziller
2024-01-29 16:25:13 +01:00
parent 759ea7695f
commit 2898e09bb4
4 changed files with 76 additions and 11 deletions

View File

@@ -83,4 +83,17 @@ expected_str<QMap<QString, QString>> parseDeviceInfo(const QByteArray &rawOutput
return make_unexpected(QLatin1String("Device is not handled by devicectl"));
}
Utils::expected_str<QUrl> parseAppInfo(const QByteArray &rawOutput, const QString &bundleIdentifier)
{
const Utils::expected_str<QJsonValue> result = parseDevicectlResult(rawOutput);
if (!result)
return make_unexpected(result.error());
const QJsonArray apps = (*result)["apps"].toArray();
for (const QJsonValue &app : apps) {
if (app["bundleIdentifier"].toString() == bundleIdentifier)
return QUrl(app["url"].toString());
}
return {};
}
} // namespace Ios::Internal

View File

@@ -22,5 +22,6 @@ const char vYes[] = "YES";
Utils::expected_str<QJsonValue> parseDevicectlResult(const QByteArray &rawOutput);
Utils::expected_str<QMap<QString, QString>> parseDeviceInfo(const QByteArray &rawOutput,
const QString &deviceUsbId);
Utils::expected_str<QUrl> parseAppInfo(const QByteArray &rawOutput, const QString &bundleIdentifier);
} // namespace Ios::Internal

View File

@@ -146,19 +146,12 @@ GroupItem DeviceCtlRunner::findApp(const QString &bundleIdentifier, Storage<AppI
reportFailure(Tr::tr("Failed to run devicectl: %1.").arg(process.errorString()));
return DoneResult::Error;
}
const Utils::expected_str<QJsonValue> resultValue = parseDevicectlResult(
process.rawStdOut());
if (resultValue) {
const QJsonArray apps = (*resultValue)["apps"].toArray();
for (const QJsonValue &app : apps) {
if (app["bundleIdentifier"].toString() == bundleIdentifier) {
appInfo->pathOnDevice = QUrl(app["url"].toString());
break;
}
}
const expected_str<QUrl> pathOnDevice = parseAppInfo(process.rawStdOut(), bundleIdentifier);
if (pathOnDevice) {
appInfo->pathOnDevice = *pathOnDevice;
return DoneResult::Success;
}
reportFailure(resultValue.error());
reportFailure(pathOnDevice.error());
return DoneResult::Error;
};
return ProcessTask(onSetup, onDone);