forked from qt-creator/qt-creator
Qbs: Factor parsing code out of QbsProject
Change-Id: I9b86baf964252e3d155cce533c79ca7a9dc9b315 Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
This commit is contained in:
committed by
Christian Kandeler
parent
a8304f3b42
commit
ce324b8d28
@@ -32,6 +32,7 @@
|
|||||||
#include "qbsbuildconfiguration.h"
|
#include "qbsbuildconfiguration.h"
|
||||||
#include "qbslogsink.h"
|
#include "qbslogsink.h"
|
||||||
#include "qbsprojectfile.h"
|
#include "qbsprojectfile.h"
|
||||||
|
#include "qbsprojectparser.h"
|
||||||
#include "qbsprojectmanagerconstants.h"
|
#include "qbsprojectmanagerconstants.h"
|
||||||
#include "qbsnodes.h"
|
#include "qbsnodes.h"
|
||||||
|
|
||||||
@@ -39,7 +40,6 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
@@ -98,9 +98,8 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
|
|||||||
m_projectName(QFileInfo(fileName).completeBaseName()),
|
m_projectName(QFileInfo(fileName).completeBaseName()),
|
||||||
m_fileName(fileName),
|
m_fileName(fileName),
|
||||||
m_rootProjectNode(0),
|
m_rootProjectNode(0),
|
||||||
m_qbsSetupProjectJob(0),
|
m_qbsProjectParser(0),
|
||||||
m_qbsUpdateFutureInterface(0),
|
m_qbsUpdateFutureInterface(0),
|
||||||
m_currentProgressBase(0),
|
|
||||||
m_forceParsing(false),
|
m_forceParsing(false),
|
||||||
m_currentBc(0)
|
m_currentBc(0)
|
||||||
{
|
{
|
||||||
@@ -127,11 +126,7 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
|
|||||||
QbsProject::~QbsProject()
|
QbsProject::~QbsProject()
|
||||||
{
|
{
|
||||||
m_codeModelFuture.cancel();
|
m_codeModelFuture.cancel();
|
||||||
if (m_qbsSetupProjectJob) {
|
delete m_qbsProjectParser;
|
||||||
m_qbsSetupProjectJob->disconnect(this);
|
|
||||||
m_qbsSetupProjectJob->cancel();
|
|
||||||
delete m_qbsSetupProjectJob;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deleting the root node triggers a few things, make sure rootProjectNode
|
// Deleting the root node triggers a few things, make sure rootProjectNode
|
||||||
// returns 0 already
|
// returns 0 already
|
||||||
@@ -279,22 +274,22 @@ bool QbsProject::needsSpecialDeployment() const
|
|||||||
|
|
||||||
void QbsProject::handleQbsParsingDone(bool success)
|
void QbsProject::handleQbsParsingDone(bool success)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_qbsSetupProjectJob, return);
|
QTC_ASSERT(m_qbsProjectParser, return);
|
||||||
QTC_ASSERT(m_qbsUpdateFutureInterface, return);
|
|
||||||
|
|
||||||
qbs::Project project;
|
qbs::Project project;
|
||||||
if (success) {
|
if (success)
|
||||||
project = m_qbsSetupProjectJob->project();
|
project = m_qbsProjectParser->qbsProject();
|
||||||
} else {
|
|
||||||
generateErrors(m_qbsSetupProjectJob->error());
|
|
||||||
m_qbsUpdateFutureInterface->reportCanceled();
|
|
||||||
}
|
|
||||||
m_qbsSetupProjectJob->deleteLater();
|
|
||||||
m_qbsSetupProjectJob = 0;
|
|
||||||
|
|
||||||
m_qbsUpdateFutureInterface->reportFinished();
|
generateErrors(m_qbsProjectParser->error());
|
||||||
delete m_qbsUpdateFutureInterface;
|
|
||||||
m_qbsUpdateFutureInterface = 0;
|
m_qbsProjectParser->deleteLater();
|
||||||
|
m_qbsProjectParser = 0;
|
||||||
|
|
||||||
|
if (m_qbsUpdateFutureInterface) {
|
||||||
|
m_qbsUpdateFutureInterface->reportFinished();
|
||||||
|
delete m_qbsUpdateFutureInterface;
|
||||||
|
m_qbsUpdateFutureInterface = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (project.isValid()) {
|
if (project.isValid()) {
|
||||||
// Do not throw away data when parsing errors were introduced. That frightens users:-)
|
// Do not throw away data when parsing errors were introduced. That frightens users:-)
|
||||||
@@ -315,21 +310,6 @@ void QbsProject::handleQbsParsingDone(bool success)
|
|||||||
emit projectParsingDone(success);
|
emit projectParsingDone(success);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QbsProject::handleQbsParsingProgress(int progress)
|
|
||||||
{
|
|
||||||
if (m_qbsUpdateFutureInterface)
|
|
||||||
m_qbsUpdateFutureInterface->setProgressValue(m_currentProgressBase + progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QbsProject::handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue)
|
|
||||||
{
|
|
||||||
Q_UNUSED(description);
|
|
||||||
if (m_qbsUpdateFutureInterface) {
|
|
||||||
m_currentProgressBase = m_qbsUpdateFutureInterface->progressValue();
|
|
||||||
m_qbsUpdateFutureInterface->setProgressRange(0, m_currentProgressBase + maximumProgressValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QbsProject::targetWasAdded(Target *t)
|
void QbsProject::targetWasAdded(Target *t)
|
||||||
{
|
{
|
||||||
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
||||||
@@ -383,8 +363,6 @@ void QbsProject::delayForcedParsing()
|
|||||||
|
|
||||||
void QbsProject::parseCurrentBuildConfiguration(bool force)
|
void QbsProject::parseCurrentBuildConfiguration(bool force)
|
||||||
{
|
{
|
||||||
m_parsingDelay.stop();
|
|
||||||
|
|
||||||
if (!m_forceParsing)
|
if (!m_forceParsing)
|
||||||
m_forceParsing = force;
|
m_forceParsing = force;
|
||||||
|
|
||||||
@@ -396,6 +374,25 @@ void QbsProject::parseCurrentBuildConfiguration(bool force)
|
|||||||
parse(bc->qbsConfiguration(), bc->environment(), bc->buildDirectory().toString());
|
parse(bc->qbsConfiguration(), bc->environment(), bc->buildDirectory().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QbsProject::registerQbsProjectParser(QbsProjectParser *p)
|
||||||
|
{
|
||||||
|
m_parsingDelay.stop();
|
||||||
|
|
||||||
|
if (m_qbsProjectParser) {
|
||||||
|
m_qbsProjectParser->disconnect(this);
|
||||||
|
m_qbsProjectParser->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_qbsProjectParser = p;
|
||||||
|
|
||||||
|
if (p) {
|
||||||
|
p->setForced(m_forceParsing);
|
||||||
|
connect(m_qbsProjectParser, SIGNAL(done(bool)), this, SLOT(handleQbsParsingDone(bool)));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_forceParsing = false;
|
||||||
|
}
|
||||||
|
|
||||||
bool QbsProject::fromMap(const QVariantMap &map)
|
bool QbsProject::fromMap(const QVariantMap &map)
|
||||||
{
|
{
|
||||||
if (!Project::fromMap(map))
|
if (!Project::fromMap(map))
|
||||||
@@ -425,75 +422,17 @@ void QbsProject::generateErrors(const qbs::ErrorInfo &e)
|
|||||||
|
|
||||||
void QbsProject::parse(const QVariantMap &config, const Environment &env, const QString &dir)
|
void QbsProject::parse(const QVariantMap &config, const Environment &env, const QString &dir)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!dir.isNull(), return);
|
|
||||||
|
|
||||||
qbs::SetupProjectParameters params;
|
|
||||||
QVariantMap baseConfig;
|
|
||||||
QVariantMap userConfig = config;
|
|
||||||
QString specialKey = QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY);
|
|
||||||
const QString profileName = userConfig.take(specialKey).toString();
|
|
||||||
baseConfig.insert(specialKey, profileName);
|
|
||||||
specialKey = QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY);
|
|
||||||
baseConfig.insert(specialKey, userConfig.take(specialKey));
|
|
||||||
params.setBuildConfiguration(baseConfig);
|
|
||||||
params.setOverriddenValues(userConfig);
|
|
||||||
qbs::ErrorInfo err = params.expandBuildConfiguration(QbsManager::settings());
|
|
||||||
if (err.hasError()) {
|
|
||||||
generateErrors(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avoid useless reparsing:
|
|
||||||
const qbs::Project ¤tProject = qbsProject();
|
|
||||||
if (!m_forceParsing
|
|
||||||
&& currentProject.isValid()
|
|
||||||
&& currentProject.projectConfiguration() == params.finalBuildConfigurationTree()) {
|
|
||||||
QHash<QString, QString> usedEnv = currentProject.usedEnvironment();
|
|
||||||
bool canSkip = true;
|
|
||||||
for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
|
|
||||||
i != usedEnv.constEnd(); ++i) {
|
|
||||||
if (env.value(i.key()) != i.value()) {
|
|
||||||
canSkip = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (canSkip)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some people don't like it when files are created as a side effect of opening a project,
|
|
||||||
// so do not store the build graph if the build directory does not exist yet.
|
|
||||||
params.setDryRun(!QFileInfo(dir).exists());
|
|
||||||
|
|
||||||
params.setBuildRoot(dir);
|
|
||||||
params.setProjectFilePath(m_fileName);
|
|
||||||
params.setIgnoreDifferentProjectFilePath(false);
|
|
||||||
params.setEnvironment(env.toProcessEnvironment());
|
|
||||||
const qbs::Preferences prefs(QbsManager::settings(), profileName);
|
|
||||||
params.setSearchPaths(prefs.searchPaths(resourcesBaseDirectory()));
|
|
||||||
params.setPluginPaths(prefs.pluginPaths(pluginsBaseDirectory()));
|
|
||||||
|
|
||||||
// Do the parsing:
|
|
||||||
prepareForParsing();
|
prepareForParsing();
|
||||||
QTC_ASSERT(!m_qbsSetupProjectJob, return);
|
QTC_ASSERT(!m_qbsProjectParser, return);
|
||||||
|
|
||||||
m_qbsSetupProjectJob
|
registerQbsProjectParser(new QbsProjectParser(this, m_qbsUpdateFutureInterface));
|
||||||
= qbs::Project::setupProject(params, QbsManager::logSink(), 0);
|
|
||||||
|
|
||||||
connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
|
if (m_qbsProjectParser->parse(config, env, dir))
|
||||||
this, SLOT(handleQbsParsingDone(bool)));
|
emit projectParsingStarted();
|
||||||
connect(m_qbsSetupProjectJob, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)),
|
|
||||||
this, SLOT(handleQbsParsingTaskSetup(QString,int)));
|
|
||||||
connect(m_qbsSetupProjectJob, SIGNAL(taskProgress(int,qbs::AbstractJob*)),
|
|
||||||
this, SLOT(handleQbsParsingProgress(int)));
|
|
||||||
|
|
||||||
emit projectParsingStarted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QbsProject::prepareForParsing()
|
void QbsProject::prepareForParsing()
|
||||||
{
|
{
|
||||||
m_forceParsing = false;
|
|
||||||
|
|
||||||
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
||||||
if (m_qbsUpdateFutureInterface) {
|
if (m_qbsUpdateFutureInterface) {
|
||||||
m_qbsUpdateFutureInterface->reportCanceled();
|
m_qbsUpdateFutureInterface->reportCanceled();
|
||||||
@@ -502,15 +441,7 @@ void QbsProject::prepareForParsing()
|
|||||||
delete m_qbsUpdateFutureInterface;
|
delete m_qbsUpdateFutureInterface;
|
||||||
m_qbsUpdateFutureInterface = 0;
|
m_qbsUpdateFutureInterface = 0;
|
||||||
|
|
||||||
if (m_qbsSetupProjectJob) {
|
m_qbsUpdateFutureInterface = new QFutureInterface<bool>();
|
||||||
m_qbsSetupProjectJob->disconnect(this);
|
|
||||||
m_qbsSetupProjectJob->cancel();
|
|
||||||
m_qbsSetupProjectJob->deleteLater();
|
|
||||||
m_qbsSetupProjectJob = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_currentProgressBase = 0;
|
|
||||||
m_qbsUpdateFutureInterface = new QFutureInterface<void>();
|
|
||||||
m_qbsUpdateFutureInterface->setProgressRange(0, 0);
|
m_qbsUpdateFutureInterface->setProgressRange(0, 0);
|
||||||
ProgressManager::addTask(m_qbsUpdateFutureInterface->future(),
|
ProgressManager::addTask(m_qbsUpdateFutureInterface->future(),
|
||||||
tr("Reading Project \"%1\"").arg(displayName()), "Qbs.QbsEvaluate");
|
tr("Reading Project \"%1\"").arg(displayName()), "Qbs.QbsEvaluate");
|
||||||
@@ -712,26 +643,5 @@ void QbsProject::updateDeploymentInfo(const qbs::Project &project)
|
|||||||
activeTarget()->setDeploymentData(deploymentData);
|
activeTarget()->setDeploymentData(deploymentData);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QbsProject::resourcesBaseDirectory() const
|
|
||||||
{
|
|
||||||
const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
|
|
||||||
if (!qbsInstallDir.isEmpty())
|
|
||||||
return qbsInstallDir;
|
|
||||||
return ICore::resourcePath() + QLatin1String("/qbs");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QbsProject::pluginsBaseDirectory() const
|
|
||||||
{
|
|
||||||
const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
|
|
||||||
if (!qbsInstallDir.isEmpty())
|
|
||||||
return qbsInstallDir + QLatin1String("/lib/");
|
|
||||||
if (Utils::HostOsInfo::isMacHost())
|
|
||||||
return QDir::cleanPath(QCoreApplication::applicationDirPath()
|
|
||||||
+ QLatin1String("/../PlugIns"));
|
|
||||||
else
|
|
||||||
return QDir::cleanPath(QCoreApplication::applicationDirPath()
|
|
||||||
+ QLatin1String("/../" IDE_LIBRARY_BASENAME "/qtcreator"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace QbsProjectManager
|
} // namespace QbsProjectManager
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ class BuildJob;
|
|||||||
class CleanJob;
|
class CleanJob;
|
||||||
class Error;
|
class Error;
|
||||||
class ProjectData;
|
class ProjectData;
|
||||||
class SetupProjectJob;
|
|
||||||
class CleanOptions;
|
class CleanOptions;
|
||||||
class InstallJob;
|
class InstallJob;
|
||||||
class InstallOptions;
|
class InstallOptions;
|
||||||
@@ -63,6 +62,7 @@ namespace QbsProjectManager {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QbsProjectNode;
|
class QbsProjectNode;
|
||||||
|
class QbsProjectParser;
|
||||||
class QbsBuildConfiguration;
|
class QbsBuildConfiguration;
|
||||||
|
|
||||||
class QbsProject : public ProjectExplorer::Project
|
class QbsProject : public ProjectExplorer::Project
|
||||||
@@ -92,6 +92,8 @@ public:
|
|||||||
bool hasParseResult() const;
|
bool hasParseResult() const;
|
||||||
void parseCurrentBuildConfiguration(bool force);
|
void parseCurrentBuildConfiguration(bool force);
|
||||||
|
|
||||||
|
void registerQbsProjectParser(QbsProjectParser *p);
|
||||||
|
|
||||||
static Utils::FileName defaultBuildDirectory(const QString &projectFilePath,
|
static Utils::FileName defaultBuildDirectory(const QString &projectFilePath,
|
||||||
const ProjectExplorer::Kit *k,
|
const ProjectExplorer::Kit *k,
|
||||||
const QString &bcName);
|
const QString &bcName);
|
||||||
@@ -100,6 +102,7 @@ public:
|
|||||||
const qbs::ProjectData qbsProjectData() const;
|
const qbs::ProjectData qbsProjectData() const;
|
||||||
|
|
||||||
bool needsSpecialDeployment() const;
|
bool needsSpecialDeployment() const;
|
||||||
|
void generateErrors(const qbs::ErrorInfo &e);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void invalidate();
|
void invalidate();
|
||||||
@@ -112,8 +115,6 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleQbsParsingDone(bool success);
|
void handleQbsParsingDone(bool success);
|
||||||
void handleQbsParsingProgress(int progress);
|
|
||||||
void handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue);
|
|
||||||
|
|
||||||
void targetWasAdded(ProjectExplorer::Target *t);
|
void targetWasAdded(ProjectExplorer::Target *t);
|
||||||
void changeActiveTarget(ProjectExplorer::Target *t);
|
void changeActiveTarget(ProjectExplorer::Target *t);
|
||||||
@@ -125,15 +126,12 @@ private:
|
|||||||
|
|
||||||
void parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir);
|
void parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir);
|
||||||
|
|
||||||
void generateErrors(const qbs::ErrorInfo &e);
|
|
||||||
void prepareForParsing();
|
void prepareForParsing();
|
||||||
void updateDocuments(const QSet<QString> &files);
|
void updateDocuments(const QSet<QString> &files);
|
||||||
void updateCppCodeModel(const qbs::ProjectData &prj);
|
void updateCppCodeModel(const qbs::ProjectData &prj);
|
||||||
void updateQmlJsCodeModel(const qbs::ProjectData &prj);
|
void updateQmlJsCodeModel(const qbs::ProjectData &prj);
|
||||||
void updateApplicationTargets(const qbs::ProjectData &projectData);
|
void updateApplicationTargets(const qbs::ProjectData &projectData);
|
||||||
void updateDeploymentInfo(const qbs::Project &project);
|
void updateDeploymentInfo(const qbs::Project &project);
|
||||||
QString resourcesBaseDirectory() const;
|
|
||||||
QString pluginsBaseDirectory() const;
|
|
||||||
|
|
||||||
QbsManager *const m_manager;
|
QbsManager *const m_manager;
|
||||||
const QString m_projectName;
|
const QString m_projectName;
|
||||||
@@ -141,10 +139,9 @@ private:
|
|||||||
QSet<Core::IDocument *> m_qbsDocuments;
|
QSet<Core::IDocument *> m_qbsDocuments;
|
||||||
QbsProjectNode *m_rootProjectNode;
|
QbsProjectNode *m_rootProjectNode;
|
||||||
|
|
||||||
qbs::SetupProjectJob *m_qbsSetupProjectJob;
|
QbsProjectParser *m_qbsProjectParser;
|
||||||
|
|
||||||
QFutureInterface<void> *m_qbsUpdateFutureInterface;
|
QFutureInterface<bool> *m_qbsUpdateFutureInterface;
|
||||||
int m_currentProgressBase;
|
|
||||||
bool m_forceParsing;
|
bool m_forceParsing;
|
||||||
|
|
||||||
QFuture<void> m_codeModelFuture;
|
QFuture<void> m_codeModelFuture;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ HEADERS = \
|
|||||||
qbsprojectmanager_global.h \
|
qbsprojectmanager_global.h \
|
||||||
qbsprojectmanagerconstants.h \
|
qbsprojectmanagerconstants.h \
|
||||||
qbsprojectmanagerplugin.h \
|
qbsprojectmanagerplugin.h \
|
||||||
|
qbsprojectparser.h \
|
||||||
qbspropertylineedit.h \
|
qbspropertylineedit.h \
|
||||||
qbsrunconfiguration.h \
|
qbsrunconfiguration.h \
|
||||||
qbsconstants.h
|
qbsconstants.h
|
||||||
@@ -55,6 +56,7 @@ SOURCES = \
|
|||||||
qbsprojectfile.cpp \
|
qbsprojectfile.cpp \
|
||||||
qbsprojectmanager.cpp \
|
qbsprojectmanager.cpp \
|
||||||
qbsprojectmanagerplugin.cpp \
|
qbsprojectmanagerplugin.cpp \
|
||||||
|
qbsprojectparser.cpp \
|
||||||
qbspropertylineedit.cpp \
|
qbspropertylineedit.cpp \
|
||||||
qbsrunconfiguration.cpp
|
qbsrunconfiguration.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ QtcPlugin {
|
|||||||
"qbsprojectmanagerconstants.h",
|
"qbsprojectmanagerconstants.h",
|
||||||
"qbsprojectmanagerplugin.cpp",
|
"qbsprojectmanagerplugin.cpp",
|
||||||
"qbsprojectmanagerplugin.h",
|
"qbsprojectmanagerplugin.h",
|
||||||
|
"qbsprojectparser.cpp",
|
||||||
|
"qbsprojectparser.h",
|
||||||
"qbspropertylineedit.cpp",
|
"qbspropertylineedit.cpp",
|
||||||
"qbspropertylineedit.h",
|
"qbspropertylineedit.h",
|
||||||
"qbsrunconfiguration.cpp",
|
"qbsrunconfiguration.cpp",
|
||||||
|
|||||||
200
src/plugins/qbsprojectmanager/qbsprojectparser.cpp
Normal file
200
src/plugins/qbsprojectmanager/qbsprojectparser.cpp
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** 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 "qbsprojectparser.h"
|
||||||
|
|
||||||
|
#include "qbslogsink.h"
|
||||||
|
#include "qbsproject.h"
|
||||||
|
#include "qbsprojectmanagerconstants.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
|
#include <qbs.h>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace QbsProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
// QbsProjectParser:
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
|
QbsProjectParser::QbsProjectParser(QbsProject *project, QFutureInterface<bool> *fi) :
|
||||||
|
m_qbsSetupProjectJob(0),
|
||||||
|
m_fi(fi),
|
||||||
|
m_currentProgressBase(0)
|
||||||
|
{
|
||||||
|
m_project = project->qbsProject();
|
||||||
|
m_projectFilePath = project->projectFilePath().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QbsProjectParser::~QbsProjectParser()
|
||||||
|
{
|
||||||
|
if (m_qbsSetupProjectJob) {
|
||||||
|
m_qbsSetupProjectJob->disconnect(this);
|
||||||
|
m_qbsSetupProjectJob->cancel();
|
||||||
|
m_qbsSetupProjectJob->deleteLater();
|
||||||
|
m_qbsSetupProjectJob = 0;
|
||||||
|
}
|
||||||
|
m_fi = 0; // we do not own m_fi, do not delete
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsProjectParser::setForced(bool f)
|
||||||
|
{
|
||||||
|
m_wasForced = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QbsProjectParser::parse(const QVariantMap &config, const Environment &env, const QString &dir)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(!m_qbsSetupProjectJob, return false);
|
||||||
|
QTC_ASSERT(!dir.isNull(), return false);
|
||||||
|
|
||||||
|
m_currentProgressBase = 0;
|
||||||
|
|
||||||
|
qbs::SetupProjectParameters params;
|
||||||
|
QVariantMap baseConfig;
|
||||||
|
QVariantMap userConfig = config;
|
||||||
|
QString specialKey = QLatin1String(Constants::QBS_CONFIG_PROFILE_KEY);
|
||||||
|
const QString profileName = userConfig.take(specialKey).toString();
|
||||||
|
baseConfig.insert(specialKey, profileName);
|
||||||
|
specialKey = QLatin1String(Constants::QBS_CONFIG_VARIANT_KEY);
|
||||||
|
baseConfig.insert(specialKey, userConfig.take(specialKey));
|
||||||
|
params.setBuildConfiguration(baseConfig);
|
||||||
|
params.setOverriddenValues(userConfig);
|
||||||
|
m_error = params.expandBuildConfiguration(QbsManager::settings());
|
||||||
|
if (m_error.hasError()) {
|
||||||
|
emit done(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avoid useless reparsing:
|
||||||
|
if (!m_wasForced
|
||||||
|
&& m_project.isValid()
|
||||||
|
&& m_project.projectConfiguration() == params.finalBuildConfigurationTree()) {
|
||||||
|
QHash<QString, QString> usedEnv = m_project.usedEnvironment();
|
||||||
|
for (QHash<QString, QString>::const_iterator i = usedEnv.constBegin();
|
||||||
|
i != usedEnv.constEnd(); ++i) {
|
||||||
|
if (env.value(i.key()) != i.value()) {
|
||||||
|
emit done(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some people don't like it when files are created as a side effect of opening a project,
|
||||||
|
// so do not store the build graph if the build directory does not exist yet.
|
||||||
|
params.setDryRun(!QFileInfo(dir).exists());
|
||||||
|
|
||||||
|
params.setBuildRoot(dir);
|
||||||
|
params.setProjectFilePath(m_projectFilePath);
|
||||||
|
params.setIgnoreDifferentProjectFilePath(false);
|
||||||
|
params.setEnvironment(env.toProcessEnvironment());
|
||||||
|
const qbs::Preferences prefs(QbsManager::settings(), profileName);
|
||||||
|
params.setSearchPaths(prefs.searchPaths(resourcesBaseDirectory()));
|
||||||
|
params.setPluginPaths(prefs.pluginPaths(pluginsBaseDirectory()));
|
||||||
|
|
||||||
|
m_qbsSetupProjectJob = qbs::Project::setupProject(params, QbsManager::logSink(), 0);
|
||||||
|
|
||||||
|
connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
|
||||||
|
this, SLOT(handleQbsParsingDone(bool)));
|
||||||
|
connect(m_qbsSetupProjectJob, SIGNAL(taskStarted(QString,int,qbs::AbstractJob*)),
|
||||||
|
this, SIGNAL(taskChanged(QString,int)));
|
||||||
|
connect(m_qbsSetupProjectJob, SIGNAL(taskProgress(int,qbs::AbstractJob*)),
|
||||||
|
this, SIGNAL(progress(int)));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
qbs::Project QbsProjectParser::qbsProject() const
|
||||||
|
{
|
||||||
|
return m_project;
|
||||||
|
}
|
||||||
|
|
||||||
|
qbs::ErrorInfo QbsProjectParser::error()
|
||||||
|
{
|
||||||
|
return m_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsProjectParser::handleQbsParsingDone(bool success)
|
||||||
|
{
|
||||||
|
QTC_ASSERT(m_qbsSetupProjectJob, return);
|
||||||
|
|
||||||
|
m_project = m_qbsSetupProjectJob->project();
|
||||||
|
m_error = m_qbsSetupProjectJob->error();
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
m_fi->reportCanceled();
|
||||||
|
|
||||||
|
emit done(success);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsProjectParser::handleQbsParsingProgress(int progress)
|
||||||
|
{
|
||||||
|
if (m_fi)
|
||||||
|
m_fi->setProgressValue(m_currentProgressBase + progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QbsProjectParser::handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue)
|
||||||
|
{
|
||||||
|
Q_UNUSED(description);
|
||||||
|
if (m_fi) {
|
||||||
|
m_currentProgressBase = m_fi->progressValue();
|
||||||
|
m_fi->setProgressRange(0, m_currentProgressBase + maximumProgressValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QbsProjectParser::resourcesBaseDirectory() const
|
||||||
|
{
|
||||||
|
const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
|
||||||
|
if (!qbsInstallDir.isEmpty())
|
||||||
|
return qbsInstallDir;
|
||||||
|
return Core::ICore::resourcePath() + QLatin1String("/qbs");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QbsProjectParser::pluginsBaseDirectory() const
|
||||||
|
{
|
||||||
|
const QString qbsInstallDir = QLatin1String(QBS_INSTALL_DIR);
|
||||||
|
if (!qbsInstallDir.isEmpty())
|
||||||
|
return qbsInstallDir + QLatin1String("/lib/");
|
||||||
|
if (Utils::HostOsInfo::isMacHost())
|
||||||
|
return QDir::cleanPath(QCoreApplication::applicationDirPath()
|
||||||
|
+ QLatin1String("/../PlugIns"));
|
||||||
|
else
|
||||||
|
return QDir::cleanPath(QCoreApplication::applicationDirPath()
|
||||||
|
+ QLatin1String("/../" IDE_LIBRARY_BASENAME "/qtcreator"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QbsProjectManager
|
||||||
86
src/plugins/qbsprojectmanager/qbsprojectparser.h
Normal file
86
src/plugins/qbsprojectmanager/qbsprojectparser.h
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt-project.org/legal
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QBSPROJECTPARSER_H
|
||||||
|
#define QBSPROJECTPARSER_H
|
||||||
|
|
||||||
|
#include <utils/environment.h>
|
||||||
|
|
||||||
|
#include <QFutureInterface>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <qbs.h>
|
||||||
|
|
||||||
|
namespace QbsProjectManager {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class QbsProject;
|
||||||
|
|
||||||
|
class QbsProjectParser : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
QbsProjectParser(QbsProjectManager::Internal::QbsProject *project,
|
||||||
|
QFutureInterface<bool> *fi);
|
||||||
|
~QbsProjectParser();
|
||||||
|
|
||||||
|
void setForced(bool);
|
||||||
|
|
||||||
|
bool parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir);
|
||||||
|
|
||||||
|
qbs::Project qbsProject() const;
|
||||||
|
qbs::ErrorInfo error();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void done(bool success);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handleQbsParsingDone(bool success);
|
||||||
|
void handleQbsParsingProgress(int progress);
|
||||||
|
void handleQbsParsingTaskSetup(const QString &description, int maximumProgressValue);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString pluginsBaseDirectory() const;
|
||||||
|
QString resourcesBaseDirectory() const;
|
||||||
|
|
||||||
|
bool m_wasForced;
|
||||||
|
QString m_projectFilePath;
|
||||||
|
qbs::SetupProjectJob *m_qbsSetupProjectJob;
|
||||||
|
qbs::ErrorInfo m_error;
|
||||||
|
qbs::Project m_project;
|
||||||
|
|
||||||
|
QFutureInterface<bool> *m_fi;
|
||||||
|
int m_currentProgressBase;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QbsProjectManager
|
||||||
|
|
||||||
|
#endif // QBSPROJECTPARSER_H
|
||||||
Reference in New Issue
Block a user