2021-05-06 15:19:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "avdmanageroutputparser.h"
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
#include <utils/fileutils.h>
|
2021-05-07 11:17:29 +02:00
|
|
|
#include <utils/optional.h>
|
2021-05-06 15:19:56 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
#include <utils/variant.h>
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
Q_LOGGING_CATEGORY(avdOutputParserLog, "qtc.android.avdOutputParser", QtWarningMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avd list keys to parse avd
|
|
|
|
const char avdInfoNameKey[] = "Name:";
|
|
|
|
const char avdInfoPathKey[] = "Path:";
|
|
|
|
const char avdInfoAbiKey[] = "abi.type";
|
|
|
|
const char avdInfoTargetKey[] = "target";
|
|
|
|
const char avdInfoErrorKey[] = "Error:";
|
|
|
|
const char avdInfoSdcardKey[] = "Sdcard";
|
|
|
|
const char avdInfoTargetTypeKey[] = "Target";
|
|
|
|
const char avdInfoDeviceKey[] = "Device";
|
|
|
|
const char avdInfoSkinKey[] = "Skin";
|
|
|
|
|
|
|
|
namespace Android {
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Parses the \a line for a [spaces]key[spaces]value[spaces] pattern and returns
|
|
|
|
\c true if the key is found, \c false otherwise. The value is copied into \a value.
|
|
|
|
*/
|
|
|
|
static bool valueForKey(QString key, const QString &line, QString *value = nullptr)
|
|
|
|
{
|
|
|
|
auto trimmedInput = line.trimmed();
|
|
|
|
if (trimmedInput.startsWith(key)) {
|
|
|
|
if (value)
|
|
|
|
*value = trimmedInput.section(key, 1, 1).trimmed();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:17:29 +02:00
|
|
|
static Utils::optional<AndroidDeviceInfo> parseAvd(const QStringList &deviceInfo)
|
2021-05-06 15:19:56 +02:00
|
|
|
{
|
2021-05-07 11:17:29 +02:00
|
|
|
AndroidDeviceInfo avd;
|
2021-05-06 15:19:56 +02:00
|
|
|
for (const QString &line : deviceInfo) {
|
|
|
|
QString value;
|
|
|
|
if (valueForKey(avdInfoErrorKey, line)) {
|
|
|
|
qCDebug(avdOutputParserLog) << "Avd Parsing: Skip avd device. Error key found:" << line;
|
2021-05-07 11:17:29 +02:00
|
|
|
return {};
|
2021-05-06 15:19:56 +02:00
|
|
|
} else if (valueForKey(avdInfoNameKey, line, &value)) {
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.avdname = value;
|
2021-05-06 15:19:56 +02:00
|
|
|
} else if (valueForKey(avdInfoPathKey, line, &value)) {
|
|
|
|
const Utils::FilePath avdPath = Utils::FilePath::fromString(value);
|
|
|
|
if (avdPath.exists()) {
|
|
|
|
// Get ABI.
|
|
|
|
const Utils::FilePath configFile = avdPath.pathAppended("config.ini");
|
|
|
|
QSettings config(configFile.toString(), QSettings::IniFormat);
|
|
|
|
value = config.value(avdInfoAbiKey).toString();
|
|
|
|
if (!value.isEmpty())
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.cpuAbi << value;
|
2021-05-06 15:19:56 +02:00
|
|
|
else
|
|
|
|
qCDebug(avdOutputParserLog) << "Avd Parsing: Cannot find ABI:" << configFile;
|
|
|
|
|
|
|
|
// Get Target
|
2021-05-07 11:17:29 +02:00
|
|
|
const QString avdInfoFileName = avd.avdname + ".ini";
|
2021-05-06 15:19:56 +02:00
|
|
|
const Utils::FilePath avdInfoFile = avdPath.parentDir().pathAppended(
|
|
|
|
avdInfoFileName);
|
|
|
|
QSettings avdInfo(avdInfoFile.toString(), QSettings::IniFormat);
|
|
|
|
value = avdInfo.value(avdInfoTargetKey).toString();
|
|
|
|
if (!value.isEmpty())
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.sdk = value.section('-', -1).toInt();
|
2021-05-06 15:19:56 +02:00
|
|
|
else
|
|
|
|
qCDebug(avdOutputParserLog)
|
|
|
|
<< "Avd Parsing: Cannot find sdk API:" << avdInfoFile.toString();
|
|
|
|
}
|
|
|
|
} else if (valueForKey(avdInfoDeviceKey, line, &value)) {
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.avdDevice = value.remove(0, 2);
|
2021-05-06 15:19:56 +02:00
|
|
|
} else if (valueForKey(avdInfoTargetTypeKey, line, &value)) {
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.avdTarget = value.remove(0, 2);
|
2021-05-06 15:19:56 +02:00
|
|
|
} else if (valueForKey(avdInfoSkinKey, line, &value)) {
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.avdSkin = value.remove(0, 2);
|
2021-05-06 15:19:56 +02:00
|
|
|
} else if (valueForKey(avdInfoSdcardKey, line, &value)) {
|
2021-05-07 11:17:29 +02:00
|
|
|
avd.avdSdcardSize = value.remove(0, 2);
|
2021-05-06 15:19:56 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-07 11:17:29 +02:00
|
|
|
if (avd != AndroidDeviceInfo())
|
|
|
|
return avd;
|
|
|
|
return {};
|
2021-05-06 15:19:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AndroidDeviceInfoList parseAvdList(const QString &output, QStringList *avdErrorPaths)
|
|
|
|
{
|
|
|
|
QTC_CHECK(avdErrorPaths);
|
|
|
|
AndroidDeviceInfoList avdList;
|
|
|
|
QStringList avdInfo;
|
|
|
|
using ErrorPath = QString;
|
|
|
|
using AvdResult = Utils::variant<std::monostate, AndroidDeviceInfo, ErrorPath>;
|
|
|
|
const auto parseAvdInfo = [](const QStringList &avdInfo) {
|
|
|
|
if (!avdInfo.filter(avdManufacturerError).isEmpty()) {
|
|
|
|
for (const QString &line : avdInfo) {
|
|
|
|
QString value;
|
|
|
|
if (valueForKey(avdInfoPathKey, line, &value))
|
|
|
|
return AvdResult(value); // error path
|
|
|
|
}
|
2021-05-07 11:17:29 +02:00
|
|
|
} else if (Utils::optional<AndroidDeviceInfo> avd = parseAvd(avdInfo)) {
|
2021-05-06 15:19:56 +02:00
|
|
|
// armeabi-v7a devices can also run armeabi code
|
2021-05-07 11:17:29 +02:00
|
|
|
if (avd->cpuAbi.contains(ProjectExplorer::Constants::ANDROID_ABI_ARMEABI_V7A))
|
|
|
|
avd->cpuAbi << ProjectExplorer::Constants::ANDROID_ABI_ARMEABI;
|
|
|
|
avd->state = AndroidDeviceInfo::OkState;
|
|
|
|
avd->type = AndroidDeviceInfo::Emulator;
|
|
|
|
return AvdResult(*avd);
|
2021-05-06 15:19:56 +02:00
|
|
|
} else {
|
|
|
|
qCDebug(avdOutputParserLog) << "Avd Parsing: Parsing failed: " << avdInfo;
|
|
|
|
}
|
|
|
|
return AvdResult();
|
|
|
|
};
|
|
|
|
|
2021-05-28 18:22:44 +03:00
|
|
|
const auto lines = output.split('\n');
|
|
|
|
for (const QString &line : lines) {
|
2021-05-06 15:19:56 +02:00
|
|
|
if (line.startsWith("---------") || line.isEmpty()) {
|
|
|
|
const AvdResult result = parseAvdInfo(avdInfo);
|
|
|
|
if (auto info = Utils::get_if<AndroidDeviceInfo>(&result))
|
|
|
|
avdList << *info;
|
|
|
|
else if (auto errorPath = Utils::get_if<ErrorPath>(&result))
|
|
|
|
*avdErrorPaths << *errorPath;
|
|
|
|
avdInfo.clear();
|
|
|
|
} else {
|
|
|
|
avdInfo << line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Utils::sort(avdList);
|
|
|
|
|
|
|
|
return avdList;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace Android
|