presets: Add graphviz support

Closes: #22164
This commit is contained in:
Aliaksandr Averchanka 2024-07-30 16:07:58 +03:00 committed by Brad King
parent e6453c200e
commit 31c0e0de49
22 changed files with 100 additions and 4 deletions

View File

@ -267,6 +267,17 @@ that may contain the following fields:
:variable:`CMAKE_TOOLCHAIN_FILE` value. It is allowed in preset files
specifying version ``3`` or above.
``graphviz``
An optional string representing the path to the graphviz input file,
that will contain all the library and executable dependencies
in the project. See the documentation for :module:`CMakeGraphVizOptions`
for more details.
This field supports `macro expansion`_. If a relative path is specified,
it is calculated relative to the build directory, and if not found,
relative to the source directory. It is allowed in preset files
specifying version ``10`` or above.
``binaryDir``
An optional string representing the path to the output binary directory.
This field supports `macro expansion`_. If a relative path is specified,

View File

@ -491,6 +491,10 @@
"properties": {
"$comment": { "$ref": "#/definitions/$comment" }
}
},
"graphviz": {
"type": "string",
"description": "An optional string specifying the path to graphviz dot file. Available in version 10 and higher."
}
}
}
@ -743,6 +747,7 @@
"architecture": { "$ref": "#/definitions/configurePresetsArchitectureV10" },
"toolset": { "$ref": "#/definitions/configurePresetsToolsetV10" },
"toolchainFile": {},
"graphviz": {},
"binaryDir": {},
"installDir": {},
"cmakeExecutable": {},

View File

