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(
|
||||
preset, project->projectDirectory());
|
||||
|
||||
return preset.configurePreset == presetName
|
||||
&& !preset.hidden.value() && enabled;
|
||||
return preset.configurePreset == presetName && !preset.hidden
|
||||
&& enabled;
|
||||
});
|
||||
if (count != 0)
|
||||
buildSteps = count;
|
||||
@@ -1885,7 +1885,7 @@ void CMakeBuildConfiguration::setBuildPresetToBuildSteps(const ProjectExplorer::
|
||||
enabled = CMakePresets::Macros::evaluatePresetCondition(preset,
|
||||
project->projectDirectory());
|
||||
|
||||
return preset.configurePreset == presetName && !preset.hidden.value() && enabled;
|
||||
return preset.configurePreset == presetName && !preset.hidden && enabled;
|
||||
});
|
||||
|
||||
const QList<BuildStep *> buildStepList
|
||||
|
@@ -698,7 +698,7 @@ bool CMakeBuildSystem::addSrcFiles(Node *context, const FilePaths &filePaths, Fi
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool haveGlobbing = isGlobbingFunction(cmakeListFile.value(), function.value());
|
||||
const bool haveGlobbing = isGlobbingFunction(*cmakeListFile, *function);
|
||||
n->setVisibleAfterAddFileAction(!haveGlobbing);
|
||||
if (haveGlobbing && settings(project()).autorunCMake()) {
|
||||
runCMake();
|
||||
@@ -804,7 +804,7 @@ CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const Q
|
||||
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
||||
} else {
|
||||
// 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) {
|
||||
return ProjectFileArgumentPosition{filePathArgument,
|
||||
targetCMakeFile,
|
||||
@@ -869,24 +869,24 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
||||
|
||||
auto filePos = projectFileArgumentPosition(targetName, fileName);
|
||||
if (filePos) {
|
||||
if (!filePos.value().cmakeFile.exists()) {
|
||||
if (!filePos->cmakeFile.exists()) {
|
||||
badFiles << file;
|
||||
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "File" << filePos.value().cmakeFile.path() << "does not exist.";
|
||||
<< "File" << filePos->cmakeFile.path() << "does not exist.";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filePos.value().fromGlobbing) {
|
||||
if (filePos->fromGlobbing) {
|
||||
haveGlobbing = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
||||
Core::EditorManager::openEditorAt(
|
||||
{filePos.value().cmakeFile,
|
||||
static_cast<int>(filePos.value().argumentPosition.Line),
|
||||
static_cast<int>(filePos.value().argumentPosition.Column - 1)},
|
||||
{filePos->cmakeFile,
|
||||
static_cast<int>(filePos->argumentPosition.Line),
|
||||
static_cast<int>(filePos->argumentPosition.Column - 1)},
|
||||
Constants::CMAKE_EDITOR_ID,
|
||||
Core::EditorManager::DoNotMakeVisible
|
||||
| Core::EditorManager::DoNotChangeCurrentEditor));
|
||||
@@ -894,9 +894,9 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
||||
badFiles << file;
|
||||
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "BaseTextEditor cannot be obtained for"
|
||||
<< filePos.value().cmakeFile.path() << filePos.value().argumentPosition.Line
|
||||
<< int(filePos.value().argumentPosition.Column - 1);
|
||||
<< "BaseTextEditor cannot be obtained for" << filePos->cmakeFile.path()
|
||||
<< filePos->argumentPosition.Line
|
||||
<< int(filePos->argumentPosition.Column - 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -905,15 +905,14 @@ RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
||||
if (filePos->argumentPosition.Delim == cmListFileArgument::Quoted)
|
||||
extraChars = 2;
|
||||
|
||||
editor->replace(filePos.value().relativeFileName.length() + extraChars, "");
|
||||
editor->replace(filePos->relativeFileName.length() + extraChars, "");
|
||||
|
||||
editor->editorWidget()->autoIndent();
|
||||
if (!Core::DocumentManager::saveDocument(editor->document())) {
|
||||
badFiles << file;
|
||||
|
||||
qCCritical(cmakeBuildSystemLog).noquote()
|
||||
<< "Changes to" << filePos.value().cmakeFile.path()
|
||||
<< "could not be saved.";
|
||||
<< "Changes to" << filePos->cmakeFile.path() << "could not be saved.";
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -959,7 +958,7 @@ bool CMakeBuildSystem::canRenameFile(Node *context,
|
||||
if (!filePos)
|
||||
return false;
|
||||
|
||||
m_filesToBeRenamed.insert(key, filePos.value());
|
||||
m_filesToBeRenamed.insert(key, *filePos);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -320,7 +320,7 @@ void CMakeProject::readPresets()
|
||||
setupBuildPresets(m_presetsData);
|
||||
|
||||
for (const auto &configPreset : m_presetsData.configurePresets) {
|
||||
if (configPreset.hidden.value())
|
||||
if (configPreset.hidden)
|
||||
continue;
|
||||
|
||||
if (configPreset.condition) {
|
||||
|
@@ -193,7 +193,7 @@ FilePaths CMakeProjectImporter::presetCandidates()
|
||||
FilePaths candidates;
|
||||
|
||||
for (const auto &configPreset : m_project->presetsData().configurePresets) {
|
||||
if (configPreset.hidden.value())
|
||||
if (configPreset.hidden)
|
||||
continue;
|
||||
|
||||
if (configPreset.condition) {
|
||||
|
@@ -91,7 +91,7 @@ public:
|
||||
|
||||
QString name;
|
||||
Utils::FilePath fileDir;
|
||||
std::optional<bool> hidden = false;
|
||||
bool hidden = false;
|
||||
std::optional<QStringList> inherits;
|
||||
std::optional<Condition> condition;
|
||||
std::optional<QVariantMap> vendor;
|
||||
@@ -117,7 +117,7 @@ public:
|
||||
|
||||
QString name;
|
||||
Utils::FilePath fileDir;
|
||||
std::optional<bool> hidden = false;
|
||||
bool hidden = false;
|
||||
std::optional<QStringList> inherits;
|
||||
std::optional<Condition> condition;
|
||||
std::optional<QVariantMap> vendor;
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
std::optional<QString> description;
|
||||
std::optional<Utils::Environment> environment;
|
||||
std::optional<QString> configurePreset;
|
||||
std::optional<bool> inheritConfigureEnvironment = true;
|
||||
bool inheritConfigureEnvironment = true;
|
||||
std::optional<int> jobs;
|
||||
std::optional<QStringList> targets;
|
||||
std::optional<QString> configuration;
|
||||
|
Reference in New Issue
Block a user