123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- /****************************************************************************
- **
- ** Copyright (C) 2013 Jarek Pelczar <jpelczar@gmail.com>
- ** Copyright (C) 2014 Tomasz Olszak <olszak.tomasz@gmail.com>
- **
- ** 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 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.
- **
- ** GNU Lesser General Public License Usage
- ** 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
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ****************************************************************************/
- #include "tizendebug.h"
- #include "tizentoolchain.h"
- #include "tizenqtversion.h"
- #include "tizenconstants.h"
- #include "tizenconfigurations.h"
- #include <utils/hostosinfo.h>
- #include <projectexplorer/gcctoolchainfactories.h>
- #include <QDirIterator>
- #include <QProcess>
- namespace {
- const QLatin1String SDKGccVersionRegExp("-\\d[\\.\\d]+");
- const QLatin1String SDKGccVersionStrRegExp("-gcc-\\d[\\.\\d]+");
- const QLatin1String GBSGccArmArchRegExp("^arm.*");
- const QLatin1String GBSGccX86ArchRegExp("^i.86.*");
- }
- namespace Tizen {
- namespace Internal {
- namespace {
- const QLatin1String tizen_emulator_mkspec("devices/linux-g++-tizen-emulator");
- const QLatin1String tizen_mobile_mkspec("devices/linux-g++-tizen-mobile");
- const QLatin1String tizen_ivi_mkspec("devices/linux-g++-tizen-ivi");
- const QLatin1String tizen_mkspec("devices/linux-g++-tizen");
- }
- TizenGccToolChain::~TizenGccToolChain()
- {
- }
- QString TizenGccToolChain::type() const
- {
- return QLatin1String(Constants::TIZEN_TOOLCHAIN_GCC_TYPE);
- }
- QString TizenGccToolChain::typeDisplayName() const
- {
- return TizenToolChainFactory::tr("Tizen GCC");
- }
- bool TizenGccToolChain::isValid() const
- {
- return GccToolChain::isValid() &&
- targetAbi().isValid();
- }
- void TizenGccToolChain::addToEnvironment(Utils::Environment &env) const
- {
- GccToolChain::addToEnvironment(env);
- }
- bool TizenGccToolChain::operator ==(const ProjectExplorer::ToolChain & other) const
- {
- if(!GccToolChain::operator ==(other))
- return false;
- return true;
- }
- ProjectExplorer::ToolChainConfigWidget * TizenGccToolChain::configurationWidget()
- {
- return GccToolChain::configurationWidget();
- }
- Utils::FileName TizenGccToolChain::suggestedDebugger() const
- {
- return GccToolChain::suggestedDebugger();
- }
- QVariantMap TizenGccToolChain::toMap() const
- {
- QVariantMap vm = GccToolChain::toMap();
- return vm;
- }
- bool TizenGccToolChain::fromMap(const QVariantMap &data)
- {
- if(!GccToolChain::fromMap(data))
- return false;
- return isValid();
- }
- QString TizenGccToolChain::makeCommand(const Utils::Environment &environment) const
- {
- if(gbsBuildRoot().isEmpty())
- return GccToolChain::makeCommand(environment);
- else {
- Utils::FileName makeBinary = m_gbsBuildRoot;
- makeBinary.appendPath(QLatin1Literal("usr/bin/make-gbs-host"));
- return makeBinary.toString();
- }
- }
- QList<Utils::FileName> TizenGccToolChain::suggestedMkspecList() const
- {
- return QList<Utils::FileName>() << Utils::FileName::fromString(tizen_emulator_mkspec)
- << Utils::FileName::fromString(tizen_mobile_mkspec)
- << Utils::FileName::fromString(tizen_ivi_mkspec)
- << Utils::FileName::fromString(tizen_mkspec);
- }
- QList<ProjectExplorer::Abi> TizenGccToolChain::detectSupportedAbis() const
- {
- return QList<ProjectExplorer::Abi>() << targetAbi();
- }
- TizenGccToolChain::TizenGccToolChain() :
- GccToolChain(QLatin1String(Constants::TIZEN_TOOLCHAIN_ID), ManualDetection)
- {
- }
- TizenGccToolChain::TizenGccToolChain(const ProjectExplorer::Abi::Architecture arch, Detection detection, Utils::FileName gbsBuildRoot) :
- GccToolChain(QLatin1String(Constants::TIZEN_TOOLCHAIN_ID), detection), m_gbsBuildRoot(gbsBuildRoot)
- {
- qCDebug(QTC_TIZEN) << "Creating Tizen toolchain:" << gbsBuildRoot.toString();
- ProjectExplorer::Abi abi = ProjectExplorer::Abi(arch,
- ProjectExplorer::Abi::LinuxOS,
- ProjectExplorer::Abi::GenericLinuxFlavor,
- ProjectExplorer::Abi::ElfFormat,
- 32);
- setTargetAbi(abi);
- if (m_gbsBuildRoot.isEmpty())
- setDisplayName(QString::fromLatin1("Tizen GCC (%1)")
- .arg(ProjectExplorer::Abi::toString(abi.architecture())));
- else
- setDisplayName(QString::fromLatin1("Tizen GCC (%1) GBS")
- .arg(ProjectExplorer::Abi::toString(abi.architecture())));
- }
- TizenGccToolChain::TizenGccToolChain(const TizenGccToolChain& other) :
- GccToolChain(other)
- {
- }
- TizenToolChainFactory::TizenToolChainFactory()
- {
- }
- QString TizenToolChainFactory::displayName() const
- {
- return tr("Tizen GCC");
- }
- QList<ProjectExplorer::ToolChain *> TizenToolChainFactory::autoDetect()
- {
- return createToolChainsForSdk(TizenConfigurations::currentConfig().sdkLocation().toString());
- }
- bool TizenToolChainFactory::canRestore(const QVariantMap &data)
- {
- return idFromMap(data).startsWith(QLatin1String(Constants::TIZEN_TOOLCHAIN_ID) + QLatin1Char(':'));
- }
- ProjectExplorer::ToolChain *TizenToolChainFactory::restore(const QVariantMap &data)
- {
- TizenGccToolChain * tc = new TizenGccToolChain();
- if(tc->fromMap(data))
- return tc;
- delete tc;
- return NULL;
- }
- QList<ProjectExplorer::ToolChain *> TizenToolChainFactory::createToolChainsForSdk(const QString& sdkPath)
- {
- QList<ProjectExplorer::ToolChain *> result;
- if(sdkPath.isEmpty())
- return result;
- Utils::FileName path = Utils::FileName::fromString(sdkPath);
- QDirIterator it(path.appendPath(QLatin1String("tools")).toString(),
- QStringList() << QLatin1String("*gcc*"),
- QDir::Dirs);
- const QLatin1String bin_dir("bin");
- QRegExp versionRegExp(SDKGccVersionRegExp);
- QRegExp versionStrRegExp(SDKGccVersionStrRegExp);
- while(it.hasNext()) {
- it.next();
- Utils::FileName gccPath = Utils::FileName::fromString(it.filePath()).appendPath(bin_dir);
- QDirIterator gcc_paths(gccPath.toString(),
- QStringList() << QLatin1String("*gcc"),
- QDir::Files|QDir::Executable);
- if(gcc_paths.hasNext()) {
- gcc_paths.next();
- QString compilerAndVersionInfo = it.fileName();
- int idx = versionRegExp.indexIn(compilerAndVersionInfo);
- QString version = compilerAndVersionInfo.mid(idx + 1);
- idx = versionStrRegExp.indexIn(compilerAndVersionInfo);
- QString platform = compilerAndVersionInfo.left(idx);
- ProjectExplorer::Abi::Architecture abiArchitecture = TizenConfig::architectureForToolChainPrefix(platform);
- if (abiArchitecture == ProjectExplorer::Abi::UnknownArchitecture) // e.g. mipsel which is not yet supported
- continue;
- TizenGccToolChain *tc = new TizenGccToolChain(abiArchitecture, ProjectExplorer::ToolChain::AutoDetection);
- Utils::FileName compilerPath = Utils::FileName::fromString(gcc_paths.filePath());
- tc->setCompilerCommand(compilerPath);
- result.append(tc);
- qCDebug(QTC_TIZEN) << "Found " << ProjectExplorer::Abi::toString(abiArchitecture) << " compiler: " << compilerPath.toString();
- }
- }
- return result;
- }
- ProjectExplorer::ToolChain *TizenToolChainFactory::createToolChainForGbs(const QString &gbsBuildRoot)
- {
- qCDebug(QTC_TIZEN);
- ProjectExplorer::GccToolChain *result(0);
- if(gbsBuildRoot.isEmpty())
- return result;
- Utils::FileName compilerPath = Utils::FileName::fromString(gbsBuildRoot)
- .appendPath(QLatin1Literal("usr/bin/gcc"));
- QProcess compiler;
- compiler.setProgram(compilerPath.toString());
- compiler.setArguments(QStringList() << QLatin1Literal("-dumpmachine"));
- compiler.start();
- if (!compiler.waitForStarted()) {
- qWarning() << QStringLiteral("can't start %1 with -dumpmachine parameter:").arg(compilerPath.toString()) << compiler.readAll();
- return result;
- }
- if (!compiler.waitForFinished()) {
- qWarning() << QStringLiteral("%1 with -dumpmachine parameter timed out:").arg(compilerPath.toString()) << compiler.readAll();
- return result;
- }
- if (compiler.exitCode()) {
- qWarning() << QStringLiteral("%1 returned non 0 exit code:").arg(compilerPath.toString()) << compiler.readAll();
- return result;
- }
- QString dumpMachineVersion = QString::fromLatin1(compiler.readAll());
- qCDebug(QTC_TIZEN) << "dumpMachineVersion:" << dumpMachineVersion;
- QRegExp armVersionRegExp(GBSGccArmArchRegExp);
- QRegExp x86VersionRegExp(GBSGccX86ArchRegExp);
- ProjectExplorer::Abi::Architecture abiArchitecture = ProjectExplorer::Abi::UnknownArchitecture;
- if (armVersionRegExp.indexIn(dumpMachineVersion) != -1)
- abiArchitecture = ProjectExplorer::Abi::ArmArchitecture;
- else if (x86VersionRegExp.indexIn(dumpMachineVersion) != -1)
- abiArchitecture = ProjectExplorer::Abi::X86Architecture;
- qCDebug(QTC_TIZEN) << "Before creating tc";
- result = new TizenGccToolChain(abiArchitecture,
- ProjectExplorer::ToolChain::AutoDetection,
- Utils::FileName::fromString(gbsBuildRoot));
- result->setCompilerCommand(compilerPath);
- return result;
- }
- bool TizenToolChainFactory::canCreate()
- {
- return false;
- }
- ProjectExplorer::ToolChain * TizenToolChainFactory::create()
- {
- return new TizenGccToolChain();
- }
- } // namespace Internal
- } // namespace Tizen
|