2012-04-18 20:30:57 +03:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (c) 2014 BogDan Vatra <bog_dan_ro@yahoo.com>
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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 Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2012-04-18 20:30:57 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2012-04-18 20:30:57 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include "androidtoolchain.h"
|
|
|
|
|
#include "androidconstants.h"
|
|
|
|
|
#include "androidconfigurations.h"
|
|
|
|
|
#include "androidqtversion.h"
|
2012-12-07 19:52:56 +02:00
|
|
|
|
2013-08-28 13:34:24 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2012-12-07 19:52:56 +02:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
|
|
|
|
#include <qtsupport/qtversionmanager.h>
|
|
|
|
|
|
2012-07-03 16:57:44 +03:00
|
|
|
#include <projectexplorer/target.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <projectexplorer/toolchainmanager.h>
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/environment.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
#include <QDir>
|
2013-01-25 16:49:22 +01:00
|
|
|
#include <QDirIterator>
|
2012-08-16 15:59:10 +02:00
|
|
|
#include <QFormLayout>
|
2012-04-18 20:30:57 +03:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
namespace {
|
|
|
|
|
const QLatin1String NDKGccVersionRegExp("-\\d[\\.\\d]+");
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
namespace Android {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
using namespace ProjectExplorer;
|
2012-08-23 15:53:58 +02:00
|
|
|
using namespace Utils;
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
static const char ANDROID_QT_VERSION_KEY[] = "Qt4ProjectManager.Android.QtVersion";
|
2013-01-25 16:49:22 +01:00
|
|
|
static const char ANDROID_NDK_TC_VERION[] = "Qt4ProjectManager.Android.NDK_TC_VERION";
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-08-28 13:34:24 +02:00
|
|
|
QMap<ProjectExplorer::Abi::Architecture, QList<int> > AndroidToolChainFactory::m_newestVersionForArch;
|
|
|
|
|
Utils::FileName AndroidToolChainFactory::m_ndkLocation;
|
|
|
|
|
|
2013-09-03 10:58:59 +02:00
|
|
|
AndroidToolChain::AndroidToolChain(Abi::Architecture arch, const QString &ndkToolChainVersion, Detection d)
|
|
|
|
|
: GccToolChain(QLatin1String(Constants::ANDROID_TOOLCHAIN_ID), d),
|
2013-08-28 13:34:24 +02:00
|
|
|
m_ndkToolChainVersion(ndkToolChainVersion), m_secondaryToolChain(false)
|
2013-01-25 16:49:22 +01:00
|
|
|
{
|
|
|
|
|
ProjectExplorer::Abi abi = ProjectExplorer::Abi(arch, ProjectExplorer::Abi::LinuxOS,
|
|
|
|
|
ProjectExplorer::Abi::AndroidLinuxFlavor, ProjectExplorer::Abi::ElfFormat,
|
|
|
|
|
32);
|
|
|
|
|
setTargetAbi(abi);
|
|
|
|
|
setDisplayName(QString::fromLatin1("Android GCC (%1-%2)")
|
|
|
|
|
.arg(Abi::toString(targetAbi().architecture()))
|
|
|
|
|
.arg(ndkToolChainVersion));
|
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
// for fromMap
|
|
|
|
|
AndroidToolChain::AndroidToolChain()
|
2013-09-03 10:58:59 +02:00
|
|
|
: GccToolChain(QLatin1String(Constants::ANDROID_TOOLCHAIN_ID), ToolChain::ManualDetection),
|
2013-08-28 13:34:24 +02:00
|
|
|
m_secondaryToolChain(false)
|
2013-01-25 16:49:22 +01:00
|
|
|
{
|
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
|
|
|
|
AndroidToolChain::AndroidToolChain(const AndroidToolChain &tc) :
|
2013-08-28 13:34:24 +02:00
|
|
|
GccToolChain(tc), m_ndkToolChainVersion(tc.m_ndkToolChainVersion),
|
|
|
|
|
m_secondaryToolChain(tc.m_secondaryToolChain)
|
2012-04-18 20:30:57 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
AndroidToolChain::~AndroidToolChain()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QString AndroidToolChain::type() const
|
|
|
|
|
{
|
2013-09-03 15:37:41 +02:00
|
|
|
return QLatin1String(Constants::ANDROID_TOOLCHAIN_TYPE);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString AndroidToolChain::typeDisplayName() const
|
|
|
|
|
{
|
|
|
|
|
return AndroidToolChainFactory::tr("Android GCC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChain::isValid() const
|
|
|
|
|
{
|
2013-02-27 12:33:21 +01:00
|
|
|
return GccToolChain::isValid() && targetAbi().isValid() && !m_ndkToolChainVersion.isEmpty()
|
|
|
|
|
&& compilerCommand().isChildOf(AndroidConfigurations::instance().config().ndkLocation);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
void AndroidToolChain::addToEnvironment(Environment &env) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// TODO this vars should be configurable in projects -> build tab
|
|
|
|
|
// TODO invalidate all .pro files !!!
|
|
|
|
|
|
2013-04-04 01:29:47 -07:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_HOST"), AndroidConfigurations::instance().config().toolchainHost);
|
2012-04-18 20:30:57 +03:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_TOOLCHAIN_PREFIX"), AndroidConfigurations::toolchainPrefix(targetAbi().architecture()));
|
|
|
|
|
env.set(QLatin1String("ANDROID_NDK_TOOLS_PREFIX"), AndroidConfigurations::toolsPrefix(targetAbi().architecture()));
|
2013-01-25 16:49:22 +01:00
|
|
|
env.set(QLatin1String("ANDROID_NDK_TOOLCHAIN_VERSION"), m_ndkToolChainVersion);
|
2013-06-10 18:18:38 +02:00
|
|
|
QString javaHome = AndroidConfigurations::instance().openJDKPath().toString();
|
|
|
|
|
if (!javaHome.isEmpty() && QFileInfo(javaHome).exists())
|
|
|
|
|
env.set(QLatin1String("JAVA_HOME"), javaHome);
|
2013-06-04 17:57:57 +02:00
|
|
|
env.set(QLatin1String("ANDROID_HOME"), AndroidConfigurations::instance().config().sdkLocation.toString());
|
2013-10-02 11:49:35 +02:00
|
|
|
env.set(QLatin1String("ANDROID_SDK_ROOT"), AndroidConfigurations::instance().config().sdkLocation.toString());
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
bool AndroidToolChain::operator ==(const ToolChain &tc) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-01-25 16:49:22 +01:00
|
|
|
if (!GccToolChain::operator ==(tc))
|
2012-04-18 20:30:57 +03:00
|
|
|
return false;
|
|
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
return m_ndkToolChainVersion == static_cast<const AndroidToolChain &>(tc).m_ndkToolChainVersion;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainConfigWidget *AndroidToolChain::configurationWidget()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
|
|
|
|
return new AndroidToolChainConfigWidget(this);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
FileName AndroidToolChain::suggestedDebugger() const
|
|
|
|
|
{
|
|
|
|
|
return AndroidConfigurations::instance().gdbPath(targetAbi().architecture(), m_ndkToolChainVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileName AndroidToolChain::suggestedGdbServer() const
|
|
|
|
|
{
|
|
|
|
|
Utils::FileName path = AndroidConfigurations::instance().config().ndkLocation;
|
|
|
|
|
path.appendPath(QString::fromLatin1("prebuilt/android-%1/gdbserver/gdbserver")
|
|
|
|
|
.arg(Abi::toString(targetAbi().architecture())));
|
|
|
|
|
if (path.toFileInfo().exists())
|
|
|
|
|
return path;
|
|
|
|
|
path = AndroidConfigurations::instance().config().ndkLocation;
|
|
|
|
|
path.appendPath(QString::fromLatin1("toolchains/%1-%2/prebuilt/gdbserver")
|
|
|
|
|
.arg(AndroidConfigurations::toolchainPrefix(targetAbi().architecture()))
|
|
|
|
|
.arg(m_ndkToolChainVersion));
|
|
|
|
|
if (path.toFileInfo().exists())
|
|
|
|
|
return path;
|
|
|
|
|
|
|
|
|
|
return Utils::FileName();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
QVariantMap AndroidToolChain::toMap() const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap result = GccToolChain::toMap();
|
2013-01-25 16:49:22 +01:00
|
|
|
result.insert(QLatin1String(ANDROID_NDK_TC_VERION), m_ndkToolChainVersion);
|
2012-04-18 20:30:57 +03:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChain::fromMap(const QVariantMap &data)
|
|
|
|
|
{
|
|
|
|
|
if (!GccToolChain::fromMap(data))
|
|
|
|
|
return false;
|
|
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
if (data.contains(QLatin1String(ANDROID_QT_VERSION_KEY))) {
|
|
|
|
|
QString command = compilerCommand().toString();
|
|
|
|
|
QString ndkPath = AndroidConfigurations::instance().config().ndkLocation.toString();
|
|
|
|
|
if (!command.startsWith(ndkPath))
|
|
|
|
|
return false;
|
|
|
|
|
command = command.mid(ndkPath.length());
|
|
|
|
|
if (!command.startsWith(QLatin1String("/toolchains/")))
|
|
|
|
|
return false;
|
|
|
|
|
command = command.mid(12);
|
|
|
|
|
int index = command.indexOf(QLatin1Char('/'));
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return false;
|
|
|
|
|
command = command.left(index);
|
|
|
|
|
QRegExp versionRegExp(NDKGccVersionRegExp);
|
|
|
|
|
index = versionRegExp.indexIn(command);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return false;
|
|
|
|
|
m_ndkToolChainVersion = command.mid(index + 1);
|
|
|
|
|
QString platform = command.left(index);
|
|
|
|
|
Abi::Architecture arch = AndroidConfigurations::architectureForToolChainPrefix(platform);
|
|
|
|
|
ProjectExplorer::Abi abi = ProjectExplorer::Abi(arch, ProjectExplorer::Abi::LinuxOS,
|
|
|
|
|
ProjectExplorer::Abi::AndroidLinuxFlavor, ProjectExplorer::Abi::ElfFormat,
|
|
|
|
|
32);
|
|
|
|
|
setTargetAbi(abi);
|
|
|
|
|
} else {
|
|
|
|
|
m_ndkToolChainVersion = data.value(QLatin1String(ANDROID_NDK_TC_VERION)).toString();
|
|
|
|
|
}
|
2012-04-18 20:30:57 +03:00
|
|
|
|
2013-08-28 13:34:24 +02:00
|
|
|
ProjectExplorer::Abi::Architecture arch = targetAbi().architecture();
|
|
|
|
|
m_secondaryToolChain = AndroidToolChainFactory::versionCompareLess(AndroidToolChainFactory::versionNumberFromString(m_ndkToolChainVersion),
|
2013-09-02 16:06:05 +02:00
|
|
|
AndroidToolChainFactory::newestToolChainVersionForArch(arch));
|
2012-04-18 20:30:57 +03:00
|
|
|
return isValid();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
QList<FileName> AndroidToolChain::suggestedMkspecList() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-23 15:53:58 +02:00
|
|
|
return QList<FileName>()<< FileName::fromString(QLatin1String("android-g++"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-09-11 15:59:17 +02:00
|
|
|
QString AndroidToolChain::makeCommand(const Utils::Environment &env) const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-05-13 13:37:31 +02:00
|
|
|
QStringList extraDirectories = AndroidConfigurations::instance().makeExtraSearchDirectories();
|
|
|
|
|
if (HostOsInfo::isWindowsHost()) {
|
|
|
|
|
QString tmp = env.searchInPath(QLatin1String("ma-make.exe"), extraDirectories);
|
|
|
|
|
if (!tmp.isEmpty())
|
|
|
|
|
return tmp;
|
|
|
|
|
tmp = env.searchInPath(QLatin1String("mingw32-make"), extraDirectories);
|
|
|
|
|
return tmp.isEmpty() ? QLatin1String("mingw32-make") : tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString make = QLatin1String("make");
|
|
|
|
|
QString tmp = env.searchInPath(make, extraDirectories);
|
2012-09-11 15:59:17 +02:00
|
|
|
return tmp.isEmpty() ? make : tmp;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2013-10-11 11:29:06 +02:00
|
|
|
QString AndroidToolChain::ndkToolChainVersion() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-01-25 16:49:22 +01:00
|
|
|
return m_ndkToolChainVersion;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2013-10-11 11:29:06 +02:00
|
|
|
bool AndroidToolChain::isSecondaryToolChain() const
|
2013-08-28 13:34:24 +02:00
|
|
|
{
|
|
|
|
|
return m_secondaryToolChain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AndroidToolChain::setSecondaryToolChain(bool b)
|
|
|
|
|
{
|
|
|
|
|
m_secondaryToolChain = b;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<Abi> AndroidToolChain::detectSupportedAbis() const
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-01-25 16:49:22 +01:00
|
|
|
return QList<Abi>() << targetAbi();
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ToolChainConfigWidget
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
AndroidToolChainConfigWidget::AndroidToolChainConfigWidget(AndroidToolChain *tc) :
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChainConfigWidget(tc)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-16 15:59:10 +02:00
|
|
|
QLabel *label = new QLabel(AndroidConfigurations::instance().config().ndkLocation.toUserOutput());
|
|
|
|
|
m_mainLayout->addRow(tr("NDK Root:"), label);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
// ToolChainFactory
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
2013-08-09 17:49:30 +02:00
|
|
|
AndroidToolChainFactory::AndroidToolChainFactory()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-08-09 17:49:30 +02:00
|
|
|
setId(Constants::ANDROID_TOOLCHAIN_ID);
|
|
|
|
|
setDisplayName(tr("Android GCC"));
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> AndroidToolChainFactory::autoDetect()
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-01-25 16:49:22 +01:00
|
|
|
return createToolChainsForNdk(AndroidConfigurations::instance().config().ndkLocation);
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChainFactory::canRestore(const QVariantMap &data)
|
|
|
|
|
{
|
|
|
|
|
return idFromMap(data).startsWith(QLatin1String(Constants::ANDROID_TOOLCHAIN_ID) + QLatin1Char(':'));
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-09 01:56:51 +02:00
|
|
|
ToolChain *AndroidToolChainFactory::restore(const QVariantMap &data)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2013-01-25 16:49:22 +01:00
|
|
|
AndroidToolChain *tc = new AndroidToolChain();
|
2012-04-18 20:30:57 +03:00
|
|
|
if (tc->fromMap(data))
|
|
|
|
|
return tc;
|
|
|
|
|
|
|
|
|
|
delete tc;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 15:51:59 +01:00
|
|
|
QList<AndroidToolChainFactory::AndroidToolChainInformation> AndroidToolChainFactory::toolchainPathsForNdk(const Utils::FileName &ndkPath)
|
|
|
|
|
{
|
|
|
|
|
QList<AndroidToolChainInformation> result;
|
|
|
|
|
if (ndkPath.isEmpty())
|
|
|
|
|
return result;
|
|
|
|
|
QRegExp versionRegExp(NDKGccVersionRegExp);
|
|
|
|
|
FileName path = ndkPath;
|
|
|
|
|
QDirIterator it(path.appendPath(QLatin1String("toolchains")).toString(),
|
|
|
|
|
QStringList() << QLatin1String("*"), QDir::Dirs);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
const QString &fileName = QFileInfo(it.next()).fileName();
|
|
|
|
|
int idx = versionRegExp.indexIn(fileName);
|
|
|
|
|
if (idx == -1)
|
|
|
|
|
continue;
|
|
|
|
|
AndroidToolChainInformation ati;
|
|
|
|
|
ati.version = fileName.mid(idx + 1);
|
|
|
|
|
QString platform = fileName.left(idx);
|
|
|
|
|
ati.architecture = AndroidConfigurations::architectureForToolChainPrefix(platform);
|
|
|
|
|
if (ati.architecture == Abi::UnknownArchitecture) // e.g. mipsel which is not yet supported
|
|
|
|
|
continue;
|
|
|
|
|
// AndroidToolChain *tc = new AndroidToolChain(arch, version, true);
|
2013-04-04 01:29:47 -07:00
|
|
|
ati.compilerCommand = AndroidConfigurations::instance().gccPath(ati.architecture, ati.version);
|
2013-02-14 15:51:59 +01:00
|
|
|
// tc->setCompilerCommand(compilerPath);
|
|
|
|
|
result.append(ati);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 13:34:24 +02:00
|
|
|
QList<int> AndroidToolChainFactory::versionNumberFromString(const QString &version)
|
|
|
|
|
{
|
|
|
|
|
QList<int> result;
|
|
|
|
|
int start = 0;
|
|
|
|
|
int end = version.length();
|
|
|
|
|
while (start <= end) {
|
|
|
|
|
int index = version.indexOf(QLatin1Char('.'), start);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
index = end;
|
|
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
|
int v = version.mid(start, index - start).toInt(&ok);
|
|
|
|
|
if (!ok) // unparseable, return what we have
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
result << v;
|
|
|
|
|
start = index + 1;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChainFactory::versionCompareLess(const QList<int> &a, const QList<int> &b)
|
|
|
|
|
{
|
|
|
|
|
int aend = a.length();
|
|
|
|
|
int bend = b.length();
|
|
|
|
|
int end = qMax(aend, bend);
|
|
|
|
|
for (int i = 0; i < end; ++i) {
|
|
|
|
|
int an = i < aend ? a.at(i) : 0;
|
|
|
|
|
int bn = i < bend ? b.at(i) : 0;
|
|
|
|
|
if (an < bn)
|
|
|
|
|
return true;
|
|
|
|
|
if (bn < an)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AndroidToolChainFactory::versionCompareLess(AndroidToolChain *atc, AndroidToolChain *btc)
|
|
|
|
|
{
|
|
|
|
|
QList<int> a = versionNumberFromString(atc->ndkToolChainVersion());
|
|
|
|
|
QList<int> b = versionNumberFromString(btc->ndkToolChainVersion());
|
|
|
|
|
|
|
|
|
|
return versionCompareLess(a, b);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
QList<ToolChain *> AndroidToolChainFactory::createToolChainsForNdk(const Utils::FileName &ndkPath)
|
2012-04-18 20:30:57 +03:00
|
|
|
{
|
2012-08-09 01:56:51 +02:00
|
|
|
QList<ToolChain *> result;
|
2013-01-25 16:49:22 +01:00
|
|
|
if (ndkPath.isEmpty())
|
|
|
|
|
return result;
|
|
|
|
|
QRegExp versionRegExp(NDKGccVersionRegExp);
|
|
|
|
|
FileName path = ndkPath;
|
|
|
|
|
QDirIterator it(path.appendPath(QLatin1String("toolchains")).toString(),
|
|
|
|
|
QStringList() << QLatin1String("*"), QDir::Dirs);
|
2013-08-28 13:34:24 +02:00
|
|
|
QMap<Abi::Architecture, AndroidToolChain *> newestToolChainForArch;
|
|
|
|
|
|
2013-01-25 16:49:22 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
const QString &fileName = QFileInfo(it.next()).fileName();
|
|
|
|
|
int idx = versionRegExp.indexIn(fileName);
|
|
|
|
|
if (idx == -1)
|
2012-04-18 20:30:57 +03:00
|
|
|
continue;
|
2013-01-25 16:49:22 +01:00
|
|
|
QString version = fileName.mid(idx + 1);
|
|
|
|
|
QString platform = fileName.left(idx);
|
|
|
|
|
Abi::Architecture arch = AndroidConfigurations::architectureForToolChainPrefix(platform);
|
|
|
|
|
if (arch == Abi::UnknownArchitecture) // e.g. mipsel which is not yet supported
|
|
|
|
|
continue;
|
2013-09-03 10:58:59 +02:00
|
|
|
AndroidToolChain *tc = new AndroidToolChain(arch, version, ToolChain::AutoDetection);
|
2013-04-04 01:29:47 -07:00
|
|
|
FileName compilerPath = AndroidConfigurations::instance().gccPath(arch, version);
|
2013-01-25 16:49:22 +01:00
|
|
|
tc->setCompilerCommand(compilerPath);
|
|
|
|
|
result.append(tc);
|
2013-08-28 13:34:24 +02:00
|
|
|
|
|
|
|
|
QMap<Abi::Architecture, AndroidToolChain *>::const_iterator it
|
|
|
|
|
= newestToolChainForArch.constFind(arch);
|
|
|
|
|
if (it == newestToolChainForArch.constEnd())
|
|
|
|
|
newestToolChainForArch.insert(arch, tc);
|
|
|
|
|
else if (versionCompareLess(it.value(), tc))
|
|
|
|
|
newestToolChainForArch[arch] = tc;
|
2012-04-18 20:30:57 +03:00
|
|
|
}
|
2013-08-28 13:34:24 +02:00
|
|
|
|
|
|
|
|
foreach (ToolChain *tc, result) {
|
|
|
|
|
AndroidToolChain *atc = static_cast<AndroidToolChain *>(tc);
|
|
|
|
|
if (newestToolChainForArch.value(atc->targetAbi().architecture()) != atc)
|
|
|
|
|
atc->setSecondaryToolChain(true);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-28 13:34:24 +02:00
|
|
|
QList<int> AndroidToolChainFactory::newestToolChainVersionForArch(Abi::Architecture arch)
|
|
|
|
|
{
|
|
|
|
|
if (m_newestVersionForArch.isEmpty()
|
|
|
|
|
|| m_ndkLocation != AndroidConfigurations::instance().config().ndkLocation) {
|
|
|
|
|
QRegExp versionRegExp(NDKGccVersionRegExp);
|
|
|
|
|
m_ndkLocation = AndroidConfigurations::instance().config().ndkLocation;
|
|
|
|
|
FileName path = m_ndkLocation;
|
|
|
|
|
QDirIterator it(path.appendPath(QLatin1String("toolchains")).toString(),
|
|
|
|
|
QStringList() << QLatin1String("*"), QDir::Dirs);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
const QString &fileName = QFileInfo(it.next()).fileName();
|
|
|
|
|
int idx = versionRegExp.indexIn(fileName);
|
|
|
|
|
if (idx == -1)
|
|
|
|
|
continue;
|
|
|
|
|
QList<int> version = versionNumberFromString(fileName.mid(idx + 1));
|
|
|
|
|
QString platform = fileName.left(idx);
|
|
|
|
|
Abi::Architecture arch = AndroidConfigurations::architectureForToolChainPrefix(platform);
|
|
|
|
|
if (arch == Abi::UnknownArchitecture) // e.g. mipsel which is not yet supported
|
|
|
|
|
continue;
|
|
|
|
|
QMap<Abi::Architecture, QList<int> >::const_iterator it
|
|
|
|
|
= m_newestVersionForArch.constFind(arch);
|
|
|
|
|
if (it == m_newestVersionForArch.constEnd())
|
|
|
|
|
m_newestVersionForArch.insert(arch, version);
|
|
|
|
|
else if (versionCompareLess(it.value(), version))
|
|
|
|
|
m_newestVersionForArch[arch] = version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return m_newestVersionForArch.value(arch);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 20:30:57 +03:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Android
|