Commit dce41176 authored by Tobias Hunger's avatar Tobias Hunger

Qbs: Avoid useless reparsing when possible

Do not trigger a reparsing when e.g. changing environment variables
that qbs does not access.

Change-Id: Ieda4f68112d372c561d99c8dffe016af0d31ad41
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 57f12519
......@@ -103,9 +103,11 @@ QbsProject::QbsProject(QbsManager *manager, const QString &fileName) :
m_rootProjectNode(0),
m_qbsSetupProjectJob(0),
m_qbsUpdateFutureInterface(0),
m_currentProgressBase(0),
m_forceParsing(false),
m_currentBc(0)
{
m_parsingDelay.setInterval(1000); // delay (some) parsing by 1s.
m_parsingDelay.setInterval(1000); // delay parsing by 1s.
setProjectContext(Core::Context(Constants::PROJECT_ID));
setProjectLanguages(Core::Context(ProjectExplorer::Constants::LANG_CXX));
......@@ -310,8 +312,8 @@ void QbsProject::handleQbsParsingTaskSetup(const QString &description, int maxim
void QbsProject::targetWasAdded(ProjectExplorer::Target *t)
{
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(delayParsing()));
connect(t, SIGNAL(buildDirectoryChanged()), this, SLOT(delayParsing()));
this, SLOT(delayForcedParsing()));
connect(t, SIGNAL(buildDirectoryChanged()), this, SLOT(delayForcedParsing()));
}
void QbsProject::changeActiveTarget(ProjectExplorer::Target *t)
......@@ -341,6 +343,12 @@ void QbsProject::delayParsing()
m_parsingDelay.start();
}
void QbsProject::delayForcedParsing()
{
m_forceParsing = true;
delayParsing();
}
void QbsProject::parseCurrentBuildConfiguration()
{
m_parsingDelay.stop();
......@@ -383,12 +391,33 @@ void QbsProject::generateErrors(const qbs::Error &e)
void QbsProject::parse(const QVariantMap &config, const Utils::Environment &env, const QString &dir)
{
QTC_ASSERT(!dir.isNull(), return);
prepareForParsing();
QTC_ASSERT(!m_qbsSetupProjectJob, return);
qbs::SetupProjectParameters params;
params.setBuildConfiguration(config);
qbs::Error err = params.expandBuildConfiguration(m_manager->settings());
if (!err.entries().isEmpty()) {
generateErrors(err);
return;
}
// Avoid useless reparsing:
const qbs::Project *currentProject = qbsProject();
if (!m_forceParsing
&& currentProject
&& currentProject->projectConfiguration() == params.buildConfiguration()) {
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;
}
params.setBuildRoot(dir);
params.setProjectFilePath(m_fileName);
params.setIgnoreDifferentProjectFilePath(false);
......@@ -398,8 +427,12 @@ void QbsProject::parse(const QVariantMap &config, const Utils::Environment &env,
params.setSearchPaths(prefs->searchPaths(buildDir));
params.setPluginPaths(prefs->pluginPaths(buildDir));
// Do the parsing:
prepareForParsing();
QTC_ASSERT(!m_qbsSetupProjectJob, return);
m_qbsSetupProjectJob
= qbs::Project::setupProject(params, m_manager->settings(), m_manager->logSink(), 0);
= qbs::Project::setupProject(params, m_manager->logSink(), 0);
connect(m_qbsSetupProjectJob, SIGNAL(finished(bool,qbs::AbstractJob*)),
this, SLOT(handleQbsParsingDone(bool)));
......@@ -413,6 +446,8 @@ void QbsProject::parse(const QVariantMap &config, const Utils::Environment &env,
void QbsProject::prepareForParsing()
{
m_forceParsing = false;
taskHub()->clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
if (m_qbsUpdateFutureInterface)
m_qbsUpdateFutureInterface->reportCanceled();
......
......@@ -100,6 +100,7 @@ public slots:
void invalidate();
void parseCurrentBuildConfiguration();
void delayParsing();
void delayForcedParsing();
signals:
void projectParsingStarted();
......@@ -136,6 +137,7 @@ private:
QFutureInterface<void> *m_qbsUpdateFutureInterface;
int m_currentProgressBase;
bool m_forceParsing;
QFuture<void> m_codeModelFuture;
......
......@@ -96,7 +96,7 @@ bool QbsProjectFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty
Q_UNUSED(flag)
if (type == TypePermissions)
return true;
m_project->delayParsing();
m_project->delayForcedParsing();
return true;
}
......
Subproject commit f8b65305729e5806b14e25172a1ee5bc9f7df4ec
Subproject commit c1b431e5389eda2f6952077e917f3118f98a6dbd
Markdown is supported
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