diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-02-02 15:50:21 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-08-31 14:18:01 (GMT) |
commit | b699610df4878a3a68cb91a0a698f77e120282d1 (patch) | |
tree | eb3072e5223385f2d1bb5a97f9443b321900168b /Source/cmCMakePresetsGraph.cxx | |
parent | 215b9148eb0841224496e55f993b9ad7da55101e (diff) | |
download | CMake-b699610df4878a3a68cb91a0a698f77e120282d1.zip CMake-b699610df4878a3a68cb91a0a698f77e120282d1.tar.gz CMake-b699610df4878a3a68cb91a0a698f77e120282d1.tar.bz2 |
cmCMakePresetsGraph: Add package presets
Diffstat (limited to 'Source/cmCMakePresetsGraph.cxx')
-rw-r--r-- | Source/cmCMakePresetsGraph.cxx | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/Source/cmCMakePresetsGraph.cxx b/Source/cmCMakePresetsGraph.cxx index c64c633..c168a45 100644 --- a/Source/cmCMakePresetsGraph.cxx +++ b/Source/cmCMakePresetsGraph.cxx @@ -43,6 +43,7 @@ using ReadFileResult = cmCMakePresetsGraph::ReadFileResult; using ConfigurePreset = cmCMakePresetsGraph::ConfigurePreset; using BuildPreset = cmCMakePresetsGraph::BuildPreset; using TestPreset = cmCMakePresetsGraph::TestPreset; +using PackagePreset = cmCMakePresetsGraph::PackagePreset; using ExpandMacroResult = cmCMakePresetsGraphInternal::ExpandMacroResult; using MacroExpander = cmCMakePresetsGraphInternal::MacroExpander; @@ -301,6 +302,28 @@ bool ExpandMacros(const cmCMakePresetsGraph& graph, const TestPreset& preset, return true; } +bool ExpandMacros(const cmCMakePresetsGraph& graph, + const PackagePreset& preset, + cm::optional<PackagePreset>& out, + const std::vector<MacroExpander>& macroExpanders) +{ + for (auto& variable : out->Variables) { + CHECK_EXPAND(out, variable.second, macroExpanders, + graph.GetVersion(preset)); + } + + CHECK_EXPAND(out, out->ConfigFile, macroExpanders, graph.GetVersion(preset)); + CHECK_EXPAND(out, out->PackageName, macroExpanders, + graph.GetVersion(preset)); + CHECK_EXPAND(out, out->PackageVersion, macroExpanders, + graph.GetVersion(preset)); + CHECK_EXPAND(out, out->PackageDirectory, macroExpanders, + graph.GetVersion(preset)); + CHECK_EXPAND(out, out->VendorName, macroExpanders, graph.GetVersion(preset)); + + return true; +} + template <class T> bool ExpandMacros(const cmCMakePresetsGraph& graph, const T& preset, cm::optional<T>& out) @@ -868,6 +891,44 @@ cmCMakePresetsGraph::TestPreset::VisitPresetAfterInherit(int /* version */) return ReadFileResult::READ_OK; } +cmCMakePresetsGraph::ReadFileResult +cmCMakePresetsGraph::PackagePreset::VisitPresetInherit( + const cmCMakePresetsGraph::Preset& parentPreset) +{ + auto& preset = *this; + const PackagePreset& parent = + static_cast<const PackagePreset&>(parentPreset); + + InheritString(preset.ConfigurePreset, parent.ConfigurePreset); + InheritOptionalValue(preset.InheritConfigureEnvironment, + parent.InheritConfigureEnvironment); + InheritVector(preset.Generators, parent.Generators); + InheritVector(preset.Configurations, parent.Configurations); + + for (auto const& v : parent.Variables) { + preset.Variables.insert(v); + } + + InheritOptionalValue(preset.DebugOutput, parent.DebugOutput); + InheritOptionalValue(preset.VerboseOutput, parent.VerboseOutput); + InheritString(preset.PackageName, parent.PackageName); + InheritString(preset.PackageVersion, parent.PackageVersion); + InheritString(preset.PackageDirectory, parent.PackageDirectory); + InheritString(preset.VendorName, parent.VendorName); + + return ReadFileResult::READ_OK; +} + +cmCMakePresetsGraph::ReadFileResult +cmCMakePresetsGraph::PackagePreset::VisitPresetAfterInherit(int /* version */) +{ + auto& preset = *this; + if (!preset.Hidden && preset.ConfigurePreset.empty()) { + return ReadFileResult::INVALID_PRESET; + } + return ReadFileResult::READ_OK; +} + std::string cmCMakePresetsGraph::GetFilename(const std::string& sourceDir) { return cmStrCat(sourceDir, "/CMakePresets.json"); @@ -930,6 +991,7 @@ cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles) CHECK_OK(ComputePresetInheritance(this->ConfigurePresets, *this)); CHECK_OK(ComputePresetInheritance(this->BuildPresets, *this)); CHECK_OK(ComputePresetInheritance(this->TestPresets, *this)); + CHECK_OK(ComputePresetInheritance(this->PackagePresets, *this)); for (auto& it : this->ConfigurePresets) { if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) { @@ -985,6 +1047,30 @@ cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles) } } + for (auto& it : this->PackagePresets) { + if (!it.second.Unexpanded.Hidden) { + const auto configurePreset = + this->ConfigurePresets.find(it.second.Unexpanded.ConfigurePreset); + if (configurePreset == this->ConfigurePresets.end()) { + return ReadFileResult::INVALID_CONFIGURE_PRESET; + } + if (!it.second.Unexpanded.OriginFile->ReachableFiles.count( + configurePreset->second.Unexpanded.OriginFile)) { + return ReadFileResult::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE; + } + + if (it.second.Unexpanded.InheritConfigureEnvironment.value_or(true)) { + it.second.Unexpanded.Environment.insert( + configurePreset->second.Unexpanded.Environment.begin(), + configurePreset->second.Unexpanded.Environment.end()); + } + } + + if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) { + return ReadFileResult::INVALID_MACRO_EXPANSION; + } + } + return ReadFileResult::READ_OK; } @@ -1028,6 +1114,8 @@ const char* cmCMakePresetsGraph::ResultToString(ReadFileResult result) case ReadFileResult::BUILD_TEST_PRESETS_UNSUPPORTED: return "File version must be 2 or higher for build and test preset " "support."; + case ReadFileResult::PACKAGE_PRESETS_UNSUPPORTED: + return "File version must be 5 or higher for package preset support"; case ReadFileResult::INCLUDE_UNSUPPORTED: return "File version must be 4 or higher for include support"; case ReadFileResult::INVALID_INCLUDE: @@ -1173,10 +1261,39 @@ void cmCMakePresetsGraph::PrintTestPresetList( } } +void cmCMakePresetsGraph::PrintPackagePresetList( + PrintPrecedingNewline* newline) const +{ + this->PrintPackagePresetList([](const PackagePreset&) { return true; }, + newline); +} + +void cmCMakePresetsGraph::PrintPackagePresetList( + const std::function<bool(const PackagePreset&)>& filter, + PrintPrecedingNewline* newline) const +{ + std::vector<const cmCMakePresetsGraph::Preset*> presets; + for (auto const& p : this->PackagePresetOrder) { + auto const& preset = this->PackagePresets.at(p); + if (!preset.Unexpanded.Hidden && preset.Expanded && + preset.Expanded->ConditionResult && filter(preset.Unexpanded)) { + presets.push_back( + static_cast<const cmCMakePresetsGraph::Preset*>(&preset.Unexpanded)); + } + } + + if (!presets.empty()) { + printPrecedingNewline(newline); + std::cout << "Available package presets:\n\n"; + cmCMakePresetsGraph::PrintPresets(presets); + } +} + void cmCMakePresetsGraph::PrintAllPresets() const { PrintPrecedingNewline newline = PrintPrecedingNewline::False; this->PrintConfigurePresetList(&newline); this->PrintBuildPresetList(&newline); this->PrintTestPresetList(&newline); + this->PrintPackagePresetList(&newline); } |