2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2012-12-07 19:52:56 +02:00
|
|
|
#include "androidconfigurations.h"
|
2022-10-06 17:53:35 +02:00
|
|
|
#include "androidconstants.h"
|
2012-12-07 19:52:56 +02:00
|
|
|
#include "androidmanager.h"
|
2022-10-06 17:53:35 +02:00
|
|
|
#include "androidqtversion.h"
|
|
|
|
|
#include "androidtr.h"
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2022-07-04 07:40:05 +02:00
|
|
|
#include <utils/algorithm.h>
|
2012-12-07 19:52:56 +02:00
|
|
|
#include <utils/environment.h>
|
2013-02-04 13:34:09 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2012-12-07 19:52:56 +02:00
|
|
|
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <qtsupport/qtsupportconstants.h>
|
2012-12-07 19:52:56 +02:00
|
|
|
#include <qtsupport/qtversionmanager.h>
|
|
|
|
|
|
2021-02-12 20:57:18 +01:00
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
2020-07-23 15:48:56 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2021-02-12 20:57:18 +01:00
|
|
|
#include <projectexplorer/projectnodes.h>
|
2013-03-07 17:12:03 +01:00
|
|
|
#include <projectexplorer/target.h>
|
2012-12-07 19:52:56 +02:00
|
|
|
#include <projectexplorer/kit.h>
|
2014-06-25 15:42:11 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2014-11-19 17:58:33 +01:00
|
|
|
#include <projectexplorer/projecttree.h>
|
2021-08-23 21:36:55 +03:00
|
|
|
#include <projectexplorer/buildsystem.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-08-01 12:49:47 +02:00
|
|
|
#include <proparser/profileevaluator.h>
|
|
|
|
|
|
2020-06-16 07:48:09 +02:00
|
|
|
#include <QRegularExpression>
|
|
|
|
|
|
2012-12-07 19:52:56 +02:00
|
|
|
using namespace ProjectExplorer;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2019-02-14 12:29:00 +01:00
|
|
|
namespace Android {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
AndroidQtVersion::AndroidQtVersion()
|
2022-01-21 16:06:36 +01:00
|
|
|
: QtSupport::QtVersion()
|
2019-11-18 16:57:44 +01:00
|
|
|
, m_guard(std::make_unique<QObject>())
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2019-11-18 16:57:44 +01:00
|
|
|
QObject::connect(AndroidConfigurations::instance(),
|
|
|
|
|
&AndroidConfigurations::aboutToUpdate,
|
|
|
|
|
m_guard.get(),
|
|
|
|
|
[this] { resetCache(); });
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidQtVersion::isValid() const
|
|
|
|
|
{
|
2022-01-21 16:06:36 +01:00
|
|
|
if (!QtVersion::isValid())
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
|
if (qtAbis().isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidQtVersion::invalidReason() const
|
|
|
|
|
{
|
2022-01-21 16:06:36 +01:00
|
|
|
QString tmp = QtVersion::invalidReason();
|
2019-10-08 13:07:06 +02:00
|
|
|
if (tmp.isEmpty()) {
|
2020-02-16 20:46:23 +02:00
|
|
|
if (AndroidConfigurations::currentConfig().ndkLocation(this).isEmpty())
|
2022-10-06 17:53:35 +02:00
|
|
|
return Tr::tr("NDK is not configured in Devices > Android.");
|
2019-10-08 13:07:06 +02:00
|
|
|
if (AndroidConfigurations::currentConfig().sdkLocation().isEmpty())
|
2022-10-06 17:53:35 +02:00
|
|
|
return Tr::tr("SDK is not configured in Devices > Android.");
|
2019-10-08 13:07:06 +02:00
|
|
|
if (qtAbis().isEmpty())
|
2022-10-06 17:53:35 +02:00
|
|
|
return Tr::tr("Failed to detect the ABIs used by the Qt version. Check the settings in "
|
|
|
|
|
"Devices > Android for errors.");
|
2019-10-08 13:07:06 +02:00
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-20 13:58:21 +02:00
|
|
|
bool AndroidQtVersion::supportsMultipleQtAbis() const
|
|
|
|
|
{
|
2022-07-04 18:36:40 +02:00
|
|
|
return qtVersion() >= QVersionNumber(5, 14) && qtVersion() < QVersionNumber(6, 0);
|
2020-08-20 13:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 11:04:18 +02:00
|
|
|
Abis AndroidQtVersion::detectQtAbis() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2022-07-07 13:39:50 +02:00
|
|
|
const bool conf = AndroidConfigurations::currentConfig().sdkFullyConfigured();
|
|
|
|
|
return conf ? Utils::transform<Abis>(androidAbis(), &AndroidManager::androidAbi2Abi) : Abis();
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:50:37 +02:00
|
|
|
void AndroidQtVersion::addToEnvironment(const Kit *k, Utils::Environment &env) const
|
2012-12-07 19:52:56 +02:00
|
|
|
{
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion::addToEnvironment(k, env);
|
2020-04-16 14:38:46 +02:00
|
|
|
|
|
|
|
|
const AndroidConfig &config = AndroidConfigurations::currentConfig();
|
2012-12-07 19:52:56 +02:00
|
|
|
// this env vars are used by qmake mkspecs to generate makefiles (check QTDIR/mkspecs/android-g++/qmake.conf for more info)
|
2020-02-16 20:46:23 +02:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_HOST"), config.toolchainHost(this));
|
|
|
|
|
env.set(QLatin1String("ANDROID_NDK_ROOT"), config.ndkLocation(this).toUserOutput());
|
2018-12-05 13:00:36 +01:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_PLATFORM"),
|
2020-02-16 20:46:23 +02:00
|
|
|
config.bestNdkPlatformMatch(qMax(minimumNDK(), AndroidManager::minimumSDK(k)), this));
|
2012-12-07 19:52:56 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-25 15:54:12 +02:00
|
|
|
void AndroidQtVersion::setupQmakeRunEnvironment(Utils::Environment &env) const
|
2014-03-27 13:12:28 +01:00
|
|
|
{
|
2020-02-16 20:46:23 +02:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_ROOT"),
|
|
|
|
|
AndroidConfigurations::currentConfig().ndkLocation(this).toUserOutput());
|
2014-03-27 13:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
QString AndroidQtVersion::description() const
|
|
|
|
|
{
|
2012-08-01 15:25:05 +02:00
|
|
|
//: Qt Version is meant for Android
|
2022-10-06 17:53:35 +02:00
|
|
|
return Tr::tr("Android");
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-26 14:19:07 +03:00
|
|
|
const QStringList &AndroidQtVersion::androidAbis() const
|
2013-08-01 12:49:47 +02:00
|
|
|
{
|
|
|
|
|
ensureMkSpecParsed();
|
2019-08-26 14:19:07 +03:00
|
|
|
return m_androidAbis;
|
2013-08-01 12:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-18 11:18:05 +01:00
|
|
|
int AndroidQtVersion::minimumNDK() const
|
2018-11-23 10:08:35 +01:00
|
|
|
{
|
|
|
|
|
ensureMkSpecParsed();
|
|
|
|
|
return m_minNdk;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-12 20:57:18 +01:00
|
|
|
Utils::FilePath AndroidQtVersion::androidDeploymentSettings(const Target *target)
|
|
|
|
|
{
|
|
|
|
|
// Try to fetch the file name from node data as provided by qmake and Qbs
|
2021-08-23 21:36:55 +03:00
|
|
|
QString buildKey = target->activeBuildKey();
|
2021-02-12 20:57:18 +01:00
|
|
|
const ProjectNode *node = target->project()->findNodeForBuildKey(buildKey);
|
|
|
|
|
if (node) {
|
|
|
|
|
const QString nameFromData = node->data(Constants::AndroidDeploySettingsFile).toString();
|
|
|
|
|
if (!nameFromData.isEmpty())
|
|
|
|
|
return Utils::FilePath::fromUserInput(nameFromData);
|
|
|
|
|
}
|
2021-08-23 21:36:55 +03:00
|
|
|
|
2021-02-12 20:57:18 +01:00
|
|
|
// If unavailable, construct the name by ourselves (CMake)
|
2021-08-23 21:36:55 +03:00
|
|
|
const BuildSystem *bs = target->buildSystem();
|
|
|
|
|
if (!bs)
|
|
|
|
|
return {};
|
2021-09-09 11:45:48 +03:00
|
|
|
const QString displayName = bs->buildTarget(buildKey).displayName;
|
|
|
|
|
return AndroidManager::buildDirectory(target).pathAppended(
|
|
|
|
|
AndroidManager::isQt5CmakeProject(target)
|
|
|
|
|
? QLatin1String("android_deployment_settings.json")
|
|
|
|
|
: QString::fromLatin1("android-%1-deployment-settings.json")
|
|
|
|
|
.arg(displayName));
|
2021-02-12 20:57:18 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-01 12:49:47 +02:00
|
|
|
void AndroidQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const
|
|
|
|
|
{
|
2020-10-23 16:26:49 +03:00
|
|
|
m_androidAbis = evaluator->values("ALL_ANDROID_ABIS");
|
|
|
|
|
if (m_androidAbis.isEmpty())
|
2021-09-05 18:49:26 +03:00
|
|
|
m_androidAbis = QStringList{evaluator->value(Constants::ANDROID_TARGET_ARCH)};
|
2019-08-26 14:19:07 +03:00
|
|
|
const QString androidPlatform = evaluator->value("ANDROID_PLATFORM");
|
2018-11-23 10:08:35 +01:00
|
|
|
if (!androidPlatform.isEmpty()) {
|
2020-06-16 07:48:09 +02:00
|
|
|
const QRegularExpression regex("android-(\\d+)");
|
|
|
|
|
const QRegularExpressionMatch match = regex.match(androidPlatform);
|
|
|
|
|
if (match.hasMatch()) {
|
2018-11-23 10:08:35 +01:00
|
|
|
bool ok = false;
|
2020-06-16 07:48:09 +02:00
|
|
|
int tmp = match.captured(1).toInt(&ok);
|
2018-11-23 10:08:35 +01:00
|
|
|
if (ok)
|
|
|
|
|
m_minNdk = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-21 16:06:36 +01:00
|
|
|
QtVersion::parseMkSpec(evaluator);
|
2013-08-01 12:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QSet<Utils::Id> AndroidQtVersion::availableFeatures() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2022-01-21 16:06:36 +01:00
|
|
|
QSet<Utils::Id> features = QtSupport::QtVersion::availableFeatures();
|
2015-11-27 11:31:35 +01:00
|
|
|
features.insert(QtSupport::Constants::FEATURE_MOBILE);
|
|
|
|
|
features.remove(QtSupport::Constants::FEATURE_QT_CONSOLE);
|
|
|
|
|
features.remove(QtSupport::Constants::FEATURE_QT_WEBKIT);
|
2012-04-18 20:30:57 +03:00
|
|
|
return features;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QSet<Utils::Id> AndroidQtVersion::targetDeviceTypes() const
|
2015-11-27 14:02:44 +01:00
|
|
|
{
|
2017-02-22 15:09:35 +01:00
|
|
|
return {Constants::ANDROID_DEVICE_TYPE};
|
2015-11-27 14:02:44 +01:00
|
|
|
}
|
2019-02-14 12:29:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Factory
|
|
|
|
|
|
|
|
|
|
AndroidQtVersionFactory::AndroidQtVersionFactory()
|
|
|
|
|
{
|
|
|
|
|
setQtVersionCreator([] { return new AndroidQtVersion; });
|
2021-09-05 18:49:26 +03:00
|
|
|
setSupportedType(Constants::ANDROID_QT_TYPE);
|
2019-02-14 12:29:00 +01:00
|
|
|
setPriority(90);
|
|
|
|
|
|
|
|
|
|
setRestrictionChecker([](const SetupData &setup) {
|
|
|
|
|
return !setup.config.contains("android-no-sdk")
|
|
|
|
|
&& (setup.config.contains("android")
|
|
|
|
|
|| setup.platforms.contains("android"));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
} // Android
|