Commit 65dbd73a authored by hjk's avatar hjk
Browse files

Clean up QmakeProjectImporter



Mostly namespaces, an unused variable, ...

Change-Id: Ia2b879873eae7cb25f796f6bcf18b10bf3de1ff6
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 746882f5
......@@ -50,47 +50,49 @@
#include <QDir>
#include <QFileInfo>
#include <QStringList>
#include <QMessageBox>
#include <QStringList>
static const Core::Id QT_IS_TEMPORARY("Qmake.TempQt");
using namespace ProjectExplorer;
using namespace QtSupport;
using namespace Utils;
namespace QmakeProjectManager {
namespace Internal {
const Core::Id QT_IS_TEMPORARY("Qmake.TempQt");
QmakeProjectImporter::QmakeProjectImporter(const QString &path) :
ProjectExplorer::ProjectImporter(path)
ProjectImporter(path)
{ }
QList<ProjectExplorer::BuildInfo *> QmakeProjectImporter::import(const Utils::FileName &importPath,
bool silent)
QList<BuildInfo *> QmakeProjectImporter::import(const FileName &importPath, bool silent)
{
QList<ProjectExplorer::BuildInfo *> result;
QList<BuildInfo *> result;
QFileInfo fi = importPath.toFileInfo();
if (!fi.exists() && !fi.isDir())
return result;
QStringList makefiles = QDir(importPath.toString()).entryList(QStringList(QLatin1String("Makefile*")));
QtSupport::BaseQtVersion *version = 0;
BaseQtVersion *version = 0;
bool temporaryVersion = false;
foreach (const QString &file, makefiles) {
// find interesting makefiles
QString makefile = importPath.toString() + QLatin1Char('/') + file;
Utils::FileName qmakeBinary = QtSupport::QtVersionManager::findQMakeBinaryFromMakefile(makefile);
FileName qmakeBinary = QtVersionManager::findQMakeBinaryFromMakefile(makefile);
QFileInfo qmakeFi = qmakeBinary.toFileInfo();
Utils::FileName canonicalQmakeBinary = Utils::FileName::fromString(qmakeFi.canonicalFilePath());
FileName canonicalQmakeBinary = FileName::fromString(qmakeFi.canonicalFilePath());
if (canonicalQmakeBinary.isEmpty())
continue;
if (QtSupport::QtVersionManager::makefileIsFor(makefile, projectFilePath()) != QtSupport::QtVersionManager::SameProject)
if (QtVersionManager::makefileIsFor(makefile, projectFilePath()) != QtVersionManager::SameProject)
continue;
// Find version:
foreach (QtSupport::BaseQtVersion *v, QtSupport::QtVersionManager::versions()) {
foreach (BaseQtVersion *v, QtVersionManager::versions()) {
QFileInfo vfi = v->qmakeCommand().toFileInfo();
Utils::FileName current = Utils::FileName::fromString(vfi.canonicalFilePath());
FileName current = FileName::fromString(vfi.canonicalFilePath());
if (current == canonicalQmakeBinary) {
version = v;
break;
......@@ -100,48 +102,48 @@ QList<ProjectExplorer::BuildInfo *> QmakeProjectImporter::import(const Utils::Fi
if (version) {
// Check if version is a temporary qt
int qtId = version->uniqueId();
temporaryVersion = Utils::anyOf(ProjectExplorer::KitManager::kits(), [&qtId](ProjectExplorer::Kit *k){
temporaryVersion = Utils::anyOf(KitManager::kits(), [&qtId](Kit *k){
return k->value(QT_IS_TEMPORARY, -1).toInt() == qtId;
});
} else {
// Create a new version if not found:
// Do not use the canonical path here...
version = QtSupport::QtVersionFactory::createQtVersionFromQMakePath(qmakeBinary);
version = QtVersionFactory::createQtVersionFromQMakePath(qmakeBinary);
if (!version)
continue;
bool oldIsUpdating = setIsUpdating(true);
QtSupport::QtVersionManager::addVersion(version);
QtVersionManager::addVersion(version);
setIsUpdating(oldIsUpdating);
temporaryVersion = true;
}
// find qmake arguments and mkspec
QPair<QtSupport::BaseQtVersion::QmakeBuildConfigs, QString> makefileBuildConfig =
QtSupport::QtVersionManager::scanMakeFile(makefile, version->defaultBuildConfig());
QPair<BaseQtVersion::QmakeBuildConfigs, QString> makefileBuildConfig =
QtVersionManager::scanMakeFile(makefile, version->defaultBuildConfig());
QString additionalArguments = makefileBuildConfig.second;
Utils::FileName parsedSpec =
FileName parsedSpec =
QmakeBuildConfiguration::extractSpecFromArguments(&additionalArguments, importPath.toString(), version);
QStringList deducedArguments =
QmakeBuildConfiguration::extractDeducedArguments(&additionalArguments);
Utils::FileName versionSpec = version->mkspec();
if (parsedSpec.isEmpty() || parsedSpec == Utils::FileName::fromLatin1("default"))
FileName versionSpec = version->mkspec();
if (parsedSpec.isEmpty() || parsedSpec == FileName::fromLatin1("default"))
parsedSpec = versionSpec;
QString specArgument;
// Compare mkspecs and add to additional arguments
if (parsedSpec != versionSpec)
specArgument = QLatin1String("-spec ") + Utils::QtcProcess::quoteArg(parsedSpec.toUserOutput());
Utils::QtcProcess::addArgs(&specArgument, additionalArguments);
specArgument = QLatin1String("-spec ") + QtcProcess::quoteArg(parsedSpec.toUserOutput());
QtcProcess::addArgs(&specArgument, additionalArguments);
// Find kits (can be more than one, e.g. (Linux-)Desktop and embedded linux):
QList<ProjectExplorer::Kit *> kitList;
foreach (ProjectExplorer::Kit *k, ProjectExplorer::KitManager::kits()) {
QtSupport::BaseQtVersion *kitVersion = QtSupport::QtKitInformation::qtVersion(k);
Utils::FileName kitSpec = QmakeKitInformation::mkspec(k);
ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
QList<Kit *> kitList = KitManager::kits();
foreach (Kit *k, kitList) {
BaseQtVersion *kitVersion = QtKitInformation::qtVersion(k);
FileName kitSpec = QmakeKitInformation::mkspec(k);
ToolChain *tc = ToolChainKitInformation::toolChain(k);
if (kitSpec.isEmpty() && kitVersion)
kitSpec = kitVersion->mkspecFor(tc);
QStringList kitDeducedArguments;
......@@ -156,32 +158,31 @@ QList<ProjectExplorer::BuildInfo *> QmakeProjectImporter::import(const Utils::Fi
if (kitList.isEmpty())
kitList.append(createTemporaryKit(version, temporaryVersion, parsedSpec, deducedArguments));
foreach (ProjectExplorer::Kit *k, kitList) {
foreach (Kit *k, kitList) {
addProject(k);
QmakeBuildConfigurationFactory *factory
= qobject_cast<QmakeBuildConfigurationFactory *>(
ProjectExplorer::IBuildConfigurationFactory::find(k, projectFilePath()));
auto factory = qobject_cast<QmakeBuildConfigurationFactory *>(
IBuildConfigurationFactory::find(k, projectFilePath()));
if (!factory)
continue;
// create info:
QmakeBuildInfo *info = new QmakeBuildInfo(factory);
if (makefileBuildConfig.first & QtSupport::BaseQtVersion::DebugBuild) {
info->type = ProjectExplorer::BuildConfiguration::Debug;
if (makefileBuildConfig.first & BaseQtVersion::DebugBuild) {
info->type = BuildConfiguration::Debug;
info->displayName = QCoreApplication::translate("QmakeProjectManager::Internal::QmakeProjectImporter", "Debug");
} else {
info->type = ProjectExplorer::BuildConfiguration::Release;
info->type = BuildConfiguration::Release;
info->displayName = QCoreApplication::translate("QmakeProjectManager::Internal::QmakeProjectImporter", "Release");
}
info->kitId = k->id();
info->buildDirectory = Utils::FileName::fromString(fi.absoluteFilePath());
info->buildDirectory = FileName::fromString(fi.absoluteFilePath());
info->additionalArguments = additionalArguments;
info->makefile = makefile;
bool found = false;
foreach (ProjectExplorer::BuildInfo *bInfo, result) {
foreach (BuildInfo *bInfo, result) {
if (*static_cast<QmakeBuildInfo *>(bInfo) == *info) {
found = true;
break;
......@@ -203,7 +204,7 @@ QList<ProjectExplorer::BuildInfo *> QmakeProjectImporter::import(const Utils::Fi
return result;
}
QStringList QmakeProjectImporter::importCandidates(const Utils::FileName &projectPath)
QStringList QmakeProjectImporter::importCandidates(const FileName &projectPath)
{
QStringList candidates;
......@@ -211,8 +212,7 @@ QStringList QmakeProjectImporter::importCandidates(const Utils::FileName &projec
const QString prefix = pfi.baseName();
candidates << pfi.absolutePath();
QList<ProjectExplorer::Kit *> kitList = ProjectExplorer::KitManager::kits();
foreach (ProjectExplorer::Kit *k, kitList) {
foreach (Kit *k, KitManager::kits()) {
QFileInfo fi(QmakeBuildConfiguration::shadowBuildDirectory(projectPath.toString(), k, QString()));
const QString baseDir = fi.absolutePath();
......@@ -225,18 +225,18 @@ QStringList QmakeProjectImporter::importCandidates(const Utils::FileName &projec
return candidates;
}
ProjectExplorer::Target *QmakeProjectImporter::preferredTarget(const QList<ProjectExplorer::Target *> &possibleTargets)
Target *QmakeProjectImporter::preferredTarget(const QList<Target *> &possibleTargets)
{
// Select active target
// a) The default target
// b) Simulator target
// c) Desktop target
// d) the first target
ProjectExplorer::Target *activeTarget = possibleTargets.isEmpty() ? 0 : possibleTargets.at(0);
Target *activeTarget = possibleTargets.isEmpty() ? 0 : possibleTargets.at(0);
int activeTargetPriority = 0;
foreach (ProjectExplorer::Target *t, possibleTargets) {
QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(t->kit());
if (t->kit() == ProjectExplorer::KitManager::defaultKit()) {
foreach (Target *t, possibleTargets) {
BaseQtVersion *version = QtKitInformation::qtVersion(t->kit());
if (t->kit() == KitManager::defaultKit()) {
activeTarget = t;
activeTargetPriority = 3;
} else if (activeTargetPriority < 2 && version && version->type() == QLatin1String(QtSupport::Constants::SIMULATORQT)) {
......@@ -250,74 +250,72 @@ ProjectExplorer::Target *QmakeProjectImporter::preferredTarget(const QList<Proje
return activeTarget;
}
void QmakeProjectImporter::cleanupKit(ProjectExplorer::Kit *k)
void QmakeProjectImporter::cleanupKit(Kit *k)
{
QtSupport::BaseQtVersion *version = QtSupport::QtVersionManager::version(k->value(QT_IS_TEMPORARY, -1).toInt());
BaseQtVersion *version = QtVersionManager::version(k->value(QT_IS_TEMPORARY, -1).toInt());
if (!version)
return;
// count how many kits are using this version
int qtId = version->uniqueId();
int count = Utils::count(ProjectExplorer::KitManager::kits(), [qtId](ProjectExplorer::Kit *k) {
int users = Utils::count(KitManager::kits(), [qtId](Kit *k) {
return k->value(QT_IS_TEMPORARY, -1).toInt() == qtId;
});
if (count == 0) // Remove if no other kit is using it. (The Kit k is not in KitManager::kits()
QtSupport::QtVersionManager::removeVersion(version);
if (users == 0) // Remove if no other kit is using it. (The Kit k is not in KitManager::kits()
QtVersionManager::removeVersion(version);
}
void QmakeProjectImporter::makePermanent(ProjectExplorer::Kit *k)
void QmakeProjectImporter::makePermanent(Kit *k)
{
if (!isTemporaryKit(k))
return;
setIsUpdating(true);
int tempId = k->value(QT_IS_TEMPORARY, -1).toInt();
int qtId = QtSupport::QtKitInformation::qtVersionId(k);
int qtId = QtKitInformation::qtVersionId(k);
if (tempId != qtId) {
QtSupport::BaseQtVersion *version = QtSupport::QtVersionManager::version(tempId);
int count = Utils::count(ProjectExplorer::KitManager::kits(), [tempId](ProjectExplorer::Kit *k) {
BaseQtVersion *version = QtVersionManager::version(tempId);
int users = count(KitManager::kits(), [tempId](Kit *k) {
return k->value(QT_IS_TEMPORARY, -1).toInt() == tempId;
});
if (count == 0)
QtSupport::QtVersionManager::removeVersion(version);
if (users == 0)
QtVersionManager::removeVersion(version);
}
foreach (ProjectExplorer::Kit *kit, ProjectExplorer::KitManager::kits())
foreach (Kit *kit, KitManager::kits())
if (kit->value(QT_IS_TEMPORARY, -1).toInt() == tempId)
kit->removeKeySilently(QT_IS_TEMPORARY);
setIsUpdating(false);
ProjectImporter::makePermanent(k);
}
namespace {
ProjectExplorer::ToolChain *preferredToolChain(QtSupport::BaseQtVersion *qtVersion, const Utils::FileName &ms, const QStringList &deducedArguments)
static ToolChain *preferredToolChain(BaseQtVersion *qtVersion, const FileName &ms, const QStringList &deducedArguments)
{
const Utils::FileName spec = ms.isEmpty() ? qtVersion->mkspec() : ms;
const FileName spec = ms.isEmpty() ? qtVersion->mkspec() : ms;
QList<ProjectExplorer::ToolChain *> toolchains = ProjectExplorer::ToolChainManager::toolChains();
QList<ProjectExplorer::Abi> qtAbis = qtVersion->qtAbis();
return Utils::findOr(toolchains,
QList<ToolChain *> toolchains = ToolChainManager::toolChains();
QList<Abi> qtAbis = qtVersion->qtAbis();
return findOr(toolchains,
toolchains.isEmpty() ? 0 : toolchains.first(),
[&spec, &deducedArguments, &qtAbis](ProjectExplorer::ToolChain *tc) -> bool{
[&spec, &deducedArguments, &qtAbis](ToolChain *tc) -> bool{
return qtAbis.contains(tc->targetAbi())
&& tc->suggestedMkspecList().contains(spec)
&& QmakeBuildConfiguration::deduceArgumnetsForTargetAbi(tc->targetAbi(), 0) == deducedArguments;
});
}
}
ProjectExplorer::Kit *QmakeProjectImporter::createTemporaryKit(QtSupport::BaseQtVersion *version,
bool temporaryVersion,
const Utils::FileName &parsedSpec,
const QStringList &deducedQmakeArguments)
Kit *QmakeProjectImporter::createTemporaryKit(BaseQtVersion *version,
bool temporaryVersion,
const FileName &parsedSpec,
const QStringList &deducedQmakeArguments)
{
ProjectExplorer::Kit *k = new ProjectExplorer::Kit;
Kit *k = new Kit;
bool oldIsUpdating = setIsUpdating(true);
{
ProjectExplorer::KitGuard guard(k);
KitGuard guard(k);
QtSupport::QtKitInformation::setQtVersion(k, version);
ProjectExplorer::ToolChainKitInformation::setToolChain(k, preferredToolChain(version, parsedSpec, deducedQmakeArguments));
QtKitInformation::setQtVersion(k, version);
ToolChainKitInformation::setToolChain(k, preferredToolChain(version, parsedSpec, deducedQmakeArguments));
QmakeKitInformation::setMkspec(k, parsedSpec);
markTemporary(k);
......@@ -325,16 +323,15 @@ ProjectExplorer::Kit *QmakeProjectImporter::createTemporaryKit(QtSupport::BaseQt
k->setValue(QT_IS_TEMPORARY, version->uniqueId());
// Set up other values:
foreach (ProjectExplorer::KitInformation *ki, ProjectExplorer::KitManager::kitInformation()) {
if (ki->id() == ProjectExplorer::ToolChainKitInformation::id()
|| ki->id() == QtSupport::QtKitInformation::id())
foreach (KitInformation *ki, KitManager::kitInformation()) {
if (ki->id() == ToolChainKitInformation::id() || ki->id() == QtKitInformation::id())
continue;
ki->setup(k);
}
k->setUnexpandedDisplayName(version->displayName());;
} // ~KitGuard, sending kitUpdated
ProjectExplorer::KitManager::registerKit(k); // potentially adds kits to other targetsetuppages
KitManager::registerKit(k); // potentially adds kits to other targetsetuppages
setIsUpdating(oldIsUpdating);
return k;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment