mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
presets: Allow macro expansion without a graph object
Prepare for future changes where the full preset graph will not yet be merged while expanding macros, and the version will be taken from the standalone file instead of the origin of the graph.
This commit is contained in:
@@ -266,156 +266,165 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
bool ExpandMacros(cmCMakePresetsGraph const& graph,
|
||||
ConfigurePreset const& preset,
|
||||
cm::optional<ConfigurePreset>& out,
|
||||
MacroExpanderVector const& macroExpanders)
|
||||
bool CheckExpandMacros(ConfigurePreset const& preset,
|
||||
cm::optional<ConfigurePreset>& out,
|
||||
MacroExpanderVector const& macroExpanders,
|
||||
cmCMakePresetsGraph const* graph = nullptr)
|
||||
{
|
||||
int version = graph ? graph->GetVersion(preset) : preset.OriginFile->Version;
|
||||
|
||||
std::string binaryDir = preset.BinaryDir;
|
||||
CHECK_EXPAND(out, binaryDir, macroExpanders, graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, binaryDir, macroExpanders, version);
|
||||
|
||||
if (!binaryDir.empty()) {
|
||||
if (!cmSystemTools::FileIsFullPath(binaryDir)) {
|
||||
binaryDir = cmStrCat(graph.SourceDir, '/', binaryDir);
|
||||
if (graph) {
|
||||
if (!cmSystemTools::FileIsFullPath(binaryDir)) {
|
||||
binaryDir = cmStrCat(graph->SourceDir, '/', binaryDir);
|
||||
}
|
||||
out->BinaryDir = cmSystemTools::CollapseFullPath(binaryDir);
|
||||
cmSystemTools::ConvertToUnixSlashes(out->BinaryDir);
|
||||
} else {
|
||||
// Defer path normalization until the graph is merged, but store the
|
||||
// intermediate result.
|
||||
out->BinaryDir = 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));
|
||||
CHECK_EXPAND(out, installDir, macroExpanders, version);
|
||||
|
||||
if (!cmSystemTools::FileIsFullPath(installDir)) {
|
||||
installDir = cmStrCat(graph.SourceDir, '/', installDir);
|
||||
if (graph) {
|
||||
if (!cmSystemTools::FileIsFullPath(installDir)) {
|
||||
installDir = cmStrCat(graph->SourceDir, '/', installDir);
|
||||
}
|
||||
out->InstallDir = cmSystemTools::CollapseFullPath(installDir);
|
||||
cmSystemTools::ConvertToUnixSlashes(out->InstallDir);
|
||||
} else {
|
||||
// Defer path normalization until the graph is merged, but store the
|
||||
// intermediate result.
|
||||
out->InstallDir = 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));
|
||||
CHECK_EXPAND(out, toolchain, macroExpanders, version);
|
||||
out->ToolchainFile = toolchain;
|
||||
}
|
||||
|
||||
if (!preset.GraphVizFile.empty()) {
|
||||
std::string graphVizFile = preset.GraphVizFile;
|
||||
CHECK_EXPAND(out, graphVizFile, macroExpanders, graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, graphVizFile, macroExpanders, version);
|
||||
out->GraphVizFile = graphVizFile;
|
||||
}
|
||||
|
||||
for (auto& variable : out->CacheVariables) {
|
||||
if (variable.second) {
|
||||
CHECK_EXPAND(out, variable.second->Value, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, variable.second->Value, macroExpanders, version);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExpandMacros(cmCMakePresetsGraph const& graph, BuildPreset const& preset,
|
||||
cm::optional<BuildPreset>& out,
|
||||
MacroExpanderVector const& macroExpanders)
|
||||
bool CheckExpandMacros(BuildPreset const& preset,
|
||||
cm::optional<BuildPreset>& out,
|
||||
MacroExpanderVector const& macroExpanders,
|
||||
cmCMakePresetsGraph const* graph = nullptr)
|
||||
{
|
||||
int version = graph ? graph->GetVersion(preset) : preset.OriginFile->Version;
|
||||
|
||||
for (auto& target : out->Targets) {
|
||||
CHECK_EXPAND(out, target, macroExpanders, graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, target, macroExpanders, version);
|
||||
}
|
||||
|
||||
for (auto& nativeToolOption : out->NativeToolOptions) {
|
||||
CHECK_EXPAND(out, nativeToolOption, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, nativeToolOption, macroExpanders, version);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExpandMacros(cmCMakePresetsGraph const& graph, TestPreset const& preset,
|
||||
cm::optional<TestPreset>& out,
|
||||
MacroExpanderVector const& macroExpanders)
|
||||
bool CheckExpandMacros(TestPreset const& preset, cm::optional<TestPreset>& out,
|
||||
MacroExpanderVector const& macroExpanders,
|
||||
cmCMakePresetsGraph const* graph = nullptr)
|
||||
{
|
||||
int version = graph ? graph->GetVersion(preset) : preset.OriginFile->Version;
|
||||
|
||||
for (auto& overwrite : out->OverwriteConfigurationFile) {
|
||||
CHECK_EXPAND(out, overwrite, macroExpanders, graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, overwrite, macroExpanders, version);
|
||||
}
|
||||
|
||||
if (out->Output) {
|
||||
CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, out->Output->OutputJUnitFile, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, out->Output->OutputLogFile, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->Output->OutputJUnitFile, macroExpanders, version);
|
||||
}
|
||||
|
||||
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));
|
||||
CHECK_EXPAND(out, out->Filter->Include->Name, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->Filter->Include->Label, macroExpanders, version);
|
||||
|
||||
if (out->Filter->Include->Index) {
|
||||
CHECK_EXPAND(out, out->Filter->Include->Index->IndexFile,
|
||||
macroExpanders, graph.GetVersion(preset));
|
||||
macroExpanders, version);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
CHECK_EXPAND(out, out->Filter->Exclude->Name, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->Filter->Exclude->Label, macroExpanders, version);
|
||||
|
||||
if (out->Filter->Exclude->Fixtures) {
|
||||
CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Any, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
version);
|
||||
CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Setup,
|
||||
macroExpanders, graph.GetVersion(preset));
|
||||
macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->Filter->Exclude->Fixtures->Cleanup,
|
||||
macroExpanders, graph.GetVersion(preset));
|
||||
macroExpanders, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (out->Execution) {
|
||||
CHECK_EXPAND(out, out->Execution->ResourceSpecFile, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
version);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExpandMacros(cmCMakePresetsGraph const& graph,
|
||||
PackagePreset const& preset,
|
||||
cm::optional<PackagePreset>& out,
|
||||
MacroExpanderVector const& macroExpanders)
|
||||
bool CheckExpandMacros(PackagePreset const& preset,
|
||||
cm::optional<PackagePreset>& out,
|
||||
MacroExpanderVector const& macroExpanders,
|
||||
cmCMakePresetsGraph const* graph = nullptr)
|
||||
{
|
||||
int version = graph ? graph->GetVersion(preset) : preset.OriginFile->Version;
|
||||
|
||||
for (auto& variable : out->Variables) {
|
||||
CHECK_EXPAND(out, variable.second, macroExpanders,
|
||||
graph.GetVersion(preset));
|
||||
CHECK_EXPAND(out, variable.second, macroExpanders, version);
|
||||
}
|
||||
|
||||
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));
|
||||
CHECK_EXPAND(out, out->ConfigFile, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->PackageName, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->PackageVersion, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->PackageDirectory, macroExpanders, version);
|
||||
CHECK_EXPAND(out, out->VendorName, macroExpanders, version);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ExpandMacros(cmCMakePresetsGraph const& /*graph*/,
|
||||
WorkflowPreset const& /*preset*/,
|
||||
cm::optional<WorkflowPreset>& /*out*/,
|
||||
MacroExpanderVector const& /*macroExpanders*/)
|
||||
bool CheckExpandMacros(WorkflowPreset const& /*preset*/,
|
||||
cm::optional<WorkflowPreset>& /*out*/,
|
||||
MacroExpanderVector const& /*macroExpanders*/,
|
||||
cmCMakePresetsGraph const* /*graph*/ = nullptr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool ExpandMacros(cmCMakePresetsGraph& graph, T const& preset,
|
||||
bool ExpandMacros(cmCMakePresetsGraph* graph, T const& preset,
|
||||
cm::optional<T>& out)
|
||||
{
|
||||
out.emplace(preset);
|
||||
@@ -427,19 +436,19 @@ bool ExpandMacros(cmCMakePresetsGraph& graph, T const& preset,
|
||||
|
||||
MacroExpanderVector macroExpanders{};
|
||||
|
||||
macroExpanders.push_back(cm::make_unique<BaseMacroExpander>(graph));
|
||||
macroExpanders.push_back(cm::make_unique<BaseMacroExpander>(*graph));
|
||||
macroExpanders.push_back(
|
||||
cm::make_unique<PresetMacroExpander<T>>(graph, preset));
|
||||
cm::make_unique<PresetMacroExpander<T>>(*graph, preset));
|
||||
macroExpanders.push_back(cm::make_unique<EnvironmentMacroExpander<T>>(
|
||||
macroExpanders, out, envCycles));
|
||||
|
||||
for (auto& v : out->Environment) {
|
||||
if (v.second) {
|
||||
switch (VisitEnv(*v.second, envCycles[v.first], macroExpanders,
|
||||
graph.GetVersion(preset))) {
|
||||
graph->GetVersion(preset))) {
|
||||
case ExpandMacroResult::Error:
|
||||
cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name,
|
||||
&graph.parseState);
|
||||
&graph->parseState);
|
||||
return false;
|
||||
case ExpandMacroResult::Ignore:
|
||||
out.reset();
|
||||
@@ -453,9 +462,9 @@ bool ExpandMacros(cmCMakePresetsGraph& graph, T const& preset,
|
||||
if (preset.ConditionEvaluator) {
|
||||
cm::optional<bool> result;
|
||||
if (!preset.ConditionEvaluator->Evaluate(
|
||||
macroExpanders, graph.GetVersion(preset), result)) {
|
||||
macroExpanders, graph->GetVersion(preset), result)) {
|
||||
cmCMakePresetsErrors::INVALID_PRESET_NAMED(preset.Name,
|
||||
&graph.parseState);
|
||||
&graph->parseState);
|
||||
return false;
|
||||
}
|
||||
if (!result) {
|
||||
@@ -465,7 +474,7 @@ bool ExpandMacros(cmCMakePresetsGraph& graph, T const& preset,
|
||||
out->ConditionResult = *result;
|
||||
}
|
||||
|
||||
return ExpandMacros(graph, preset, out, macroExpanders);
|
||||
return CheckExpandMacros(preset, out, macroExpanders, graph);
|
||||
}
|
||||
|
||||
ExpandMacroResult VisitEnv(std::string& value, CycleStatus& status,
|
||||
@@ -1098,7 +1107,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
|
||||
}
|
||||
|
||||
for (auto& it : this->ConfigurePresets) {
|
||||
if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
if (!ExpandMacros(this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
|
||||
&this->parseState);
|
||||
return false;
|
||||
@@ -1128,7 +1137,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
|
||||
}
|
||||
}
|
||||
|
||||
if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
if (!ExpandMacros(this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
|
||||
&this->parseState);
|
||||
return false;
|
||||
@@ -1158,7 +1167,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
|
||||
}
|
||||
}
|
||||
|
||||
if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
if (!ExpandMacros(this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
|
||||
&this->parseState);
|
||||
return false;
|
||||
@@ -1188,7 +1197,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
|
||||
}
|
||||
}
|
||||
|
||||
if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
if (!ExpandMacros(this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
|
||||
&this->parseState);
|
||||
return false;
|
||||
@@ -1243,7 +1252,7 @@ bool cmCMakePresetsGraph::ReadProjectPresetsInternal(bool allowNoFiles)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ExpandMacros(*this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
if (!ExpandMacros(this, it.second.Unexpanded, it.second.Expanded)) {
|
||||
cmCMakePresetsErrors::INVALID_MACRO_EXPANSION(it.first,
|
||||
&this->parseState);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user