CMake: Make cache clean detection better

Do clean the cache when necessary. The logic used to be wrong in that
it sometimes would just force a reparse where a cache clean was necessary.

Change-Id: Ice5e3bceaea83d4fd4d7c2ae6e21e76118e2d2c0
Reviewed-by: Vikas Pachdha <vikas.pachdha@theqtcompany.com>
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2016-04-08 14:16:20 +02:00
parent 8dadafb9e0
commit 118e42ecce

View File

@@ -607,6 +607,9 @@ void BuildDirManager::maybeForceReparse()
const QByteArray EXTRA_GENERATOR_KEY = "CMAKE_EXTRA_GENERATOR"; const QByteArray EXTRA_GENERATOR_KEY = "CMAKE_EXTRA_GENERATOR";
const QByteArray CMAKE_COMMAND_KEY = "CMAKE_COMMAND"; const QByteArray CMAKE_COMMAND_KEY = "CMAKE_COMMAND";
const QByteArrayList criticalKeys
= QByteArrayList() << GENERATOR_KEY << EXTRA_GENERATOR_KEY << CMAKE_COMMAND_KEY;
if (!m_hasData) { if (!m_hasData) {
forceReparse(); forceReparse();
return; return;
@@ -614,6 +617,8 @@ void BuildDirManager::maybeForceReparse()
const CMakeConfig currentConfig = parsedConfiguration(); const CMakeConfig currentConfig = parsedConfiguration();
const CMakeTool *tool = CMakeKitInformation::cmakeTool(kit());
QTC_ASSERT(tool, return); // No cmake... we should not have ended up here in the first place
const QString kitGenerator = CMakeGeneratorKitInformation::generator(kit()); const QString kitGenerator = CMakeGeneratorKitInformation::generator(kit());
int pos = kitGenerator.lastIndexOf(QLatin1String(" - ")); int pos = kitGenerator.lastIndexOf(QLatin1String(" - "));
const QString extraKitGenerator = (pos > 0) ? kitGenerator.left(pos) : QString(); const QString extraKitGenerator = (pos > 0) ? kitGenerator.left(pos) : QString();
@@ -624,36 +629,41 @@ void BuildDirManager::maybeForceReparse()
if (!extraKitGenerator.isEmpty()) if (!extraKitGenerator.isEmpty())
targetConfig.append(CMakeConfigItem(EXTRA_GENERATOR_KEY, CMakeConfigItem::INTERNAL, targetConfig.append(CMakeConfigItem(EXTRA_GENERATOR_KEY, CMakeConfigItem::INTERNAL,
QByteArray(), extraKitGenerator.toUtf8())); QByteArray(), extraKitGenerator.toUtf8()));
const CMakeTool *tool = CMakeKitInformation::cmakeTool(kit());
if (tool)
targetConfig.append(CMakeConfigItem(CMAKE_COMMAND_KEY, CMakeConfigItem::INTERNAL, targetConfig.append(CMakeConfigItem(CMAKE_COMMAND_KEY, CMakeConfigItem::INTERNAL,
QByteArray(), tool->cmakeExecutable().toUserOutput().toUtf8())); QByteArray(), tool->cmakeExecutable().toUserOutput().toUtf8()));
Utils::sort(targetConfig, CMakeConfigItem::sortOperator()); Utils::sort(targetConfig, CMakeConfigItem::sortOperator());
bool mustReparse = false;
auto ccit = currentConfig.constBegin(); auto ccit = currentConfig.constBegin();
auto kcit = targetConfig.constBegin(); auto kcit = targetConfig.constBegin();
while (ccit != currentConfig.constEnd() && kcit != targetConfig.constEnd()) { while (ccit != currentConfig.constEnd() && kcit != targetConfig.constEnd()) {
if (ccit->key == kcit->key) { if (ccit->key == kcit->key) {
if (ccit->value != kcit->value) if (ccit->value != kcit->value) {
break; if (criticalKeys.contains(kcit->key)) {
clearCache();
return;
}
mustReparse = true;
}
++ccit; ++ccit;
++kcit; ++kcit;
} else { } else {
if (ccit->key < kcit->key) if (ccit->key < kcit->key) {
++ccit; ++ccit;
else } else {
break; ++kcit;
mustReparse = true;
}
} }
} }
if (kcit != targetConfig.end()) { // If we have keys that do not exist yet, then reparse.
if (kcit->key == GENERATOR_KEY //
|| kcit->key == EXTRA_GENERATOR_KEY // The critical keys *must* be set in cmake configuration, so those were already
|| kcit->key == CMAKE_COMMAND_KEY) // handled above.
clearCache(); if (mustReparse || kcit != targetConfig.constEnd())
else
forceReparse(); forceReparse();
}
} }
} // namespace Internal } // namespace Internal