diff options
| author | Miguel Costa <miguel.costa@qt.io> | 2025-11-13 20:06:42 +0100 |
|---|---|---|
| committer | Miguel Costa <miguel.costa@qt.io> | 2025-11-14 16:15:02 +0000 |
| commit | 33338888c2e9c19f9046a4c18a6924fbeb18ae25 (patch) | |
| tree | 3722d058e8a3c341bd074256d089cc96d2c4db79 | |
| parent | edb46ca50cca2d063b9bc4a6c62f3dbc7167192a (diff) | |
Remove graphviz dependency
Change-Id: I6790f92526c2042e8a921903034667f0420ba8c5
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
7 files changed, 3 insertions, 178 deletions
diff --git a/examples/Tutorial/Tutorial.csproj b/examples/Tutorial/Tutorial.csproj index 2855e70..9b853c3 100644 --- a/examples/Tutorial/Tutorial.csproj +++ b/examples/Tutorial/Tutorial.csproj @@ -19,9 +19,4 @@ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> - <PropertyGroup> - <QtGenCmd Condition="'$(QtGenCmd)' != '' AND '$(Configuration)' == 'Debug'" - >$(QtGenCmd) --graphviz "$(IntermediateOutputPath)qtdotnet\dependency_graph.pdf"</QtGenCmd> - </PropertyGroup> - </Project> diff --git a/examples/UserView/UserViewQml/UserViewQml.csproj b/examples/UserView/UserViewQml/UserViewQml.csproj index d8ebd5e..470d204 100644 --- a/examples/UserView/UserViewQml/UserViewQml.csproj +++ b/examples/UserView/UserViewQml/UserViewQml.csproj @@ -21,9 +21,4 @@ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> - <PropertyGroup> - <QtGenCmd Condition="'$(QtGenCmd)' != '' AND '$(Configuration)' == 'Debug'" - >$(QtGenCmd) --graphviz "$(IntermediateOutputPath)qtdotnet\dependency_graph.pdf"</QtGenCmd> - </PropertyGroup> - </Project> diff --git a/src/Qt.DotNet.Generator/Properties/launchSettings.json b/src/Qt.DotNet.Generator/Properties/launchSettings.json index 408fe7c..e08005a 100644 --- a/src/Qt.DotNet.Generator/Properties/launchSettings.json +++ b/src/Qt.DotNet.Generator/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Qt.DotNet.Generator": { "commandName": "Project", - "commandLineArgs": "--source \"$(SolutionDir)\\tests\\GeneratorTestApp\\obj\\Debug\\net8.0\\GeneratorTestApp.dll\" --graphviz dependency_graph.pdf --rules \"$(ProjectDir)\\..\\Qt.DotNet.GenerationRules\\bin\\$(Configuration)\\$(TargetFramework)\\Qt.DotNet.GenerationRules.dll\" --target \"$(SolutionDir)\\tests\\GeneratorTestApp\\obj\\Debug\\net8.0\\qtdotnet\\native\"" + "commandLineArgs": "--source \"$(SolutionDir)\\tests\\GeneratorTestApp\\obj\\Debug\\net8.0\\GeneratorTestApp.dll\" --rules \"$(ProjectDir)\\..\\Qt.DotNet.GenerationRules\\bin\\$(Configuration)\\$(TargetFramework)\\Qt.DotNet.GenerationRules.dll\" --target \"$(SolutionDir)\\tests\\GeneratorTestApp\\obj\\Debug\\net8.0\\qtdotnet\\native\"" } } }
\ No newline at end of file diff --git a/src/Qt.DotNet.Generator/Qt.DotNet.Generator.csproj b/src/Qt.DotNet.Generator/Qt.DotNet.Generator.csproj index 8169311..7898d7c 100644 --- a/src/Qt.DotNet.Generator/Qt.DotNet.Generator.csproj +++ b/src/Qt.DotNet.Generator/Qt.DotNet.Generator.csproj @@ -28,10 +28,6 @@ <ProjectReference Include="..\Qt.DotNet.Adapter\Qt.DotNet.Adapter.csproj" /> </ItemGroup> - <ItemGroup Condition="'$(Configuration)' == 'Debug'"> - <PackageReference Include="Rubjerg.Graphviz" Version="3.0.1" /> - </ItemGroup> - <PropertyGroup Condition="'$(Configuration)' == 'Debug'"> <ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch> </PropertyGroup> diff --git a/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/Generator.cs b/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/Generator.cs index f2c7a0f..65e1974 100644 --- a/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/Generator.cs +++ b/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/Generator.cs @@ -23,10 +23,7 @@ namespace Qt.DotNet.CodeGeneration SourceFileNotFound, GraphBuildError, GenerationError, - OutputError, -#if DEBUG - GraphVizError = 99 -#endif + OutputError } private static void Error(string msg) @@ -48,9 +45,6 @@ namespace Qt.DotNet.CodeGeneration public enum Options { -#if DEBUG - Graphviz, -#endif Source, Ref, Exclude, Target, Rules } @@ -82,14 +76,7 @@ namespace Qt.DotNet.CodeGeneration Options.Exclude, new Option<string[]>( "--exclude", "Exclude type from dependency graph") { Arity = ArgumentArity.ZeroOrMore } - }, -#if DEBUG - { - Options.Graphviz, new Option<string>( - "--graphviz", "Debug visualization") - { Arity = ArgumentArity.ZeroOrOne } } -#endif }; private static async Task<int> Main(string[] args) @@ -127,18 +114,7 @@ namespace Qt.DotNet.CodeGeneration await DependencyGraph.CreateAsync(loader, sourceAssembly, excludedTypes); if (Rules.SourceGraph == null) return Error(ctx, ExitCode.GraphBuildError, "Graph build error"); -#if DEBUG - if (ctx.TryGetValue(Options.Graphviz, out string graphVizPath)) { - try { - GraphViz - .FromDependencyGraph(Rules.SourceGraph) - .ToPdfFile(graphVizPath); - } catch (Exception ex) { - return Error(ctx, ExitCode.GraphVizError, - $"Error generating GraphViz content: '{ex.Message}'"); - } - } -#endif + if (!ctx.TryGetValue(Options.Target, out string targetPath)) return ExitCode.Ok; diff --git a/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/GraphViz.cs b/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/GraphViz.cs deleted file mode 100644 index 5f07606..0000000 --- a/src/Qt.DotNet.Generator/Qt/DotNet/CodeGeneration/GraphViz.cs +++ /dev/null @@ -1,132 +0,0 @@ -/*************************************************************************************************** - Copyright (C) 2025 The Qt Company Ltd. - SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only -***************************************************************************************************/ -#if DEBUG - -using System.Reflection; -using System.Text; -using System.Xml.Linq; -using Rubjerg.Graphviz; - -namespace Qt.DotNet.CodeGeneration -{ - public static class GraphViz - { - public static RootGraph FromDependencyGraph(DependencyGraph graph) - { - var graphViz = RootGraph.CreateNew(GraphType.Directed, "Assembly Dependency Graph"); - graphViz.SetAttribute("fontname", "Consolas"); - - foreach (var node in graph) { - var type = node.Key; - var gvNode = graphViz.GetOrAddNode(type.GetHashCode().ToString()); - - var baseTypes = type.GetInterfaces() - .OrderBy(x => x.Name) - .Prepend(type.BaseType) - .Where(x => graph.Keys.Contains(x)) - .Select(x => $"BASE {TypeLabel(x)}"); - var ctors = node.Value - .OfType<ConstructorInfo>() - .OrderBy(x => x.GetParameters().Length) - .Select(x => $"CTOR ({string - .Join(',', x.GetParameters().Select(y => TypeLabel(y.ParameterType)))})"); - var methods = node.Value - .OfType<MethodInfo>() - .OrderBy(x => x.IsStatic).ThenBy(x => x.Name) - .Select(x => $@" -{(x.IsStatic ? "STATIC " : "")}METHOD {TypeLabel(x.ReturnType)} {x.Name}({string - .Join(',', x.GetParameters().Select(y => TypeLabel(y.ParameterType)))})"); - var props = node.Value - .OfType<PropertyInfo>() - .OrderBy(x => (x.GetAccessors().FirstOrDefault()?.IsStatic == true)) - .ThenBy(x => x.Name) - .Select(x => $@" -{(x.GetAccessors().FirstOrDefault()?.IsStatic == true ? "STATIC " : "")} -PROPERTY {TypeLabel(x.PropertyType)} {x.Name}"); - var fields = node.Value - .OfType<FieldInfo>() - .Where(x => !x.IsLiteral) - .OrderBy(x => x.IsStatic).ThenBy(x => x.Name) - .Select(x => $@" -{(x.IsStatic ? "STATIC " : "")}FIELD {TypeLabel(x.FieldType)} {x.Name}"); - var consts = node.Value - .OfType<FieldInfo>() - .Where(x => x.IsLiteral) - .OrderBy(x => x.Name) - .Select(x => $"CONST {TypeLabel(x.FieldType)} {x.Name}"); - var events = node.Value - .OfType<EventInfo>() - .OrderBy(x => (x.AddMethod.IsStatic)).ThenBy(x => x.Name) - .Select(x => $@" -{(x.AddMethod.IsStatic ? "STATIC " : "")}EVENT {TypeLabel(x.EventHandlerType)} {x.Name}"); - var nestedTypes = node.Value - .OfType<TypeInfo>() - .OrderBy(x => x.Name) - .Select(x => $"TYPE {TypeLabel(x)}"); - var members = baseTypes - .Union(ctors) - .Union(methods) - .Union(props) - .Union(fields) - .Union(consts) - .Union(events) - .Union(nestedTypes); - - gvNode.SetAttribute("shape", "plaintext"); - var membersHtml = new StringBuilder(); - foreach (var member in members) { - membersHtml.Append($@" - <TR> - <TD ALIGN=""LEFT"">{member}</TD> - </TR>"); - } - gvNode.SetAttributeHtml("label", @$" -<FONT FACE=""Consolas"" POINT-SIZE=""{(type.IsRootNode() ? 24 : 14)}""> - <TABLE BORDER=""{(type.IsRootNode() ? 2 : 1)}"" CELLBORDER=""0"" CELLSPACING=""0""> - <TR> - <TD ALIGN=""LEFT"" BGCOLOR=""lightgray"" - ><SUP>{type.Namespace ?? "<B>ROOT</B>"}</SUP></TD> - </TR> - <TR> - <TD BORDER=""{(members.Any() ? 1 : 0)}"" SIDES=""B""><B>{TypeLabel(type)}</B></TD> - </TR> -{membersHtml} - </TABLE> -</FONT>"); - } - - foreach (var nodeFrom in graph.Keys) { - foreach (var nodeTo in graph.Connected(nodeFrom)) { - var edge = graphViz.GetOrAddEdge( - graphViz.GetNode(nodeFrom.GetHashCode().ToString()), - graphViz.GetNode(nodeTo.GetHashCode().ToString())); - edge.SetAttribute("color", "blue"); - } - } - - return graphViz; - } - - private static string TypeLabel(Type type) - { - if (type.IsRootNode()) - return type.Module.Name; - var typeName = type.Name.Replace("<", "<").Replace(">", ">"); - if (type.DeclaringType != null) - typeName = TypeLabel(type.DeclaringType) + "+" + typeName; - - return - type switch - { - { IsConstructedGenericType: true } => typeName.Split('`')[0] - + "<" - + string.Join(',', type.GenericTypeArguments.Select(t => TypeLabel(t))) - + ">", - _ => typeName.Split('`', StringSplitOptions.RemoveEmptyEntries)[0] - }; - } - } -} -#endif diff --git a/tests/GeneratorTestApp/GeneratorTestApp.csproj b/tests/GeneratorTestApp/GeneratorTestApp.csproj index 3208cd6..a8e2a1e 100644 --- a/tests/GeneratorTestApp/GeneratorTestApp.csproj +++ b/tests/GeneratorTestApp/GeneratorTestApp.csproj @@ -32,9 +32,4 @@ <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> - <PropertyGroup> - <QtGenCmd Condition="'$(QtGenCmd)' != '' AND '$(Configuration)' == 'Debug'" - >$(QtGenCmd) --graphviz "$(IntermediateOutputPath)qtdotnet\dependency_graph.pdf"</QtGenCmd> - </PropertyGroup> - </Project> |
