presets: Convert allowNoFiles to enum class

This improves readability at the call site when "yes" is desired.
This commit is contained in:
Tyler Yankee
2026-04-21 09:44:30 -04:00
parent 8476469b72
commit e75b62fd73
3 changed files with 17 additions and 8 deletions

View File

@@ -541,7 +541,8 @@ void QCMake::setUpEnvironment() const
void QCMake::loadPresets()
{
auto result = this->CMakePresetsGraph.ReadProjectPresets(
this->SourceDirectory.toStdString(), true);
this->SourceDirectory.toStdString(),
cmCMakePresetsGraph::ReadOption::AllowNoFiles);
if (!result) {
emit this->presetLoadError(
this->SourceDirectory,

View File

@@ -1142,12 +1142,12 @@ std::string cmCMakePresetsGraph::GetUserFilename(std::string const& sourceDir)
}
bool cmCMakePresetsGraph::ReadProjectPresets(std::string const& sourceDir,
bool allowNoFiles)
ReadOption readFilesOption)
{
this->SourceDir = cmSystemTools::CollapseFullPath(sourceDir);
this->ClearPresets();
if (!this->ReadProjectPresetsInternal(allowNoFiles)) {
if (!this->ReadProjectPresetsInternal(readFilesOption)) {
this->ClearPresets();
return false;
}
@@ -1183,7 +1183,8 @@ std::string cmCMakePresetsGraph::GetGeneratorForPreset(
return {};
}
bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
bool cmCMakePresetsGraph::ReadProjectPresetsInternal(
ReadOption readFilesOption)
{
bool haveOneFile = false;
@@ -1209,7 +1210,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
assert(inProgressFiles.empty());
if (!haveOneFile) {
if (allowNoFiles) {
if (readFilesOption == ReadOption::AllowNoFiles) {
return true;
}
cmCMakePresetsErrors::FILE_NOT_FOUND(filename, &this->parseState);

View File

@@ -453,8 +453,15 @@ public:
return preset.OriginFile->Version;
}
bool ReadProjectPresets(std::string const& sourceDir,
bool allowNoFiles = false);
enum class ReadOption
{
RequireFiles,
AllowNoFiles,
};
bool ReadProjectPresets(
std::string const& sourceDir,
ReadOption readFilesOption = ReadOption::RequireFiles);
std::string GetGeneratorForPreset(std::string const& presetName) const;
@@ -482,7 +489,7 @@ private:
Included,
};
bool ReadProjectPresetsInternal(bool allowNoFiles);
bool ReadProjectPresetsInternal(ReadOption readFilesOption);
bool ReadJSONFile(std::string const& filename, RootType rootType,
ReadReason readReason, std::vector<File*>& inProgressFiles,
File*& file, std::string& errMsg);