| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 |
- /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- file Copyright.txt or https://cmake.org/licensing for details. */
- #include "cmCMakePresetsGraph.h"
- #include <algorithm>
- #include <cassert>
- #include <cstdlib>
- #include <functional>
- #include <iostream>
- #include <iterator>
- #include <utility>
- #include <cm/string_view>
- #include "cmsys/RegularExpression.hxx"
- #include "cmCMakePresetsGraphInternal.h"
- #include "cmStringAlgorithms.h"
- #include "cmSystemTools.h"
- #define CHECK_EXPAND(out, field, expanders, version) \
- do { \
- switch (ExpandMacros(field, expanders, version)) { \
- case ExpandMacroResult::Error: \
- return false; \
- case ExpandMacroResult::Ignore: \
- out.reset(); \
- return true; \
- case ExpandMacroResult::Ok: \
- break; \
- } \
- } while (false)
- namespace {
- enum class CycleStatus
- {
- Unvisited,
- InProgress,
- Verified,
- };
- using ReadFileResult = cmCMakePresetsGraph::ReadFileResult;
- using ConfigurePreset = cmCMakePresetsGraph::ConfigurePreset;
- using BuildPreset = cmCMakePresetsGraph::BuildPreset;
- using TestPreset = cmCMakePresetsGraph::TestPreset;
- using PackagePreset = cmCMakePresetsGraph::PackagePreset;
- using WorkflowPreset = cmCMakePresetsGraph::WorkflowPreset;
- template <typename T>
- using PresetPair = cmCMakePresetsGraph::PresetPair<T>;
- using ExpandMacroResult = cmCMakePresetsGraphInternal::ExpandMacroResult;
- using MacroExpander = cmCMakePresetsGraphInternal::MacroExpander;
- void InheritString(std::string& child, const std::string& parent)
- {
- if (child.empty()) {
- child = parent;
- }
- }
- template <typename T>
- void InheritOptionalValue(cm::optional<T>& child,
- const cm::optional<T>& parent)
- {
- if (!child) {
- child = parent;
- }
- }
- template <typename T>
- void InheritVector(std::vector<T>& child, const std::vector<T>& parent)
- {
- if (child.empty()) {
- child = parent;
- }
- }
- /**
- * Check preset inheritance for cycles (using a DAG check algorithm) while
- * also bubbling up fields through the inheritance hierarchy, then verify
- * that each preset has the required fields, either directly or through
- * inheritance.
- */
- template <class T>
- ReadFileResult VisitPreset(
- T& preset,
- std::map<std::string, cmCMakePresetsGraph::PresetPair<T>>& presets,
- std::map<std::string, CycleStatus> cycleStatus,
- const cmCMakePresetsGraph& graph)
- {
- switch (cycleStatus[preset.Name]) {
- case CycleStatus::InProgress:
- return ReadFileResult::CYCLIC_PRESET_INHERITANCE;
- case CycleStatus::Verified:
- return ReadFileResult::READ_OK;
- default:
- break;
- }
- cycleStatus[preset.Name] = CycleStatus::InProgress;
- if (preset.Environment.count("") != 0) {
- return ReadFileResult::INVALID_PRESET;
- }
- CHECK_OK(preset.VisitPresetBeforeInherit());
- for (auto const& i : preset.Inherits) {
- auto parent = presets.find(i);
- if (parent == presets.end()) {
- return ReadFileResult::INVALID_PRESET;
- }
- auto& parentPreset = parent->second.Unexpanded;
- if (!preset.OriginFile->ReachableFiles.count(parentPreset.OriginFile)) {
- return ReadFileResult::INHERITED_PRESET_UNREACHABLE_FROM_FILE;
- }
- auto result = VisitPreset(parentPreset, presets, cycleStatus, graph);
- if (result != ReadFileResult::READ_OK) {
- return result;
- }
- CHECK_OK(preset.VisitPresetInherit(parentPreset));
- for (auto const& v : parentPreset.Environment) {
- preset.Environment.insert(v);
- }
- if (!preset.ConditionEvaluator) {
- preset.ConditionEvaluator = parentPreset.ConditionEvaluator;
- }
- }
- if (preset.ConditionEvaluator && preset.ConditionEvaluator->IsNull()) {
- preset.ConditionEvaluator.reset();
- }
- CHECK_OK(preset.VisitPresetAfterInherit(graph.GetVersion(preset)));
- cycleStatus[preset.Name] = CycleStatus::Verified;
- return ReadFileResult::READ_OK;
- }
- template <class T>
- ReadFileResult ComputePresetInheritance(
- std::map<std::string, cmCMakePresetsGraph::PresetPair<T>>& presets,
- const cmCMakePresetsGraph& graph)
- {
- std::map<std::string, CycleStatus> cycleStatus;
- for (auto const& it : presets) {
- cycleStatus[it.first] = CycleStatus::Unvisited;
- }
- for (auto& it : presets) {
- auto& preset = it.second.Unexpanded;
- auto result = VisitPreset<T>(preset, presets, cycleStatus, graph);
- if (result != ReadFileResult::READ_OK) {
- return result;
- }
- }
- return ReadFileResult::READ_OK;
- }
- constexpr const char* ValidPrefixes[] = {
- "",
- "env",
- "penv",
- "vendor",
- };
- bool PrefixesValidMacroNamespace(const std::string& str)
- {
- return std::any_of(
- std::begin(ValidPrefixes), std::end(ValidPrefixes),
- [&str](const char* prefix) -> bool { return cmHasPrefix(prefix, str); });
- }
- bool IsValidMacroNamespace(const std::string& str)
- {
- return std::any_of(
- std::begin(ValidPrefixes), std::end(ValidPrefixes),
- [&str](const char* prefix) -> bool { return str == prefix; });
- }
- ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
- const std::vector<MacroExpander>& macroExpanders,
- int version);
- ExpandMacroResult ExpandMacros(
- std::string& out, const std::vector<MacroExpander>& macroExpanders,
- int version);
- ExpandMacroResult ExpandMacro(std::string& out,
- const std::string& macroNamespace,
- const std::string& macroName,
- const std::vector<MacroExpander>& macroExpanders,
- int version);
- bool ExpandMacros(const cmCMakePresetsGraph& graph,
- const ConfigurePreset& preset,
- cm::optional<ConfigurePreset>& out,
- const std::vector<MacroExpander>& macroExpanders)
- {
- std::string binaryDir = preset.BinaryDir;
- CHECK_EXPAND(out, binaryDir, macroExpanders, graph.GetVersion(preset));
- if (!binaryDir.empty()) {
- if (!cmSystemTools::FileIsFullPath(binaryDir)) {
- binaryDir = cmStrCat(graph.SourceDir, '/', binaryDir);
- }
- out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir);
- cmSystemTools::ConvertToUnixSlashes(out->BinaryDir);
- }
- if (!preset.InstallDir.empty()) {
- std::string installDir = preset.InstallDir;
- CHECK_EXPAND(out, installDir, macroExpanders, graph.GetVersion(preset));
- if (!cmSystemTools::FileIsFullPath(installDir)) {
- installDir = cmStrCat(graph.SourceDir, '/', installDir);
- }
- out->InstallDir = cmSystemTools::CollapseFullPath(installDir);
- cmSystemTools::ConvertToUnixSlashes(out->InstallDir);
- }
- if (!preset.ToolchainFile.empty()) {
- std::string toolchain = preset.ToolchainFile;
- CHECK_EXPAND(out, toolchain, macroExpanders, graph.GetVersion(preset));
- out->ToolchainFile = toolchain;
- }
- for (auto& variable : out->CacheVariables) {
- if (variable.second) {
- CHECK_EXPAND(out, variable.second->Value, macroExpanders,
- graph.GetVersion(preset));
- }
- }
- return true;
- }
- bool ExpandMacros(const cmCMakePresetsGraph& graph, const BuildPreset& preset,
- cm::optional<BuildPreset>& out,
- const std::vector<MacroExpander>& macroExpanders)
- {
- for (auto& target : out->Targets) {
- CHECK_EXPAND(out, target, macroExpanders, graph.GetVersion(preset));
- }
- for (auto& nativeToolOption : out->NativeToolOptions) {
- CHECK_EXPAND(out, nativeToolOption, macroExpanders,
- graph.GetVersion(preset));
- }
- return true;
- }
- bool ExpandMacros(const cmCMakePresetsGraph& graph, const TestPreset& preset,
- cm::optional<TestPreset>& out,
- const std::vector<MacroExpander>& macroExpanders)
- {
- for (auto& overwrite : out->OverwriteConfigurationFile) {
- CHECK_EXPAND(out, overwrite, macroExpanders, graph.GetVersion(preset));
- }
- if (out->Output) {
- CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders,
- graph.GetVersion(preset));
- CHECK_EXPAND(out, out->Output->OutputJUnitFile, macroExpanders,
- graph.GetVersion(preset));
- }
- if (out->Filter) {
- if (out->Filter->Include) {
- CHECK_EXPAND(out, out->Filter->Include->Name, macroExpanders,
- graph.GetVersion(preset));
- CHECK_EXPAND(out, out->Filter->Include->Label, macroExpanders,
- graph.GetVersion(preset));
- if (out->Filter->Include->Index) {
- CHECK_EXPAND(out, out->Filter->Include->Index->IndexFile,
- macroExpanders, graph.GetVersion(preset));
- }
- }
- if (out->Filter->Exclude) {
- CHECK_EXPAND(out, out->Filter->Exclude->Name, macroExpanders,
- graph.GetVersion(preset));
- CHECK_EXPAND(out, out->Filter->Exclude->Label, macroExpanders,
- graph.GetVersion(preset));
- if (out->Filter->Exclude->Fixtures) {
- CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Any, macroExpanders,
- graph.GetVersion(preset));
- CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Setup,
- macroExpanders, graph.GetVersion(preset));
- CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Cleanup,
- macroExpanders, graph.GetVersion(preset));
- }
- }
- }
- if (out->Execution) {
- CHECK_EXPAND(out, out->Execution->ResourceSpecFile, macroExpanders,
- graph.GetVersion(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;
- }
- bool ExpandMacros(const cmCMakePresetsGraph& /*graph*/,
- const WorkflowPreset& /*preset*/,
- cm::optional<WorkflowPreset>& /*out*/,
- const std::vector<MacroExpander>& /*macroExpanders*/)
- {
- return true;
- }
- template <class T>
- bool ExpandMacros(const cmCMakePresetsGraph& graph, const T& preset,
- cm::optional<T>& out)
- {
- out.emplace(preset);
- std::map<std::string, CycleStatus> envCycles;
- for (auto const& v : out->Environment) {
- envCycles[v.first] = CycleStatus::Unvisited;
- }
- std::vector<MacroExpander> macroExpanders;
- MacroExpander defaultMacroExpander =
- [&graph, &preset](const std::string& macroNamespace,
- const std::string& macroName, std::string& macroOut,
- int version) -> ExpandMacroResult {
- if (macroNamespace.empty()) {
- if (macroName == "sourceDir") {
- macroOut += graph.SourceDir;
- return ExpandMacroResult::Ok;
- }
- if (macroName == "sourceParentDir") {
- macroOut += cmSystemTools::GetParentDirectory(graph.SourceDir);
- return ExpandMacroResult::Ok;
- }
- if (macroName == "sourceDirName") {
- macroOut += cmSystemTools::GetFilenameName(graph.SourceDir);
- return ExpandMacroResult::Ok;
- }
- if (macroName == "presetName") {
- macroOut += preset.Name;
- return ExpandMacroResult::Ok;
- }
- if (macroName == "generator") {
- // Generator only makes sense if preset is not hidden.
- if (!preset.Hidden) {
- macroOut += graph.GetGeneratorForPreset(preset.Name);
- }
- return ExpandMacroResult::Ok;
- }
- if (macroName == "dollar") {
- macroOut += '$';
- return ExpandMacroResult::Ok;
- }
- if (macroName == "hostSystemName") {
- if (version < 3) {
- return ExpandMacroResult::Error;
- }
- macroOut += cmSystemTools::GetSystemName();
- return ExpandMacroResult::Ok;
- }
- if (macroName == "fileDir") {
- if (version < 4) {
- return ExpandMacroResult::Error;
- }
- macroOut +=
- cmSystemTools::GetParentDirectory(preset.OriginFile->Filename);
- return ExpandMacroResult::Ok;
- }
- if (macroName == "pathListSep") {
- if (version < 5) {
- return ExpandMacroResult::Error;
- }
- macroOut += cmSystemTools::GetSystemPathlistSeparator();
- return ExpandMacroResult::Ok;
- }
- }
- return ExpandMacroResult::Ignore;
- };
- MacroExpander environmentMacroExpander =
- [¯oExpanders, &out, &envCycles](
- const std::string& macroNamespace, const std::string& macroName,
- std::string& result, int version) -> ExpandMacroResult {
- if (macroNamespace == "env" && !macroName.empty() && out) {
- auto v = out->Environment.find(macroName);
- if (v != out->Environment.end() && v->second) {
- auto e =
- VisitEnv(*v->second, envCycles[macroName], macroExpanders, version);
- if (e != ExpandMacroResult::Ok) {
- return e;
- }
- result += *v->second;
- return ExpandMacroResult::Ok;
- }
- }
- if (macroNamespace == "env" || macroNamespace == "penv") {
- if (macroName.empty()) {
- return ExpandMacroResult::Error;
- }
- const char* value = std::getenv(macroName.c_str());
- if (value) {
- result += value;
- }
- return ExpandMacroResult::Ok;
- }
- return ExpandMacroResult::Ignore;
- };
- macroExpanders.push_back(defaultMacroExpander);
- macroExpanders.push_back(environmentMacroExpander);
- for (auto& v : out->Environment) {
- if (v.second) {
- switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders,
- graph.GetVersion(preset))) {
- case ExpandMacroResult::Error:
- return false;
- case ExpandMacroResult::Ignore:
- out.reset();
- return true;
- case ExpandMacroResult::Ok:
- break;
- }
- }
- }
- if (preset.ConditionEvaluator) {
- cm::optional<bool> result;
- if (!preset.ConditionEvaluator->Evaluate(
- macroExpanders, graph.GetVersion(preset), result)) {
- return false;
- }
- if (!result) {
- out.reset();
- return true;
- }
- out->ConditionResult = *result;
- }
- return ExpandMacros(graph, preset, out, macroExpanders);
- }
- ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
- const std::vector<MacroExpander>& macroExpanders,
- int version)
- {
- if (status == CycleStatus::Verified) {
- return ExpandMacroResult::Ok;
- }
- if (status == CycleStatus::InProgress) {
- return ExpandMacroResult::Error;
- }
- status = CycleStatus::InProgress;
- auto e = ExpandMacros(value, macroExpanders, version);
- if (e != ExpandMacroResult::Ok) {
- return e;
- }
- status = CycleStatus::Verified;
- return ExpandMacroResult::Ok;
- }
- ExpandMacroResult ExpandMacros(
- std::string& out, const std::vector<MacroExpander>& macroExpanders,
- int version)
- {
- std::string result;
- std::string macroNamespace;
- std::string macroName;
- enum class State
- {
- Default,
- MacroNamespace,
- MacroName,
- } state = State::Default;
- for (auto c : out) {
- switch (state) {
- case State::Default:
- if (c == '$') {
- state = State::MacroNamespace;
- } else {
- result += c;
- }
- break;
- case State::MacroNamespace:
- if (c == '{') {
- if (IsValidMacroNamespace(macroNamespace)) {
- state = State::MacroName;
- } else {
- result += '$';
- result += macroNamespace;
- result += '{';
- macroNamespace.clear();
- state = State::Default;
- }
- } else {
- macroNamespace += c;
- if (!PrefixesValidMacroNamespace(macroNamespace)) {
- result += '$';
- result += macroNamespace;
- macroNamespace.clear();
- state = State::Default;
- }
- }
- break;
- case State::MacroName:
- if (c == '}') {
- auto e = ExpandMacro(result, macroNamespace, macroName,
- macroExpanders, version);
- if (e != ExpandMacroResult::Ok) {
- return e;
- }
- macroNamespace.clear();
- macroName.clear();
- state = State::Default;
- } else {
- macroName += c;
- }
- break;
- }
- }
- switch (state) {
- case State::Default:
- break;
- case State::MacroNamespace:
- result += '$';
- result += macroNamespace;
- break;
- case State::MacroName:
- return ExpandMacroResult::Error;
- }
- out = std::move(result);
- return ExpandMacroResult::Ok;
- }
- ExpandMacroResult ExpandMacro(std::string& out,
- const std::string& macroNamespace,
- const std::string& macroName,
- const std::vector<MacroExpander>& macroExpanders,
- int version)
- {
- for (auto const& macroExpander : macroExpanders) {
- auto result = macroExpander(macroNamespace, macroName, out, version);
- if (result != ExpandMacroResult::Ignore) {
- return result;
- }
- }
- if (macroNamespace == "vendor") {
- return ExpandMacroResult::Ignore;
- }
- return ExpandMacroResult::Error;
- }
- template <typename T>
- ReadFileResult SetupWorkflowConfigurePreset(
- const T& preset, const ConfigurePreset*& configurePreset)
- {
- if (preset.ConfigurePreset != configurePreset->Name) {
- return ReadFileResult::INVALID_WORKFLOW_STEPS;
- }
- return ReadFileResult::READ_OK;
- }
- template <>
- ReadFileResult SetupWorkflowConfigurePreset<ConfigurePreset>(
- const ConfigurePreset& preset, const ConfigurePreset*& configurePreset)
- {
- configurePreset = &preset;
- return ReadFileResult::READ_OK;
- }
- template <typename T>
- ReadFileResult TryReachPresetFromWorkflow(
- const WorkflowPreset& origin,
- const std::map<std::string, PresetPair<T>>& presets, const std::string& name,
- const ConfigurePreset*& configurePreset)
- {
- auto it = presets.find(name);
- if (it == presets.end()) {
- return ReadFileResult::INVALID_WORKFLOW_STEPS;
- }
- if (!origin.OriginFile->ReachableFiles.count(
- it->second.Unexpanded.OriginFile)) {
- return ReadFileResult::WORKFLOW_STEP_UNREACHABLE_FROM_FILE;
- }
- return SetupWorkflowConfigurePreset<T>(it->second.Unexpanded,
- configurePreset);
- }
- }
- bool cmCMakePresetsGraphInternal::EqualsCondition::Evaluate(
- const std::vector<MacroExpander>& expanders, int version,
- cm::optional<bool>& out) const
- {
- std::string lhs = this->Lhs;
- CHECK_EXPAND(out, lhs, expanders, version);
- std::string rhs = this->Rhs;
- CHECK_EXPAND(out, rhs, expanders, version);
- out = (lhs == rhs);
- return true;
- }
- bool cmCMakePresetsGraphInternal::InListCondition::Evaluate(
- const std::vector<MacroExpander>& expanders, int version,
- cm::optional<bool>& out) const
- {
- std::string str = this->String;
- CHECK_EXPAND(out, str, expanders, version);
- for (auto item : this->List) {
- CHECK_EXPAND(out, item, expanders, version);
- if (str == item) {
- out = true;
- return true;
- }
- }
- out = false;
- return true;
- }
- bool cmCMakePresetsGraphInternal::MatchesCondition::Evaluate(
- const std::vector<MacroExpander>& expanders, int version,
- cm::optional<bool>& out) const
- {
- std::string str = this->String;
- CHECK_EXPAND(out, str, expanders, version);
- std::string regexStr = this->Regex;
- CHECK_EXPAND(out, regexStr, expanders, version);
- cmsys::RegularExpression regex;
- if (!regex.compile(regexStr)) {
- return false;
- }
- out = regex.find(str);
- return true;
- }
- bool cmCMakePresetsGraphInternal::AnyAllOfCondition::Evaluate(
- const std::vector<MacroExpander>& expanders, int version,
- cm::optional<bool>& out) const
- {
- for (auto const& condition : this->Conditions) {
- cm::optional<bool> result;
- if (!condition->Evaluate(expanders, version, result)) {
- out.reset();
- return false;
- }
- if (!result) {
- out.reset();
- return true;
- }
- if (result == this->StopValue) {
- out = result;
- return true;
- }
- }
- out = !this->StopValue;
- return true;
- }
- bool cmCMakePresetsGraphInternal::NotCondition::Evaluate(
- const std::vector<MacroExpander>& expanders, int version,
- cm::optional<bool>& out) const
- {
- out.reset();
- if (!this->SubCondition->Evaluate(expanders, version, out)) {
- out.reset();
- return false;
- }
- if (out) {
- *out = !*out;
- }
- return true;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::ConfigurePreset::VisitPresetInherit(
- const cmCMakePresetsGraph::Preset& parentPreset)
- {
- auto& preset = *this;
- const ConfigurePreset& parent =
- static_cast<const ConfigurePreset&>(parentPreset);
- InheritString(preset.Generator, parent.Generator);
- InheritString(preset.Architecture, parent.Architecture);
- InheritString(preset.Toolset, parent.Toolset);
- if (!preset.ArchitectureStrategy) {
- preset.ArchitectureStrategy = parent.ArchitectureStrategy;
- }
- if (!preset.ToolsetStrategy) {
- preset.ToolsetStrategy = parent.ToolsetStrategy;
- }
- InheritString(preset.BinaryDir, parent.BinaryDir);
- InheritString(preset.InstallDir, parent.InstallDir);
- InheritString(preset.ToolchainFile, parent.ToolchainFile);
- InheritOptionalValue(preset.WarnDev, parent.WarnDev);
- InheritOptionalValue(preset.ErrorDev, parent.ErrorDev);
- InheritOptionalValue(preset.WarnDeprecated, parent.WarnDeprecated);
- InheritOptionalValue(preset.ErrorDeprecated, parent.ErrorDeprecated);
- InheritOptionalValue(preset.WarnUninitialized, parent.WarnUninitialized);
- InheritOptionalValue(preset.WarnUnusedCli, parent.WarnUnusedCli);
- InheritOptionalValue(preset.WarnSystemVars, parent.WarnSystemVars);
- for (auto const& v : parent.CacheVariables) {
- preset.CacheVariables.insert(v);
- }
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::ConfigurePreset::VisitPresetBeforeInherit()
- {
- auto& preset = *this;
- if (preset.Environment.count("") != 0) {
- return ReadFileResult::INVALID_PRESET;
- }
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::ConfigurePreset::VisitPresetAfterInherit(int version)
- {
- auto& preset = *this;
- if (!preset.Hidden) {
- if (version < 3) {
- if (preset.Generator.empty()) {
- return ReadFileResult::INVALID_PRESET;
- }
- if (preset.BinaryDir.empty()) {
- return ReadFileResult::INVALID_PRESET;
- }
- }
- if (preset.WarnDev == false && preset.ErrorDev == true) {
- return ReadFileResult::INVALID_PRESET;
- }
- if (preset.WarnDeprecated == false && preset.ErrorDeprecated == true) {
- return ReadFileResult::INVALID_PRESET;
- }
- if (preset.CacheVariables.count("") != 0) {
- return ReadFileResult::INVALID_PRESET;
- }
- }
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::BuildPreset::VisitPresetInherit(
- const cmCMakePresetsGraph::Preset& parentPreset)
- {
- auto& preset = *this;
- const BuildPreset& parent = static_cast<const BuildPreset&>(parentPreset);
- InheritString(preset.ConfigurePreset, parent.ConfigurePreset);
- InheritOptionalValue(preset.InheritConfigureEnvironment,
- parent.InheritConfigureEnvironment);
- InheritOptionalValue(preset.Jobs, parent.Jobs);
- InheritVector(preset.Targets, parent.Targets);
- InheritString(preset.Configuration, parent.Configuration);
- InheritOptionalValue(preset.CleanFirst, parent.CleanFirst);
- InheritOptionalValue(preset.Verbose, parent.Verbose);
- InheritVector(preset.NativeToolOptions, parent.NativeToolOptions);
- if (!preset.ResolvePackageReferences) {
- preset.ResolvePackageReferences = parent.ResolvePackageReferences;
- }
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::BuildPreset::VisitPresetAfterInherit(int /* version */)
- {
- auto& preset = *this;
- if (!preset.Hidden && preset.ConfigurePreset.empty()) {
- return ReadFileResult::INVALID_PRESET;
- }
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::TestPreset::VisitPresetInherit(
- const cmCMakePresetsGraph::Preset& parentPreset)
- {
- auto& preset = *this;
- const TestPreset& parent = static_cast<const TestPreset&>(parentPreset);
- InheritString(preset.ConfigurePreset, parent.ConfigurePreset);
- InheritOptionalValue(preset.InheritConfigureEnvironment,
- parent.InheritConfigureEnvironment);
- InheritString(preset.Configuration, parent.Configuration);
- InheritVector(preset.OverwriteConfigurationFile,
- parent.OverwriteConfigurationFile);
- if (parent.Output) {
- if (preset.Output) {
- auto& output = preset.Output.value();
- const auto& parentOutput = parent.Output.value();
- InheritOptionalValue(output.ShortProgress, parentOutput.ShortProgress);
- InheritOptionalValue(output.Verbosity, parentOutput.Verbosity);
- InheritOptionalValue(output.Debug, parentOutput.Debug);
- InheritOptionalValue(output.OutputOnFailure,
- parentOutput.OutputOnFailure);
- InheritOptionalValue(output.Quiet, parentOutput.Quiet);
- InheritString(output.OutputLogFile, parentOutput.OutputLogFile);
- InheritString(output.OutputJUnitFile, parentOutput.OutputJUnitFile);
- InheritOptionalValue(output.LabelSummary, parentOutput.LabelSummary);
- InheritOptionalValue(output.SubprojectSummary,
- parentOutput.SubprojectSummary);
- InheritOptionalValue(output.MaxPassedTestOutputSize,
- parentOutput.MaxPassedTestOutputSize);
- InheritOptionalValue(output.MaxFailedTestOutputSize,
- parentOutput.MaxFailedTestOutputSize);
- InheritOptionalValue(output.TestOutputTruncation,
- parentOutput.TestOutputTruncation);
- InheritOptionalValue(output.MaxTestNameWidth,
- parentOutput.MaxTestNameWidth);
- } else {
- preset.Output = parent.Output;
- }
- }
- if (parent.Filter) {
- if (parent.Filter->Include) {
- if (preset.Filter && preset.Filter->Include) {
- auto& include = *preset.Filter->Include;
- const auto& parentInclude = *parent.Filter->Include;
- InheritString(include.Name, parentInclude.Name);
- InheritString(include.Label, parentInclude.Label);
- InheritOptionalValue(include.Index, parentInclude.Index);
- } else {
- if (!preset.Filter) {
- preset.Filter.emplace();
- }
- preset.Filter->Include = parent.Filter->Include;
- }
- }
- if (parent.Filter->Exclude) {
- if (preset.Filter && preset.Filter->Exclude) {
- auto& exclude = *preset.Filter->Exclude;
- const auto& parentExclude = *parent.Filter->Exclude;
- InheritString(exclude.Name, parentExclude.Name);
- InheritString(exclude.Label, parentExclude.Label);
- InheritOptionalValue(exclude.Fixtures, parentExclude.Fixtures);
- } else {
- if (!preset.Filter) {
- preset.Filter.emplace();
- }
- preset.Filter->Exclude = parent.Filter->Exclude;
- }
- }
- }
- if (parent.Execution) {
- if (preset.Execution) {
- auto& execution = *preset.Execution;
- const auto& parentExecution = *parent.Execution;
- InheritOptionalValue(execution.StopOnFailure,
- parentExecution.StopOnFailure);
- InheritOptionalValue(execution.EnableFailover,
- parentExecution.EnableFailover);
- InheritOptionalValue(execution.Jobs, parentExecution.Jobs);
- InheritString(execution.ResourceSpecFile,
- parentExecution.ResourceSpecFile);
- InheritOptionalValue(execution.TestLoad, parentExecution.TestLoad);
- InheritOptionalValue(execution.ShowOnly, parentExecution.ShowOnly);
- InheritOptionalValue(execution.Repeat, parentExecution.Repeat);
- InheritOptionalValue(execution.InteractiveDebugging,
- parentExecution.InteractiveDebugging);
- InheritOptionalValue(execution.ScheduleRandom,
- parentExecution.ScheduleRandom);
- InheritOptionalValue(execution.Timeout, parentExecution.Timeout);
- InheritOptionalValue(execution.NoTestsAction,
- parentExecution.NoTestsAction);
- } else {
- preset.Execution = parent.Execution;
- }
- }
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::TestPreset::VisitPresetAfterInherit(int /* version */)
- {
- auto& preset = *this;
- if (!preset.Hidden && preset.ConfigurePreset.empty()) {
- return ReadFileResult::INVALID_PRESET;
- }
- 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;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::WorkflowPreset::VisitPresetInherit(
- const cmCMakePresetsGraph::Preset& /*parentPreset*/)
- {
- return ReadFileResult::READ_OK;
- }
- cmCMakePresetsGraph::ReadFileResult
- cmCMakePresetsGraph::WorkflowPreset::VisitPresetAfterInherit(int /* version */)
- {
- return ReadFileResult::READ_OK;
- }
- std::string cmCMakePresetsGraph::GetFilename(const std::string& sourceDir)
- {
- return cmStrCat(sourceDir, "/CMakePresets.json");
- }
- std::string cmCMakePresetsGraph::GetUserFilename(const std::string& sourceDir)
- {
- return cmStrCat(sourceDir, "/CMakeUserPresets.json");
- }
- cmCMakePresetsGraph::ReadFileResult cmCMakePresetsGraph::ReadProjectPresets(
- const std::string& sourceDir, bool allowNoFiles)
- {
- this->SourceDir = sourceDir;
- this->ClearPresets();
- auto result = this->ReadProjectPresetsInternal(allowNoFiles);
- if (result != ReadFileResult::READ_OK) {
- this->ClearPresets();
- }
- return result;
- }
- cmCMakePresetsGraph::ReadFileResult
- 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, RootType::User, ReadReason::Root,
- inProgressFiles, file, this->errors);
- if (result != ReadFileResult::READ_OK) {
- return result;
- }
- haveOneFile = true;
- } else {
- filename = GetFilename(this->SourceDir);
- if (cmSystemTools::FileExists(filename)) {
- auto result =
- this->ReadJSONFile(filename, RootType::Project, ReadReason::Root,
- inProgressFiles, file, this->errors);
- if (result != ReadFileResult::READ_OK) {
- return result;
- }
- haveOneFile = true;
- }
- }
- assert(inProgressFiles.empty());
- if (!haveOneFile) {
- return allowNoFiles ? ReadFileResult::READ_OK
- : ReadFileResult::FILE_NOT_FOUND;
- }
- CHECK_OK(ComputePresetInheritance(this->ConfigurePresets, *this));
- CHECK_OK(ComputePresetInheritance(this->BuildPresets, *this));
- CHECK_OK(ComputePresetInheritance(this->TestPresets, *this));
- CHECK_OK(ComputePresetInheritance(this->PackagePresets, *this));
- CHECK_OK(ComputePresetInheritance(this->WorkflowPresets, *this));
- for (auto& it : this->ConfigurePresets) {
- if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
- return ReadFileResult::INVALID_MACRO_EXPANSION;
- }
- }
- for (auto& it : this->BuildPresets) {
- 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;
- }
- }
- for (auto& it : this->TestPresets) {
- 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;
- }
- }
- 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;
- }
- }
- for (auto& it : this->WorkflowPresets) {
- using Type = WorkflowPreset::WorkflowStep::Type;
- const ConfigurePreset* configurePreset = nullptr;
- for (auto const& step : it.second.Unexpanded.Steps) {
- if (configurePreset == nullptr && step.PresetType != Type::Configure) {
- return ReadFileResult::INVALID_WORKFLOW_STEPS;
- }
- if (configurePreset != nullptr && step.PresetType == Type::Configure) {
- return ReadFileResult::INVALID_WORKFLOW_STEPS;
- }
- ReadFileResult result;
- switch (step.PresetType) {
- case Type::Configure:
- result = TryReachPresetFromWorkflow(
- it.second.Unexpanded, this->ConfigurePresets, step.PresetName,
- configurePreset);
- break;
- case Type::Build:
- result = TryReachPresetFromWorkflow(
- it.second.Unexpanded, this->BuildPresets, step.PresetName,
- configurePreset);
- break;
- case Type::Test:
- result =
- TryReachPresetFromWorkflow(it.second.Unexpanded, this->TestPresets,
- step.PresetName, configurePreset);
- break;
- case Type::Package:
- result = TryReachPresetFromWorkflow(
- it.second.Unexpanded, this->PackagePresets, step.PresetName,
- configurePreset);
- break;
- }
- if (result != ReadFileResult::READ_OK) {
- return result;
- }
- }
- if (configurePreset == nullptr) {
- return ReadFileResult::INVALID_WORKFLOW_STEPS;
- }
- if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
- return ReadFileResult::INVALID_MACRO_EXPANSION;
- }
- }
- return ReadFileResult::READ_OK;
- }
- const char* cmCMakePresetsGraph::ResultToString(ReadFileResult result)
- {
- switch (result) {
- case ReadFileResult::READ_OK:
- return "OK";
- case ReadFileResult::FILE_NOT_FOUND:
- return "File not found";
- case ReadFileResult::JSON_PARSE_ERROR:
- return "JSON parse error";
- case ReadFileResult::INVALID_ROOT:
- return "Invalid root object";
- case ReadFileResult::NO_VERSION:
- return "No \"version\" field";
- case ReadFileResult::INVALID_VERSION:
- return "Invalid \"version\" field";
- case ReadFileResult::UNRECOGNIZED_VERSION:
- return "Unrecognized \"version\" field";
- case ReadFileResult::INVALID_CMAKE_VERSION:
- return "Invalid \"cmakeMinimumRequired\" field";
- case ReadFileResult::UNRECOGNIZED_CMAKE_VERSION:
- return "\"cmakeMinimumRequired\" version too new";
- case ReadFileResult::INVALID_PRESETS:
- return "Invalid \"configurePresets\" field";
- case ReadFileResult::INVALID_PRESET:
- return "Invalid preset";
- case ReadFileResult::INVALID_VARIABLE:
- return "Invalid CMake variable definition";
- case ReadFileResult::DUPLICATE_PRESETS:
- return "Duplicate presets";
- case ReadFileResult::CYCLIC_PRESET_INHERITANCE:
- return "Cyclic preset inheritance";
- case ReadFileResult::INHERITED_PRESET_UNREACHABLE_FROM_FILE:
- return "Inherited preset is unreachable from preset's file";
- case ReadFileResult::CONFIGURE_PRESET_UNREACHABLE_FROM_FILE:
- return "Configure preset is unreachable from preset's file";
- case ReadFileResult::INVALID_MACRO_EXPANSION:
- return "Invalid macro expansion";
- 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 6 or higher for package preset support";
- case ReadFileResult::WORKFLOW_PRESETS_UNSUPPORTED:
- return "File version must be 6 or higher for workflow preset support";
- case ReadFileResult::INCLUDE_UNSUPPORTED:
- return "File version must be 4 or higher for include support";
- case ReadFileResult::INVALID_INCLUDE:
- return "Invalid \"include\" field";
- case ReadFileResult::INVALID_CONFIGURE_PRESET:
- return "Invalid \"configurePreset\" field";
- case ReadFileResult::INSTALL_PREFIX_UNSUPPORTED:
- return "File version must be 3 or higher for installDir preset "
- "support.";
- case ReadFileResult::INVALID_CONDITION:
- return "Invalid preset condition";
- case ReadFileResult::CONDITION_UNSUPPORTED:
- return "File version must be 3 or higher for condition support";
- 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";
- case ReadFileResult::TEST_OUTPUT_TRUNCATION_UNSUPPORTED:
- return "File version must be 5 or higher for testOutputTruncation "
- "preset support.";
- case ReadFileResult::INVALID_WORKFLOW_STEPS:
- return "Invalid workflow steps";
- case ReadFileResult::WORKFLOW_STEP_UNREACHABLE_FROM_FILE:
- return "Workflow step is unreachable from preset's file";
- case ReadFileResult::CTEST_JUNIT_UNSUPPORTED:
- return "File version must be 6 or higher for CTest JUnit output support";
- }
- return "Unknown error";
- }
- void cmCMakePresetsGraph::ClearPresets()
- {
- this->ConfigurePresets.clear();
- this->BuildPresets.clear();
- this->TestPresets.clear();
- this->PackagePresets.clear();
- this->WorkflowPresets.clear();
- this->ConfigurePresetOrder.clear();
- this->BuildPresetOrder.clear();
- this->TestPresetOrder.clear();
- this->PackagePresetOrder.clear();
- this->WorkflowPresetOrder.clear();
- this->Files.clear();
- }
- void cmCMakePresetsGraph::printPrecedingNewline(PrintPrecedingNewline* newline)
- {
- if (newline) {
- if (*newline == PrintPrecedingNewline::True) {
- std::cout << std::endl;
- }
- *newline = PrintPrecedingNewline::True;
- }
- }
- void cmCMakePresetsGraph::PrintPresets(
- const std::vector<const cmCMakePresetsGraph::Preset*>& presets)
- {
- if (presets.empty()) {
- return;
- }
- auto longestPresetName =
- std::max_element(presets.begin(), presets.end(),
- [](const cmCMakePresetsGraph::Preset* a,
- const cmCMakePresetsGraph::Preset* b) {
- return a->Name.length() < b->Name.length();
- });
- auto longestLength = (*longestPresetName)->Name.length();
- for (const auto* preset : presets) {
- std::cout << " \"" << preset->Name << '"';
- const auto& description = preset->DisplayName;
- if (!description.empty()) {
- for (std::size_t i = 0; i < longestLength - preset->Name.length(); ++i) {
- std::cout << ' ';
- }
- std::cout << " - " << description;
- }
- std::cout << '\n';
- }
- }
- void cmCMakePresetsGraph::PrintConfigurePresetList(
- PrintPrecedingNewline* newline) const
- {
- PrintConfigurePresetList([](const ConfigurePreset&) { return true; },
- newline);
- }
- void cmCMakePresetsGraph::PrintConfigurePresetList(
- const std::function<bool(const ConfigurePreset&)>& filter,
- PrintPrecedingNewline* newline) const
- {
- std::vector<const cmCMakePresetsGraph::Preset*> presets;
- for (auto const& p : this->ConfigurePresetOrder) {
- auto const& preset = this->ConfigurePresets.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 configure presets:\n\n";
- cmCMakePresetsGraph::PrintPresets(presets);
- }
- }
- void cmCMakePresetsGraph::PrintBuildPresetList(
- PrintPrecedingNewline* newline) const
- {
- std::vector<const cmCMakePresetsGraph::Preset*> presets;
- for (auto const& p : this->BuildPresetOrder) {
- auto const& preset = this->BuildPresets.at(p);
- if (!preset.Unexpanded.Hidden && preset.Expanded &&
- preset.Expanded->ConditionResult) {
- presets.push_back(
- static_cast<const cmCMakePresetsGraph::Preset*>(&preset.Unexpanded));
- }
- }
- if (!presets.empty()) {
- printPrecedingNewline(newline);
- std::cout << "Available build presets:\n\n";
- cmCMakePresetsGraph::PrintPresets(presets);
- }
- }
- void cmCMakePresetsGraph::PrintTestPresetList(
- PrintPrecedingNewline* newline) const
- {
- std::vector<const cmCMakePresetsGraph::Preset*> presets;
- for (auto const& p : this->TestPresetOrder) {
- auto const& preset = this->TestPresets.at(p);
- if (!preset.Unexpanded.Hidden && preset.Expanded &&
- preset.Expanded->ConditionResult) {
- presets.push_back(
- static_cast<const cmCMakePresetsGraph::Preset*>(&preset.Unexpanded));
- }
- }
- if (!presets.empty()) {
- printPrecedingNewline(newline);
- std::cout << "Available test presets:\n\n";
- cmCMakePresetsGraph::PrintPresets(presets);
- }
- }
- 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::PrintWorkflowPresetList(
- PrintPrecedingNewline* newline) const
- {
- std::vector<const cmCMakePresetsGraph::Preset*> presets;
- for (auto const& p : this->WorkflowPresetOrder) {
- auto const& preset = this->WorkflowPresets.at(p);
- if (!preset.Unexpanded.Hidden && preset.Expanded &&
- preset.Expanded->ConditionResult) {
- presets.push_back(
- static_cast<const cmCMakePresetsGraph::Preset*>(&preset.Unexpanded));
- }
- }
- if (!presets.empty()) {
- printPrecedingNewline(newline);
- std::cout << "Available workflow 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);
- this->PrintWorkflowPresetList(&newline);
- }
|