2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2010-11-09 20:37:51 +00:00
|
|
|
#include "cmGraphVizWriter.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
#include <cctype>
|
2016-11-05 20:40:14 +00:00
|
|
|
#include <iostream>
|
2019-07-10 15:38:48 +00:00
|
|
|
#include <memory>
|
2019-10-08 02:45:30 +00:00
|
|
|
#include <set>
|
2016-11-05 20:40:14 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
#include <cm/memory>
|
|
|
|
|
2010-11-09 20:37:51 +00:00
|
|
|
#include "cmGeneratedFileStream.h"
|
2016-09-01 18:59:28 +00:00
|
|
|
#include "cmGeneratorTarget.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmGlobalGenerator.h"
|
2019-10-08 02:45:30 +00:00
|
|
|
#include "cmLinkItem.h"
|
2016-04-29 14:53:13 +00:00
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2019-01-14 17:27:14 +00:00
|
|
|
#include "cmState.h"
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmStateSnapshot.h"
|
2019-08-11 09:56:59 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2016-09-01 18:59:28 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmake.h"
|
|
|
|
|
2017-09-18 17:22:59 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
char const* const GRAPHVIZ_EDGE_STYLE_PUBLIC = "solid";
|
|
|
|
char const* const GRAPHVIZ_EDGE_STYLE_INTERFACE = "dashed";
|
|
|
|
char const* const GRAPHVIZ_EDGE_STYLE_PRIVATE = "dotted";
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_EXECUTABLE = "egg"; // egg-xecutable
|
|
|
|
|
|
|
|
// Normal libraries.
|
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_LIBRARY_STATIC = "octagon";
|
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_LIBRARY_SHARED = "doubleoctagon";
|
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_LIBRARY_MODULE = "tripleoctagon";
|
2017-12-09 05:27:24 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_LIBRARY_INTERFACE = "pentagon";
|
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_LIBRARY_OBJECT = "hexagon";
|
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_LIBRARY_UNKNOWN = "septagon";
|
|
|
|
|
|
|
|
char const* const GRAPHVIZ_NODE_SHAPE_UTILITY = "box";
|
|
|
|
|
|
|
|
const char* getShapeForTarget(const cmLinkItem& item)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
if (item.Target == nullptr) {
|
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_UNKNOWN;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
switch (item.Target->GetType()) {
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::EXECUTABLE:
|
2019-10-08 02:45:30 +00:00
|
|
|
return GRAPHVIZ_NODE_SHAPE_EXECUTABLE;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::STATIC_LIBRARY:
|
2019-10-08 02:45:30 +00:00
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_STATIC;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::SHARED_LIBRARY:
|
2019-10-08 02:45:30 +00:00
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_SHARED;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::MODULE_LIBRARY:
|
2019-10-08 02:45:30 +00:00
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_MODULE;
|
|
|
|
case cmStateEnums::OBJECT_LIBRARY:
|
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_OBJECT;
|
|
|
|
case cmStateEnums::UTILITY:
|
|
|
|
return GRAPHVIZ_NODE_SHAPE_UTILITY;
|
|
|
|
case cmStateEnums::INTERFACE_LIBRARY:
|
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_INTERFACE;
|
|
|
|
case cmStateEnums::UNKNOWN_LIBRARY:
|
2010-11-09 20:37:51 +00:00
|
|
|
default:
|
2019-10-08 02:45:30 +00:00
|
|
|
return GRAPHVIZ_NODE_SHAPE_LIBRARY_UNKNOWN;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2019-10-08 02:45:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
cmGraphVizWriter::cmGraphVizWriter(std::string const& fileName,
|
|
|
|
const cmGlobalGenerator* globalGenerator)
|
|
|
|
: FileName(fileName)
|
|
|
|
, GlobalFileStream(fileName)
|
|
|
|
, GraphName(globalGenerator->GetSafeGlobalSetting("CMAKE_PROJECT_NAME"))
|
|
|
|
, GraphHeader("node [\n fontsize = \"12\"\n];")
|
|
|
|
, GraphNodePrefix("node")
|
|
|
|
, GlobalGenerator(globalGenerator)
|
|
|
|
, NextNodeId(0)
|
|
|
|
, GenerateForExecutables(true)
|
|
|
|
, GenerateForStaticLibs(true)
|
|
|
|
, GenerateForSharedLibs(true)
|
|
|
|
, GenerateForModuleLibs(true)
|
|
|
|
, GenerateForInterfaceLibs(true)
|
|
|
|
, GenerateForObjectLibs(true)
|
|
|
|
, GenerateForUnknownLibs(true)
|
|
|
|
, GenerateForCustomTargets(false)
|
|
|
|
, GenerateForExternals(true)
|
|
|
|
, GeneratePerTarget(true)
|
|
|
|
, GenerateDependers(true)
|
|
|
|
{
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
cmGraphVizWriter::~cmGraphVizWriter()
|
2017-09-18 17:22:59 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
this->WriteFooter(this->GlobalFileStream);
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
for (auto& fileStream : this->PerTargetFileStreams) {
|
|
|
|
this->WriteFooter(*fileStream.second);
|
|
|
|
}
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
for (auto& fileStream : this->TargetDependersFileStreams) {
|
|
|
|
this->WriteFooter(*fileStream.second);
|
2017-09-18 17:22:59 +00:00
|
|
|
}
|
2019-10-08 02:45:30 +00:00
|
|
|
}
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::VisitGraph(std::string const&)
|
|
|
|
{
|
|
|
|
this->WriteHeader(GlobalFileStream, this->GraphName);
|
|
|
|
this->WriteLegend(GlobalFileStream);
|
|
|
|
}
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::OnItem(cmLinkItem const& item)
|
|
|
|
{
|
|
|
|
if (this->ItemExcluded(item)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
NodeNames[item.AsStr()] = cmStrCat(GraphNodePrefix, NextNodeId);
|
|
|
|
++NextNodeId;
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
this->WriteNode(this->GlobalFileStream, item);
|
2018-10-24 22:49:12 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (this->GeneratePerTarget) {
|
|
|
|
this->CreateTargetFile(this->PerTargetFileStreams, item);
|
2017-09-18 17:22:59 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (this->GenerateDependers) {
|
|
|
|
this->CreateTargetFile(this->TargetDependersFileStreams, item,
|
|
|
|
".dependers");
|
|
|
|
}
|
|
|
|
}
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::CreateTargetFile(FileStreamMap& fileStreamMap,
|
|
|
|
cmLinkItem const& item,
|
|
|
|
std::string const& fileNameSuffix)
|
|
|
|
{
|
|
|
|
auto const pathSafeItemName = PathSafeString(item.AsStr());
|
|
|
|
auto const perTargetFileName =
|
|
|
|
cmStrCat(this->FileName, '.', pathSafeItemName, fileNameSuffix);
|
|
|
|
auto perTargetFileStream =
|
|
|
|
cm::make_unique<cmGeneratedFileStream>(perTargetFileName);
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
this->WriteHeader(*perTargetFileStream, item.AsStr());
|
|
|
|
this->WriteNode(*perTargetFileStream, item);
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
fileStreamMap.emplace(item.AsStr(), std::move(perTargetFileStream));
|
|
|
|
}
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::OnDirectLink(cmLinkItem const& depender,
|
|
|
|
cmLinkItem const& dependee,
|
|
|
|
DependencyType dt)
|
|
|
|
{
|
|
|
|
this->VisitLink(depender, dependee, true, GetEdgeStyle(dt));
|
2017-09-18 17:22:59 +00:00
|
|
|
}
|
2019-10-08 02:45:30 +00:00
|
|
|
|
|
|
|
void cmGraphVizWriter::OnIndirectLink(cmLinkItem const& depender,
|
|
|
|
cmLinkItem const& dependee)
|
|
|
|
{
|
|
|
|
this->VisitLink(depender, dependee, false);
|
2017-09-18 17:22:59 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::VisitLink(cmLinkItem const& depender,
|
|
|
|
cmLinkItem const& dependee, bool isDirectLink,
|
|
|
|
std::string const& scopeType)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
if (this->ItemExcluded(depender) || this->ItemExcluded(dependee)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDirectLink) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->WriteConnection(this->GlobalFileStream, depender, dependee, scopeType);
|
|
|
|
|
|
|
|
if (this->GeneratePerTarget) {
|
|
|
|
auto fileStream = PerTargetFileStreams[depender.AsStr()].get();
|
|
|
|
this->WriteNode(*fileStream, dependee);
|
|
|
|
this->WriteConnection(*fileStream, depender, dependee, scopeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->GenerateDependers) {
|
|
|
|
auto fileStream = TargetDependersFileStreams[dependee.AsStr()].get();
|
|
|
|
this->WriteNode(*fileStream, depender);
|
|
|
|
this->WriteConnection(*fileStream, depender, dependee, scopeType);
|
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-19 14:30:00 +00:00
|
|
|
void cmGraphVizWriter::ReadSettings(
|
|
|
|
const std::string& settingsFileName,
|
|
|
|
const std::string& fallbackSettingsFileName)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-01-14 17:27:14 +00:00
|
|
|
cmake cm(cmake::RoleScript, cmState::Unknown);
|
2015-05-04 21:01:29 +00:00
|
|
|
cm.SetHomeDirectory("");
|
|
|
|
cm.SetHomeOutputDirectory("");
|
2015-10-13 19:48:46 +00:00
|
|
|
cm.GetCurrentSnapshot().SetDefaultDefinitions();
|
2015-05-24 09:31:14 +00:00
|
|
|
cmGlobalGenerator ggi(&cm);
|
2017-09-21 21:06:05 +00:00
|
|
|
cmMakefile mf(&ggi, cm.GetCurrentSnapshot());
|
|
|
|
std::unique_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator(&mf));
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-05-19 14:30:00 +00:00
|
|
|
std::string inFileName = settingsFileName;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::FileExists(inFileName)) {
|
2010-11-09 20:37:51 +00:00
|
|
|
inFileName = fallbackSettingsFileName;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::FileExists(inFileName)) {
|
2010-11-09 20:37:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2017-09-21 21:06:05 +00:00
|
|
|
if (!mf.ReadListFile(inFileName)) {
|
2019-05-19 14:30:00 +00:00
|
|
|
cmSystemTools::Error("Problem opening GraphViz options file: " +
|
2010-11-09 20:37:51 +00:00
|
|
|
inFileName);
|
|
|
|
return;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
|
|
|
|
std::cout << "Reading GraphViz options file: " << inFileName << std::endl;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
#define __set_if_set(var, cmakeDefinition) \
|
2019-01-11 21:58:56 +00:00
|
|
|
do { \
|
2017-09-21 21:06:05 +00:00
|
|
|
const char* value = mf.GetDefinition(cmakeDefinition); \
|
2016-05-16 14:34:04 +00:00
|
|
|
if (value) { \
|
2016-09-05 20:09:49 +00:00
|
|
|
(var) = value; \
|
2016-05-16 14:34:04 +00:00
|
|
|
} \
|
2019-01-11 21:58:56 +00:00
|
|
|
} while (false)
|
2010-11-09 20:37:51 +00:00
|
|
|
|
|
|
|
__set_if_set(this->GraphName, "GRAPHVIZ_GRAPH_NAME");
|
|
|
|
__set_if_set(this->GraphHeader, "GRAPHVIZ_GRAPH_HEADER");
|
|
|
|
__set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX");
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
#define __set_bool_if_set(var, cmakeDefinition) \
|
2019-01-11 21:58:56 +00:00
|
|
|
do { \
|
2017-09-21 21:06:05 +00:00
|
|
|
const char* value = mf.GetDefinition(cmakeDefinition); \
|
2016-05-16 14:34:04 +00:00
|
|
|
if (value) { \
|
2017-09-21 21:06:05 +00:00
|
|
|
(var) = mf.IsOn(cmakeDefinition); \
|
2016-05-16 14:34:04 +00:00
|
|
|
} \
|
2019-01-11 21:58:56 +00:00
|
|
|
} while (false)
|
2010-11-14 18:30:58 +00:00
|
|
|
|
|
|
|
__set_bool_if_set(this->GenerateForExecutables, "GRAPHVIZ_EXECUTABLES");
|
|
|
|
__set_bool_if_set(this->GenerateForStaticLibs, "GRAPHVIZ_STATIC_LIBS");
|
|
|
|
__set_bool_if_set(this->GenerateForSharedLibs, "GRAPHVIZ_SHARED_LIBS");
|
2011-02-05 17:43:34 +00:00
|
|
|
__set_bool_if_set(this->GenerateForModuleLibs, "GRAPHVIZ_MODULE_LIBS");
|
2019-10-08 02:45:30 +00:00
|
|
|
__set_bool_if_set(this->GenerateForInterfaceLibs, "GRAPHVIZ_INTERFACE_LIBS");
|
|
|
|
__set_bool_if_set(this->GenerateForObjectLibs, "GRAPHVIZ_OBJECT_LIBS");
|
|
|
|
__set_bool_if_set(this->GenerateForUnknownLibs, "GRAPHVIZ_UNKNOWN_LIBS");
|
|
|
|
__set_bool_if_set(this->GenerateForCustomTargets, "GRAPHVIZ_CUSTOM_TARGETS");
|
2011-02-05 17:43:34 +00:00
|
|
|
__set_bool_if_set(this->GenerateForExternals, "GRAPHVIZ_EXTERNAL_LIBS");
|
2014-02-09 21:58:44 +00:00
|
|
|
__set_bool_if_set(this->GeneratePerTarget, "GRAPHVIZ_GENERATE_PER_TARGET");
|
|
|
|
__set_bool_if_set(this->GenerateDependers, "GRAPHVIZ_GENERATE_DEPENDERS");
|
2010-11-14 18:30:58 +00:00
|
|
|
|
2014-02-10 05:21:34 +00:00
|
|
|
std::string ignoreTargetsRegexes;
|
2011-02-05 18:09:54 +00:00
|
|
|
__set_if_set(ignoreTargetsRegexes, "GRAPHVIZ_IGNORE_TARGETS");
|
2010-11-14 18:47:28 +00:00
|
|
|
|
2011-02-05 18:09:54 +00:00
|
|
|
this->TargetsToIgnoreRegex.clear();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!ignoreTargetsRegexes.empty()) {
|
2019-08-23 14:17:39 +00:00
|
|
|
std::vector<std::string> ignoreTargetsRegExVector =
|
|
|
|
cmExpandedList(ignoreTargetsRegexes);
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& currentRegexString : ignoreTargetsRegExVector) {
|
2011-02-05 18:09:54 +00:00
|
|
|
cmsys::RegularExpression currentRegex;
|
2018-01-25 13:59:33 +00:00
|
|
|
if (!currentRegex.compile(currentRegexString)) {
|
2011-02-05 18:09:54 +00:00
|
|
|
std::cerr << "Could not compile bad regex \"" << currentRegexString
|
|
|
|
<< "\"" << std::endl;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
2018-01-25 13:59:33 +00:00
|
|
|
this->TargetsToIgnoreRegex.push_back(std::move(currentRegex));
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::Write()
|
2011-02-06 17:34:48 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
auto gg = this->GlobalGenerator;
|
|
|
|
|
|
|
|
this->VisitGraph(gg->GetName());
|
|
|
|
|
|
|
|
// We want to traverse in a determined order, such that the output is always
|
|
|
|
// the same for a given project (this makes tests reproducible, etc.)
|
|
|
|
std::set<cmGeneratorTarget const*, cmGeneratorTarget::StrictTargetComparison>
|
|
|
|
sortedGeneratorTargets;
|
|
|
|
|
2019-12-09 17:13:42 +00:00
|
|
|
for (const auto& lg : gg->GetLocalGenerators()) {
|
2019-11-07 17:52:06 +00:00
|
|
|
for (const auto& gt : lg->GetGeneratorTargets()) {
|
2019-10-08 02:45:30 +00:00
|
|
|
// Reserved targets have inconsistent names across platforms (e.g. 'all'
|
|
|
|
// vs. 'ALL_BUILD'), which can disrupt the traversal ordering.
|
|
|
|
// We don't need or want them anyway.
|
|
|
|
if (!cmGlobalGenerator::IsReservedTarget(gt->GetName())) {
|
2019-11-07 17:52:06 +00:00
|
|
|
sortedGeneratorTargets.insert(gt.get());
|
2019-10-08 02:45:30 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-09 21:58:44 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
for (auto const gt : sortedGeneratorTargets) {
|
2020-02-13 16:12:34 +00:00
|
|
|
auto item = cmLinkItem(gt, false, gt->GetBacktrace());
|
2019-10-08 02:45:30 +00:00
|
|
|
this->VisitItem(item);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::WriteHeader(cmGeneratedFileStream& fs,
|
|
|
|
const std::string& name)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
auto const escapedGraphName = EscapeForDotFile(name);
|
|
|
|
fs << "digraph \"" << escapedGraphName << "\" {" << std::endl;
|
|
|
|
fs << this->GraphHeader << std::endl;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::WriteFooter(cmGeneratedFileStream& fs)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
fs << "}" << std::endl;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::WriteLegend(cmGeneratedFileStream& fs)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
// Note that the subgraph name must start with "cluster", as done here, to
|
|
|
|
// make Graphviz layout engines do the right thing and keep the nodes
|
|
|
|
// together.
|
|
|
|
fs << "subgraph clusterLegend {" << std::endl;
|
|
|
|
fs << " label = \"Legend\";" << std::endl;
|
|
|
|
// Set the color of the box surrounding the legend.
|
|
|
|
fs << " color = black;" << std::endl;
|
|
|
|
// We use invisible edges just to enforce the layout.
|
|
|
|
fs << " edge [ style = invis ];" << std::endl;
|
|
|
|
|
|
|
|
// Nodes.
|
|
|
|
fs << " legendNode0 [ label = \"Executable\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_EXECUTABLE << " ];" << std::endl;
|
|
|
|
|
|
|
|
fs << " legendNode1 [ label = \"Static Library\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_LIBRARY_STATIC << " ];" << std::endl;
|
|
|
|
fs << " legendNode2 [ label = \"Shared Library\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_LIBRARY_SHARED << " ];" << std::endl;
|
|
|
|
fs << " legendNode3 [ label = \"Module Library\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_LIBRARY_MODULE << " ];" << std::endl;
|
|
|
|
|
|
|
|
fs << " legendNode4 [ label = \"Interface Library\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_LIBRARY_INTERFACE << " ];" << std::endl;
|
|
|
|
fs << " legendNode5 [ label = \"Object Library\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_LIBRARY_OBJECT << " ];" << std::endl;
|
|
|
|
fs << " legendNode6 [ label = \"Unknown Library\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_LIBRARY_UNKNOWN << " ];" << std::endl;
|
|
|
|
|
|
|
|
fs << " legendNode7 [ label = \"Custom Target\", shape = "
|
|
|
|
<< GRAPHVIZ_NODE_SHAPE_UTILITY << " ];" << std::endl;
|
|
|
|
|
|
|
|
// Edges.
|
|
|
|
// Some of those are dummy (invisible) edges to enforce a layout.
|
|
|
|
fs << " legendNode0 -> legendNode1 [ style = " << GRAPHVIZ_EDGE_STYLE_PUBLIC
|
|
|
|
<< " ];" << std::endl;
|
|
|
|
fs << " legendNode0 -> legendNode2 [ style = " << GRAPHVIZ_EDGE_STYLE_PUBLIC
|
|
|
|
<< " ];" << std::endl;
|
|
|
|
fs << " legendNode0 -> legendNode3;" << std::endl;
|
|
|
|
|
|
|
|
fs << " legendNode1 -> legendNode4 [ label = \"Interface\", style = "
|
|
|
|
<< GRAPHVIZ_EDGE_STYLE_INTERFACE << " ];" << std::endl;
|
|
|
|
fs << " legendNode2 -> legendNode5 [ label = \"Private\", style = "
|
|
|
|
<< GRAPHVIZ_EDGE_STYLE_PRIVATE << " ];" << std::endl;
|
|
|
|
fs << " legendNode3 -> legendNode6 [ style = " << GRAPHVIZ_EDGE_STYLE_PUBLIC
|
|
|
|
<< " ];" << std::endl;
|
|
|
|
|
|
|
|
fs << " legendNode0 -> legendNode7;" << std::endl;
|
|
|
|
|
|
|
|
fs << "}" << std::endl;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::WriteNode(cmGeneratedFileStream& fs,
|
|
|
|
cmLinkItem const& item)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
auto const& itemName = item.AsStr();
|
|
|
|
auto const& nodeName = this->NodeNames[itemName];
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
auto const itemNameWithAliases = ItemNameWithAliases(itemName);
|
|
|
|
auto const escapedLabel = EscapeForDotFile(itemNameWithAliases);
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
fs << " \"" << nodeName << "\" [ label = \"" << escapedLabel
|
|
|
|
<< "\", shape = " << getShapeForTarget(item) << " ];" << std::endl;
|
|
|
|
}
|
2011-02-04 19:31:18 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
void cmGraphVizWriter::WriteConnection(cmGeneratedFileStream& fs,
|
|
|
|
cmLinkItem const& depender,
|
|
|
|
cmLinkItem const& dependee,
|
|
|
|
std::string const& edgeStyle)
|
|
|
|
{
|
|
|
|
auto const& dependerName = depender.AsStr();
|
|
|
|
auto const& dependeeName = dependee.AsStr();
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
fs << " \"" << this->NodeNames[dependerName] << "\" -> \""
|
|
|
|
<< this->NodeNames[dependeeName] << "\" ";
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
fs << edgeStyle;
|
2017-09-18 17:22:59 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
fs << " // " << dependerName << " -> " << dependeeName << std::endl;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
bool cmGraphVizWriter::ItemExcluded(cmLinkItem const& item)
|
2011-02-06 17:34:48 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
auto const itemName = item.AsStr();
|
2011-02-06 17:34:48 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (this->ItemNameFilteredOut(itemName)) {
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-02-06 17:34:48 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (item.Target == nullptr) {
|
|
|
|
return !this->GenerateForExternals;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-02-06 17:34:48 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (item.Target->GetType() == cmStateEnums::UTILITY) {
|
|
|
|
if ((itemName.find("Nightly") == 0) ||
|
|
|
|
(itemName.find("Continuous") == 0) ||
|
|
|
|
(itemName.find("Experimental") == 0)) {
|
|
|
|
return true;
|
2011-02-06 17:34:48 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-02-06 17:34:48 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (item.Target->IsImported() && !this->GenerateForExternals) {
|
|
|
|
return true;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
return !this->TargetTypeEnabled(item.Target->GetType());
|
2010-11-14 18:37:03 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
bool cmGraphVizWriter::ItemNameFilteredOut(std::string const& itemName)
|
2010-11-09 20:37:51 +00:00
|
|
|
{
|
2019-10-08 02:45:30 +00:00
|
|
|
if (itemName == ">") {
|
|
|
|
// FIXME: why do we even receive such a target here?
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
if (cmGlobalGenerator::IsReservedTarget(itemName)) {
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-11-09 20:37:51 +00:00
|
|
|
|
2017-09-11 10:40:26 +00:00
|
|
|
for (cmsys::RegularExpression& regEx : this->TargetsToIgnoreRegex) {
|
2016-05-16 14:34:04 +00:00
|
|
|
if (regEx.is_valid()) {
|
2019-10-08 02:45:30 +00:00
|
|
|
if (regEx.find(itemName)) {
|
2011-02-05 18:09:54 +00:00
|
|
|
return true;
|
2010-11-14 18:47:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-02-05 18:09:54 +00:00
|
|
|
|
|
|
|
return false;
|
2010-11-09 20:37:51 +00:00
|
|
|
}
|
2010-11-14 18:30:58 +00:00
|
|
|
|
2019-10-08 02:45:30 +00:00
|
|
|
bool cmGraphVizWriter::TargetTypeEnabled(
|
2016-10-18 19:28:46 +00:00
|
|
|
cmStateEnums::TargetType targetType) const
|
2010-11-14 18:30:58 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (targetType) {
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::EXECUTABLE:
|
2010-11-14 18:30:58 +00:00
|
|
|
return this->GenerateForExecutables;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::STATIC_LIBRARY:
|
2010-11-14 18:30:58 +00:00
|
|
|
return this->GenerateForStaticLibs;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::SHARED_LIBRARY:
|
2010-11-14 18:30:58 +00:00
|
|
|
return this->GenerateForSharedLibs;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::MODULE_LIBRARY:
|
2010-11-14 18:30:58 +00:00
|
|
|
return this->GenerateForModuleLibs;
|
2017-12-09 05:27:24 +00:00
|
|
|
case cmStateEnums::INTERFACE_LIBRARY:
|
2019-10-08 02:45:30 +00:00
|
|
|
return this->GenerateForInterfaceLibs;
|
|
|
|
case cmStateEnums::OBJECT_LIBRARY:
|
|
|
|
return this->GenerateForObjectLibs;
|
|
|
|
case cmStateEnums::UNKNOWN_LIBRARY:
|
|
|
|
return this->GenerateForUnknownLibs;
|
|
|
|
case cmStateEnums::UTILITY:
|
|
|
|
return this->GenerateForCustomTargets;
|
|
|
|
case cmStateEnums::GLOBAL_TARGET:
|
|
|
|
// Built-in targets like edit_cache, etc.
|
|
|
|
// We don't need/want those in the dot file.
|
|
|
|
return false;
|
2010-11-14 18:30:58 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-08 02:45:30 +00:00
|
|
|
|
|
|
|
std::string cmGraphVizWriter::ItemNameWithAliases(
|
|
|
|
std::string const& itemName) const
|
|
|
|
{
|
|
|
|
auto nameWithAliases = itemName;
|
|
|
|
|
|
|
|
for (auto const& lg : this->GlobalGenerator->GetLocalGenerators()) {
|
|
|
|
for (auto const& aliasTargets : lg->GetMakefile()->GetAliasTargets()) {
|
|
|
|
if (aliasTargets.second == itemName) {
|
|
|
|
nameWithAliases += "\\n(" + aliasTargets.first + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nameWithAliases;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmGraphVizWriter::GetEdgeStyle(DependencyType dt)
|
|
|
|
{
|
|
|
|
std::string style;
|
|
|
|
switch (dt) {
|
|
|
|
case DependencyType::LinkPrivate:
|
|
|
|
style = "[ style = " + std::string(GRAPHVIZ_EDGE_STYLE_PRIVATE) + " ]";
|
|
|
|
break;
|
|
|
|
case DependencyType::LinkInterface:
|
|
|
|
style = "[ style = " + std::string(GRAPHVIZ_EDGE_STYLE_INTERFACE) + " ]";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmGraphVizWriter::EscapeForDotFile(std::string const& str)
|
|
|
|
{
|
|
|
|
return cmSystemTools::EscapeChars(str.data(), "\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmGraphVizWriter::PathSafeString(std::string const& str)
|
|
|
|
{
|
|
|
|
std::string pathSafeStr;
|
|
|
|
|
|
|
|
// We'll only keep alphanumerical characters, plus the following ones that
|
|
|
|
// are common, and safe on all platforms:
|
|
|
|
auto const extra_chars = std::set<char>{ '.', '-', '_' };
|
|
|
|
|
|
|
|
for (char c : str) {
|
|
|
|
if (std::isalnum(c) || extra_chars.find(c) != extra_chars.cend()) {
|
|
|
|
pathSafeStr += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pathSafeStr;
|
|
|
|
}
|