Commit 118e42ec authored by Tobias Hunger's avatar Tobias Hunger

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: default avatarVikas Pachdha <vikas.pachdha@theqtcompany.com>
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 8dadafb9
......@@ -607,6 +607,9 @@ void BuildDirManager::maybeForceReparse()
const QByteArray EXTRA_GENERATOR_KEY = "CMAKE_EXTRA_GENERATOR";
const QByteArray CMAKE_COMMAND_KEY = "CMAKE_COMMAND";
const QByteArrayList criticalKeys
= QByteArrayList() << GENERATOR_KEY << EXTRA_GENERATOR_KEY << CMAKE_COMMAND_KEY;
if (!m_hasData) {
forceReparse();
return;
......@@ -614,6 +617,8 @@ void BuildDirManager::maybeForceReparse()
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());
int pos = kitGenerator.lastIndexOf(QLatin1String(" - "));
const QString extraKitGenerator = (pos > 0) ? kitGenerator.left(pos) : QString();
......@@ -623,37 +628,42 @@ void BuildDirManager::maybeForceReparse()
QByteArray(), mainKitGenerator.toUtf8()));
if (!extraKitGenerator.isEmpty())
targetConfig.append(CMakeConfigItem(EXTRA_GENERATOR_KEY, CMakeConfigItem::INTERNAL,
QByteArray(), extraKitGenerator.toUtf8()));
const CMakeTool *tool = CMakeKitInformation::cmakeTool(kit());
if (tool)
targetConfig.append(CMakeConfigItem(CMAKE_COMMAND_KEY, CMakeConfigItem::INTERNAL,
QByteArray(), tool->cmakeExecutable().toUserOutput().toUtf8()));
QByteArray(), extraKitGenerator.toUtf8()));
targetConfig.append(CMakeConfigItem(CMAKE_COMMAND_KEY, CMakeConfigItem::INTERNAL,
QByteArray(), tool->cmakeExecutable().toUserOutput().toUtf8()));
Utils::sort(targetConfig, CMakeConfigItem::sortOperator());
bool mustReparse = false;
auto ccit = currentConfig.constBegin();
auto kcit = targetConfig.constBegin();
while (ccit != currentConfig.constEnd() && kcit != targetConfig.constEnd()) {
if (ccit->key == kcit->key) {
if (ccit->value != kcit->value)
break;
if (ccit->value != kcit->value) {
if (criticalKeys.contains(kcit->key)) {
clearCache();
return;
}
mustReparse = true;
}
++ccit;
++kcit;
} else {
if (ccit->key < kcit->key)
if (ccit->key < kcit->key) {
++ccit;
else
break;
} else {
++kcit;
mustReparse = true;
}
}
}
if (kcit != targetConfig.end()) {
if (kcit->key == GENERATOR_KEY
|| kcit->key == EXTRA_GENERATOR_KEY
|| kcit->key == CMAKE_COMMAND_KEY)
clearCache();
else
forceReparse();
}
// If we have keys that do not exist yet, then reparse.
//
// The critical keys *must* be set in cmake configuration, so those were already
// handled above.
if (mustReparse || kcit != targetConfig.constEnd())
forceReparse();
}
} // namespace Internal
......
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