forked from qt-creator/qt-creator
CMake: Fix usage of optionals in presets
Do not use optional for values that are not optional. The `hidden` properties of configure and build presets have defaults and are never unset. And also never checked for existence of a value. The same for `inheritConfigureEnvironment`. In that case the "value" in the optional was also never used, which isn't right. Change-Id: I3dd427bd4a2434de9d2c7b5f1f16ef78dd7d1277 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -1853,8 +1853,8 @@ void CMakeBuildConfiguration::setInitialBuildAndCleanSteps(const Target *target)
|
|||||||
enabled = CMakePresets::Macros::evaluatePresetCondition(
|
enabled = CMakePresets::Macros::evaluatePresetCondition(
|
||||||
preset, project->projectDirectory());
|
preset, project->projectDirectory());
|
||||||
|
|
||||||
return preset.configurePreset == presetName
|
return preset.configurePreset == presetName && !preset.hidden
|
||||||
&& !preset.hidden.value() && enabled;
|
&& enabled;
|
||||||
});
|
});
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
buildSteps = count;
|
buildSteps = count;
|
||||||
@@ -1885,7 +1885,7 @@ void CMakeBuildConfiguration::setBuildPresetToBuildSteps(const ProjectExplorer::
|
|||||||
enabled = CMakePresets::Macros::evaluatePresetCondition(preset,
|
enabled = CMakePresets::Macros::evaluatePresetCondition(preset,
|
||||||
project->projectDirectory());
|
project->projectDirectory());
|
||||||
|
|
||||||
return preset.configurePreset == presetName && !preset.hidden.value() && enabled;
|
return preset.configurePreset == presetName && !preset.hidden && enabled;
|
||||||
});
|
});
|
||||||
|
|
||||||
const QList<BuildStep *> buildStepList
|
const QList<BuildStep *> buildStepList
|
||||||
|
@@ -698,7 +698,7 @@ bool CMakeBuildSystem::addSrcFiles(Node *context, const FilePaths &filePaths, Fi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool haveGlobbing = isGlobbingFunction(cmakeListFile.value(), function.value());
|
const bool haveGlobbing = isGlobbingFunction(*cmakeListFile, *function);
|
||||||
n->setVisibleAfterAddFileAction(!haveGlobbing);
|
n->setVisibleAfterAddFileAction(!haveGlobbing);
|
||||||
if (haveGlobbing && settings(project()).autorunCMake()) {
|
if (haveGlobbing && settings(project()).autorunCMake()) {
|
||||||
runCMake();
|
runCMake();
|
||||||
@@ -804,7 +804,7 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
|
|||||||
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
||||||
} else {
|
} else {
|
||||||
// Check if the filename is part of globbing variable result
|
// Check if the filename is part of globbing variable result
|
||||||
const auto haveGlobbing = isGlobbingFunction(cmakeListFile.value(), func.value());
|
const auto haveGlobbing = isGlobbingFunction(*cmakeListFile, *func);
|
||||||
if (haveGlobbing) {
|
if (haveGlobbing) {
|
||||||
return ProjectFileArgumentPosition{filePathArgument,
|
return ProjectFileArgumentPosition{filePathArgument,
|
||||||
targetCMakeFile,
|
targetCMakeFile,
|
||||||
@@ -869,24 +869,24 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
|||||||
|
|
||||||
auto filePos = projectFileArgumentPosition(targetName, fileName);
|
auto filePos = projectFileArgumentPosition(targetName, fileName);
|
||||||
if (filePos) {
|
if (filePos) {
|
||||||
if (!filePos.value().cmakeFile.exists()) {
|
if (!filePos->cmakeFile.exists()) {
|
||||||
badFiles << file;
|
badFiles << file;
|
||||||
|
|
||||||
qCCritical(cmakeBuildSystemLog).noquote()
|
qCCritical(cmakeBuildSystemLog).noquote()
|
||||||
<< "File" << filePos.value().cmakeFile.path() << "does not exist.";
|
<< "File" << filePos->cmakeFile.path() << "does not exist.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filePos.value().fromGlobbing) {
|
if (filePos->fromGlobbing) {
|
||||||
haveGlobbing = true;
|
haveGlobbing = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
||||||
Core::EditorManager::openEditorAt(
|
Core::EditorManager::openEditorAt(
|
||||||
{filePos.value().cmakeFile,
|
{filePos->cmakeFile,
|
||||||
static_cast<int>(filePos.value().argumentPosition.Line),
|
static_cast<int>(filePos->argumentPosition.Line),
|
||||||
static_cast<int>(filePos.value().argumentPosition.Column - 1)},
|
static_cast<int>(filePos->argumentPosition.Column - 1)},
|
||||||
Constants::CMAKE_EDITOR_ID,
|
Constants::CMAKE_EDITOR_ID,
|
||||||
Core::EditorManager::DoNotMakeVisible
|
Core::EditorManager::DoNotMakeVisible
|
||||||
| Core::EditorManager::DoNotChangeCurrentEditor));
|
| Core::EditorManager::DoNotChangeCurrentEditor));
|
||||||
@@ -894,9 +894,9 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
|||||||
badFiles << file;
|
badFiles << file;
|
||||||
|
|
||||||
qCCritical(cmakeBuildSystemLog).noquote()
|
qCCritical(cmakeBuildSystemLog).noquote()
|
||||||
<< "BaseTextEditor cannot be obtained for"
|
<< "BaseTextEditor cannot be obtained for" << filePos->cmakeFile.path()
|
||||||
<< filePos.value().cmakeFile.path() << filePos.value().argumentPosition.Line
|
<< filePos->argumentPosition.Line
|
||||||
<< int(filePos.value().argumentPosition.Column - 1);
|
<< int(filePos->argumentPosition.Column - 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,15 +905,14 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
|||||||
if (filePos->argumentPosition.Delim == cmListFileArgument::Quoted)
|
if (filePos->argumentPosition.Delim == cmListFileArgument::Quoted)
|
||||||
extraChars = 2;
|
extraChars = 2;
|
||||||
|
|
||||||
editor->replace(filePos.value().relativeFileName.length() + extraChars, "");
|
editor->replace(filePos->relativeFileName.length() + extraChars, "");
|
||||||
|
|
||||||
editor->editorWidget()->autoIndent();
|
editor->editorWidget()->autoIndent();
|
||||||
if (!Core::DocumentManager::saveDocument(editor->document())) {
|
if (!Core::DocumentManager::saveDocument(editor->document())) {
|
||||||
badFiles << file;
|
badFiles << file;
|
||||||
|
|
||||||
qCCritical(cmakeBuildSystemLog).noquote()
|
qCCritical(cmakeBuildSystemLog).noquote()
|
||||||
<< "Changes to" << filePos.value().cmakeFile.path()
|
<< "Changes to" << filePos->cmakeFile.path() << "could not be saved.";
|
||||||
<< "could not be saved.";
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -959,7 +958,7 @@ bool CMakeBuildSystem::canRenameFile(Node *context,
|
|||||||
if (!filePos)
|
if (!filePos)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_filesToBeRenamed.insert(key, filePos.value());
|
m_filesToBeRenamed.insert(key, *filePos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@@ -320,7 +320,7 @@ void CMakeProject::readPresets()
|
|||||||
setupBuildPresets(m_presetsData);
|
setupBuildPresets(m_presetsData);
|
||||||
|
|
||||||
for (const auto &configPreset : m_presetsData.configurePresets) {
|
for (const auto &configPreset : m_presetsData.configurePresets) {
|
||||||
if (configPreset.hidden.value())
|
if (configPreset.hidden)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (configPreset.condition) {
|
if (configPreset.condition) {
|
||||||
|
@@ -193,7 +193,7 @@ FilePaths CMakeProjectImporter::presetCandidates()
|
|||||||
FilePaths candidates;
|
FilePaths candidates;
|
||||||
|
|
||||||
for (const auto &configPreset : m_project->presetsData().configurePresets) {
|
for (const auto &configPreset : m_project->presetsData().configurePresets) {
|
||||||
if (configPreset.hidden.value())
|
if (configPreset.hidden)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (configPreset.condition) {
|
if (configPreset.condition) {
|
||||||
|
@@ -91,7 +91,7 @@ public:
|
|||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
Utils::FilePath fileDir;
|
Utils::FilePath fileDir;
|
||||||
std::optional<bool> hidden = false;
|
bool hidden = false;
|
||||||
std::optional<QStringList> inherits;
|
std::optional<QStringList> inherits;
|
||||||
std::optional<Condition> condition;
|
std::optional<Condition> condition;
|
||||||
std::optional<QVariantMap> vendor;
|
std::optional<QVariantMap> vendor;
|
||||||
@@ -117,7 +117,7 @@ public:
|
|||||||
|
|
||||||
QString name;
|
QString name;
|
||||||
Utils::FilePath fileDir;
|
Utils::FilePath fileDir;
|
||||||
std::optional<bool> hidden = false;
|
bool hidden = false;
|
||||||
std::optional<QStringList> inherits;
|
std::optional<QStringList> inherits;
|
||||||
std::optional<Condition> condition;
|
std::optional<Condition> condition;
|
||||||
std::optional<QVariantMap> vendor;
|
std::optional<QVariantMap> vendor;
|
||||||
@@ -125,7 +125,7 @@ public:
|
|||||||
std::optional<QString> description;
|
std::optional<QString> description;
|
||||||
std::optional<Utils::Environment> environment;
|
std::optional<Utils::Environment> environment;
|
||||||
std::optional<QString> configurePreset;
|
std::optional<QString> configurePreset;
|
||||||
std::optional<bool> inheritConfigureEnvironment = true;
|
bool inheritConfigureEnvironment = true;
|
||||||
std::optional<int> jobs;
|
std::optional<int> jobs;
|
||||||
std::optional<QStringList> targets;
|
std::optional<QStringList> targets;
|
||||||
std::optional<QString> configuration;
|
std::optional<QString> configuration;
|
||||||
|
Reference in New Issue
Block a user