Qbs: Move environment cache from runconfiguration to project

Change-Id: I2a987e55cde133931bb4578506bb26666eece601
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-05-24 11:48:47 +02:00
parent d492d14a92
commit f8e21037e3
4 changed files with 17 additions and 17 deletions

View File

@@ -469,6 +469,7 @@ void QbsProject::updateAfterParse()
updateCppCodeModel(); updateCppCodeModel();
updateQmlJsCodeModel(); updateQmlJsCodeModel();
emit fileListChanged(); emit fileListChanged();
m_envCache.clear();
emit dataChanged(); emit dataChanged();
} }
@@ -652,6 +653,7 @@ void QbsProject::updateAfterBuild()
m_extraCompilersPending = false; m_extraCompilersPending = false;
updateCppCodeModel(); updateCppCodeModel();
} }
m_envCache.clear();
emit dataChanged(); emit dataChanged();
} }
@@ -1115,6 +1117,16 @@ void QbsProject::updateApplicationTargets()
bti.runEnvModifier = [targetFile, productData, this](Utils::Environment &env, bool usingLibraryPaths) { bti.runEnvModifier = [targetFile, productData, this](Utils::Environment &env, bool usingLibraryPaths) {
if (!qbsProject().isValid()) if (!qbsProject().isValid())
return; return;
const QString key = env.toStringList().join(QChar())
+ QbsProject::uniqueProductName(productData)
+ QString::number(usingLibraryPaths);
const auto it = m_envCache.constFind(key);
if (it != m_envCache.constEnd()) {
env = it.value();
return;
}
QProcessEnvironment procEnv = env.toProcessEnvironment(); QProcessEnvironment procEnv = env.toProcessEnvironment();
procEnv.insert(QLatin1String("QBS_RUN_FILE_PATH"), targetFile); procEnv.insert(QLatin1String("QBS_RUN_FILE_PATH"), targetFile);
QStringList setupRunEnvConfig; QStringList setupRunEnvConfig;
@@ -1133,6 +1145,8 @@ void QbsProject::updateApplicationTargets()
foreach (const QString &key, procEnv.keys()) foreach (const QString &key, procEnv.keys())
env.set(key, procEnv.value(key)); env.set(key, procEnv.value(key));
} }
m_envCache.insert(key, env);
}; };
applications.append(bti); applications.append(bti);

View File

@@ -164,6 +164,8 @@ private:
QTimer m_parsingDelay; QTimer m_parsingDelay;
QList<ProjectExplorer::ExtraCompiler *> m_extraCompilers; QList<ProjectExplorer::ExtraCompiler *> m_extraCompilers;
bool m_extraCompilersPending = false; bool m_extraCompilersPending = false;
QHash<QString, Utils::Environment> m_envCache;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -59,21 +59,9 @@ QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
envAspect->addModifier([this](Environment &env) { envAspect->addModifier([this](Environment &env) {
bool usingLibraryPaths = aspect<UseLibraryPathsAspect>()->value(); bool usingLibraryPaths = aspect<UseLibraryPathsAspect>()->value();
const auto key = qMakePair(env.toStringList(), usingLibraryPaths);
const auto it = m_envCache.constFind(key);
if (it != m_envCache.constEnd()) {
env = it.value();
return;
}
BuildTargetInfo bti = buildTargetInfo(); BuildTargetInfo bti = buildTargetInfo();
if (bti.runEnvModifier) { if (bti.runEnvModifier)
if (project()->isParsing() || BuildManager::isBuilding(this->target())) {
qCDebug(qbsPmLog) << "qbs project in flux, cannot modify environment";
return; // Intentionally skips the cache update below.
}
bti.runEnvModifier(env, usingLibraryPaths); bti.runEnvModifier(env, usingLibraryPaths);
}
m_envCache.insert(key, env);
}); });
addAspect<ExecutableAspect>(); addAspect<ExecutableAspect>();
@@ -108,7 +96,6 @@ QbsRunConfiguration::QbsRunConfiguration(Target *target, Core::Id id)
this, &QbsRunConfiguration::updateTargetInformation); this, &QbsRunConfiguration::updateTargetInformation);
auto qbsProject = static_cast<QbsProject *>(target->project()); auto qbsProject = static_cast<QbsProject *>(target->project());
connect(qbsProject, &QbsProject::dataChanged, this, [this] { m_envCache.clear(); });
connect(qbsProject, &Project::parsingFinished, connect(qbsProject, &Project::parsingFinished,
this, &QbsRunConfiguration::updateTargetInformation); this, &QbsRunConfiguration::updateTargetInformation);
} }

View File

@@ -48,9 +48,6 @@ private:
void doAdditionalSetup(const ProjectExplorer::RunConfigurationCreationInfo &rci) final; void doAdditionalSetup(const ProjectExplorer::RunConfigurationCreationInfo &rci) final;
void updateTargetInformation(); void updateTargetInformation();
using EnvCache = QHash<QPair<QStringList, bool>, Utils::Environment>;
mutable EnvCache m_envCache;
}; };
class QbsRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory class QbsRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory