diff --git a/utils/SkiaSharpGenerator/BaseTool.cs b/utils/SkiaSharpGenerator/BaseTool.cs index 474dbfc29..4c1b1ed20 100644 --- a/utils/SkiaSharpGenerator/BaseTool.cs +++ b/utils/SkiaSharpGenerator/BaseTool.cs @@ -330,6 +330,17 @@ namespace SkiaSharpGenerator } } + protected bool IncludeNamespace(string name) + { + foreach (var ns in config.Namespaces) + { + if (name.StartsWith(ns.Key) && ns.Value.Exclude == true) + return false; + } + + return true; + } + protected string GetNamespace(string name) { foreach (var ns in config.Namespaces) diff --git a/utils/SkiaSharpGenerator/ConfigJson/NamespaceMapping.cs b/utils/SkiaSharpGenerator/ConfigJson/NamespaceMapping.cs index d6589af3c..3d867ff4c 100644 --- a/utils/SkiaSharpGenerator/ConfigJson/NamespaceMapping.cs +++ b/utils/SkiaSharpGenerator/ConfigJson/NamespaceMapping.cs @@ -9,5 +9,8 @@ namespace SkiaSharpGenerator [JsonPropertyName("prefix")] public string? Prefix { get; set; } + + [JsonPropertyName("exclude")] + public bool? Exclude { get; set; } } } diff --git a/utils/SkiaSharpGenerator/Generate/Generator.cs b/utils/SkiaSharpGenerator/Generate/Generator.cs index 018bc1e03..cea06f3eb 100644 --- a/utils/SkiaSharpGenerator/Generate/Generator.cs +++ b/utils/SkiaSharpGenerator/Generate/Generator.cs @@ -72,6 +72,7 @@ namespace SkiaSharpGenerator var delegates = compilation.Typedefs .Where(t => t.ElementType.TypeKind == CppTypeKind.Pointer) + .Where(t => IncludeNamespace(t.GetDisplayName())) .OrderBy(t => t.GetDisplayName()) .GroupBy(t => GetNamespace(t.GetDisplayName())); @@ -149,6 +150,7 @@ namespace SkiaSharpGenerator var classes = compilation.Classes .Where(c => c.SizeOf != 0) + .Where(c => IncludeNamespace(c.GetDisplayName())) .OrderBy(c => c.GetDisplayName()) .GroupBy(c => GetNamespace(c.GetDisplayName())); @@ -313,6 +315,7 @@ namespace SkiaSharpGenerator writer.WriteLine($"#region Enums"); var enums = compilation.Enums + .Where(e => IncludeNamespace(e.GetDisplayName())) .OrderBy(e => e.GetDisplayName()) .GroupBy(e => GetNamespace(e.GetDisplayName())); @@ -437,6 +440,7 @@ namespace SkiaSharpGenerator Log?.LogVerbose(" Writing p/invokes..."); var functionGroups = compilation.Functions + .Where(f => IncludeNamespace(f.Name)) .OrderBy(f => f.Name) .GroupBy(f => f.Span.Start.File.ToLower().Replace("\\", "/")) .OrderBy(g => Path.GetDirectoryName(g.Key) + "/" + Path.GetFileName(g.Key));