forked from qt-creator/qt-creator
MsvcToolChain: Cache the environment modification
Introduce a cache storing the environment modification as a list of EnvironmentItem. This saves quite a few invocations of the vcvars.bat during loading projects, speeding it up. Change-Id: Ica27495fe96db4dd683e68746559701cc3e30428 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
@@ -499,30 +499,60 @@ static QString winExpandDelayedEnvReferences(QString in, const Utils::Environmen
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::Environment MsvcToolChain::readEnvironmentSetting(const Utils::Environment& env) const
|
QList<Utils::EnvironmentItem> MsvcToolChain::environmentModifications() const
|
||||||
{
|
{
|
||||||
Utils::Environment result;
|
const Utils::Environment inEnv = Utils::Environment::systemEnvironment();
|
||||||
|
Utils::Environment outEnv;
|
||||||
QMap<QString, QString> envPairs;
|
QMap<QString, QString> envPairs;
|
||||||
if (!generateEnvironmentSettings(env, m_vcvarsBat, m_varsBatArg, envPairs))
|
if (!generateEnvironmentSettings(inEnv, m_vcvarsBat, m_varsBatArg, envPairs))
|
||||||
return env;
|
return QList<Utils::EnvironmentItem>();
|
||||||
|
|
||||||
// Now loop through and process them
|
// Now loop through and process them
|
||||||
QMap<QString,QString>::const_iterator envIter;
|
for (auto envIter = envPairs.cbegin(), eend = envPairs.cend(); envIter != eend; ++envIter) {
|
||||||
for (envIter = envPairs.constBegin(); envIter!=envPairs.constEnd(); ++envIter) {
|
const QString expandedValue = winExpandDelayedEnvReferences(envIter.value(), inEnv);
|
||||||
const QString expandedValue = winExpandDelayedEnvReferences(envIter.value(), env);
|
|
||||||
if (!expandedValue.isEmpty())
|
if (!expandedValue.isEmpty())
|
||||||
result.set(envIter.key(), expandedValue);
|
outEnv.set(envIter.key(), expandedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
const QStringList newVars = result.toStringList();
|
const QStringList newVars = outEnv.toStringList();
|
||||||
const QStringList oldVars = env.toStringList();
|
const QStringList oldVars = inEnv.toStringList();
|
||||||
QDebug nsp = qDebug().nospace();
|
QDebug nsp = qDebug().nospace();
|
||||||
foreach (const QString &n, newVars) {
|
foreach (const QString &n, newVars) {
|
||||||
if (!oldVars.contains(n))
|
if (!oldVars.contains(n))
|
||||||
nsp << n << '\n';
|
nsp << n << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Utils::EnvironmentItem> diff = inEnv.diff(outEnv);
|
||||||
|
for (int i = diff.size() - 1; i >= 0; --i) {
|
||||||
|
if (diff.at(i).name.startsWith(QLatin1Char('='))) { // Exclude "=C:", "=EXITCODE"
|
||||||
|
diff.removeAt(i);
|
||||||
|
} else {
|
||||||
|
// Fix the append/prepend cases to "FOO=${FOO};newValue" (see Environment::modify)
|
||||||
|
Utils::EnvironmentItem &e = diff[i];
|
||||||
|
if (!e.unset) {
|
||||||
|
const auto oldIt = inEnv.constFind(e.name);
|
||||||
|
if (oldIt != inEnv.constEnd()) {
|
||||||
|
const int index = e.value.indexOf(oldIt.value());
|
||||||
|
if (index != -1) {
|
||||||
|
e.value.replace(index, oldIt.value().size(),
|
||||||
|
QStringLiteral("${") + e.name + QLatin1Char('}'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::Environment MsvcToolChain::readEnvironmentSetting(const Utils::Environment& env) const
|
||||||
|
{
|
||||||
|
if (m_environmentModifications.isEmpty())
|
||||||
|
m_environmentModifications = environmentModifications();
|
||||||
|
Utils::Environment result = env;
|
||||||
|
result.modify(m_environmentModifications);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -86,6 +86,10 @@ protected:
|
|||||||
const Utils::Environment &env) const override;
|
const Utils::Environment &env) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QList<Utils::EnvironmentItem> environmentModifications() const;
|
||||||
|
|
||||||
|
mutable QList<Utils::EnvironmentItem> m_environmentModifications;
|
||||||
|
|
||||||
QString m_varsBatArg; // Argument
|
QString m_varsBatArg; // Argument
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user