@ -177,6 +177,12 @@ void TOOLCHAIN_FILE_UNSUPPORTED(cmJSONState* state)
"support");
}
void GRAPHVIZ_FILE_UNSUPPORTED(cmJSONState* state)
{
state->AddError(
"File version must be 10 or higher for graphviz preset support");
}
void CYCLIC_INCLUDE(const std::string& file, cmJSONState* state)
{
state->AddError(cmStrCat("Cyclic include among preset files: ", file));

View File

@ -70,6 +70,8 @@ void CONDITION_UNSUPPORTED(cmJSONState* state);
void TOOLCHAIN_FILE_UNSUPPORTED(cmJSONState* state);
void GRAPHVIZ_FILE_UNSUPPORTED(cmJSONState* state);
void CYCLIC_INCLUDE(const std::string& file, cmJSONState* state);
void TEST_OUTPUT_TRUNCATION_UNSUPPORTED(cmJSONState* state);

View File

@ -293,6 +293,12 @@ bool ExpandMacros(const cmCMakePresetsGraph& graph,
out->ToolchainFile = toolchain;
}
if (!preset.GraphVizFile.empty()) {
std::string graphVizFile = preset.GraphVizFile;
CHECK_EXPAND(out, graphVizFile, macroExpanders, graph.GetVersion(preset));
out->GraphVizFile = graphVizFile;
}
for (auto& variable : out->CacheVariables) {
if (variable.second) {
CHECK_EXPAND(out, variable.second->Value, macroExpanders,
@ -775,6 +781,7 @@ bool cmCMakePresetsGraph::ConfigurePreset::VisitPresetInherit(
InheritString(preset.BinaryDir, parent.BinaryDir);
InheritString(preset.InstallDir, parent.InstallDir);
InheritString(preset.ToolchainFile, parent.ToolchainFile);
InheritString(preset.GraphVizFile, parent.GraphVizFile);
InheritOptionalValue(preset.WarnDev, parent.WarnDev);
InheritOptionalValue(preset.ErrorDev, parent.ErrorDev);
InheritOptionalValue(preset.WarnDeprecated, parent.WarnDeprecated);

View File

@ -120,6 +120,7 @@ public:
std::string Toolset;
cm::optional<ArchToolsetStrategy> ToolsetStrategy;
std::string ToolchainFile;
std::string GraphVizFile;
std::string BinaryDir;
std::string InstallDir;

View File

@ -611,6 +611,12 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
return false;
}
// Support for graphviz argument added in version 10.
if (v < 10 && !preset.GraphVizFile.empty()) {
cmCMakePresetsErrors::GRAPHVIZ_FILE_UNSUPPORTED(&this->parseState);
return false;
}
this->ConfigurePresetOrder.push_back(preset.Name);
}

View File

@ -272,6 +272,8 @@ auto const ConfigurePresetHelper =
.Bind("toolset"_s, ToolsetHelper, false)
.Bind("toolchainFile"_s, &ConfigurePreset::ToolchainFile,
cmCMakePresetsGraphInternal::PresetStringHelper, false)
.Bind("graphviz"_s, &ConfigurePreset::GraphVizFile,
cmCMakePresetsGraphInternal::PresetStringHelper, false)
.Bind("binaryDir"_s, &ConfigurePreset::BinaryDir,
cmCMakePresetsGraphInternal::PresetStringHelper, false)
.Bind("installDir"_s, &ConfigurePreset::InstallDir,

View File

@ -1075,10 +1075,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
CommandArgument{ "--graphviz", "No file specified for --graphviz",
CommandArgument::Values::One,
[](std::string const& value, cmake* state) -> bool {
std::string path =
cmSystemTools::CollapseFullPath(value);
cmSystemTools::ConvertToUnixSlashes(path);
state->GraphVizFile = path;
state->SetGraphVizFile(value);
return true;
} },
@ -1590,6 +1587,12 @@ void cmake::SetArgs(const std::vector<std::string>& args)
}
}
if (!expandedPreset->GraphVizFile.empty()) {
if (this->GraphVizFile.empty()) {
this->SetGraphVizFile(expandedPreset->GraphVizFile);
}
}
this->SetWarningFromPreset("dev", expandedPreset->WarnDev,
expandedPreset->ErrorDev);
this->SetWarningFromPreset("deprecated", expandedPreset->WarnDeprecated,

View File

@ -26,6 +26,7 @@
#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmValue.h"
#if !defined(CMAKE_BOOTSTRAP)
@ -298,6 +299,14 @@ public:
this->GeneratorToolsetSet = true;
}
//! Set the name of the graphviz file.
void SetGraphVizFile(std::string const& ts)
{
std::string path = cmSystemTools::CollapseFullPath(ts);
cmSystemTools::ConvertToUnixSlashes(path);
this->GraphVizFile = path;
}
bool IsAKnownSourceExtension(cm::string_view ext) const
{
return this->CLikeSourceFileExtensions.Test(ext) ||

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,2 @@
Generate graphviz: .+[\\/]my_graphviz\.dot

View File

@ -0,0 +1,11 @@
{
"version": 10,
"configurePresets": [
{
"name": "GraphvizValid",
"generator": "@RunCMake_GENERATOR@",
"graphviz": "${sourceDir}/my_graphviz.dot",
"binaryDir": "${sourceDir}/build"
}
]
}

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,2 @@
^CMake Error: Could not read presets from .*
File version must be 10 or higher for graphviz preset support

View File

@ -0,0 +1,11 @@
{
"version": 9,
"configurePresets": [
{
"name": "GraphvizValid",
"generator": "@RunCMake_GENERATOR@",
"graphviz": "${sourceDir}/my_graphviz.dot",
"binaryDir": "${sourceDir}/build"
}
]
}

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1,10 @@
{
"version": 10,
"configurePresets": [
{
"name": "NoGraphvizValid",
"generator": "@RunCMake_GENERATOR@",
"binaryDir": "${sourceDir}/build"
}
]
}

View File

@ -98,6 +98,11 @@ run_cmake_presets(CommentValid)
run_cmake_presets(CommentValidFull)
set(CMakePresets_SCHEMA_EXPECTED_RESULT 1)
run_cmake_presets(CommentValidOldSchema)
set(CMakePresets_SCHEMA_EXPECTED_RESULT 0)
run_cmake_presets(NoGraphvizValid)
run_cmake_presets(GraphvizValid)
set(CMakePresets_SCHEMA_EXPECTED_RESULT 1)
run_cmake_presets(GraphvizValidOldSchema)
run_cmake_presets(JSONParseError)
run_cmake_presets(InvalidRoot)
run_cmake_presets(NoVersion)