diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2021-12-21 22:12:51 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-01-07 00:46:41 (GMT) |
commit | a239f23a987a063852c8f29040ef4eaeaebf3b9c (patch) | |
tree | 1130ca42122ad547cd706803e8e48a3d35065eb5 /Source/cmCMakePresetsGraph.cxx | |
parent | 84d440caace3f65ef6ddd197098f8d83c0ecef70 (diff) | |
download | CMake-a239f23a987a063852c8f29040ef4eaeaebf3b9c.zip CMake-a239f23a987a063852c8f29040ef4eaeaebf3b9c.tar.gz CMake-a239f23a987a063852c8f29040ef4eaeaebf3b9c.tar.bz2 |
Refactor: Generalize file graph in CMakePresets
Before this refactoring, presets had a simple flag that marked them
as "user" or "not user", and checking the file graph of two files
was as simple as checking this flag. This only allowed for two files
in the graph. Generalize the code to allow for arbitrarily many files
in the graph.
Diffstat (limited to 'Source/cmCMakePresetsGraph.cxx')
-rw-r--r-- | Source/cmCMakePresetsGraph.cxx | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/Source/cmCMakePresetsGraph.cxx b/Source/cmCMakePresetsGraph.cxx index ebc243b..a8aad12 100644 --- a/Source/cmCMakePresetsGraph.cxx +++ b/Source/cmCMakePresetsGraph.cxx @@ -3,6 +3,7 @@ #include "cmCMakePresetsGraph.h" #include <algorithm> +#include <cassert> #include <cstdlib> #include <functional> #include <iostream> @@ -106,8 +107,8 @@ ReadFileResult VisitPreset( } auto& parentPreset = parent->second.Unexpanded; - if (!preset.User && parentPreset.User) { - return ReadFileResult::USER_PRESET_INHERITANCE; + if (!preset.OriginFile->ReachableFiles.count(parentPreset.OriginFile)) { + return ReadFileResult::PRESET_UNREACHABLE_FROM_FILE; } auto result = VisitPreset(parentPreset, presets, cycleStatus, graph); @@ -876,23 +877,28 @@ cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles) { bool haveOneFile = false; + File* file; std::string filename = GetUserFilename(this->SourceDir); + std::vector<File*> inProgressFiles; if (cmSystemTools::FileExists(filename)) { - auto result = this->ReadJSONFile(filename, true); + auto result = this->ReadJSONFile(filename, RootType::User, + ReadReason::Root, inProgressFiles, file); if (result != ReadFileResult::READ_OK) { return result; } haveOneFile = true; - } - - filename = GetFilename(this->SourceDir); - if (cmSystemTools::FileExists(filename)) { - auto result = this->ReadJSONFile(filename, false); - if (result != ReadFileResult::READ_OK) { - return result; + } else { + filename = GetFilename(this->SourceDir); + if (cmSystemTools::FileExists(filename)) { + auto result = this->ReadJSONFile( + filename, RootType::Project, ReadReason::Root, inProgressFiles, file); + if (result != ReadFileResult::READ_OK) { + return result; + } + haveOneFile = true; } - haveOneFile = true; } + assert(inProgressFiles.empty()); if (!haveOneFile) { return allowNoFiles ? ReadFileResult::READ_OK @@ -983,8 +989,8 @@ const char* cmCMakePresetsGraph::ResultToString(ReadFileResult result) return "Duplicate presets"; case ReadFileResult::CYCLIC_PRESET_INHERITANCE: return "Cyclic preset inheritance"; - case ReadFileResult::USER_PRESET_INHERITANCE: - return "Project preset inherits from user preset"; + case ReadFileResult::PRESET_UNREACHABLE_FROM_FILE: + return "Inherited preset is unreachable from preset's file"; case ReadFileResult::INVALID_MACRO_EXPANSION: return "Invalid macro expansion"; case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED: @@ -1002,6 +1008,8 @@ const char* cmCMakePresetsGraph::ResultToString(ReadFileResult result) case ReadFileResult::TOOLCHAIN_FILE_UNSUPPORTED: return "File version must be 3 or higher for toolchainFile preset " "support."; + case ReadFileResult::CYCLIC_INCLUDE: + return "Cyclic include among preset files"; } return "Unknown error"; @@ -1016,6 +1024,8 @@ void cmCMakePresetsGraph::ClearPresets() this->ConfigurePresetOrder.clear(); this->BuildPresetOrder.clear(); this->TestPresetOrder.clear(); + + this->Files.clear(); } void cmCMakePresetsGraph::PrintPresets( |