Merge pull request #71049 from alexdlm/dotnet-generator-selective-disable

Add fine-grained disabling of SourceGenerators
This commit is contained in:
Yuri Sizov 2023-03-31 12:56:03 +02:00 committed by GitHub
commit 8f6ce4c8f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 14 additions and 7 deletions

View file

@ -26,6 +26,12 @@ namespace Godot.SourceGenerators
toggle != null &&
toggle.Equals("true", StringComparison.OrdinalIgnoreCase);
public static bool IsGodotSourceGeneratorDisabled(this GeneratorExecutionContext context, string generatorName) =>
AreGodotSourceGeneratorsDisabled(context) ||
(context.TryGetGlobalAnalyzerProperty("GodotDisabledSourceGenerators", out string? disabledGenerators) &&
disabledGenerators != null &&
disabledGenerators.Split(';').Contains(generatorName));
public static bool InheritsFrom(this INamedTypeSymbol? symbol, string assemblyName, string typeFullName)
{
while (symbol != null)

View file

@ -1,6 +1,7 @@
<Project>
<ItemGroup>
<!-- $(GodotProjectDir) is defined by Godot.NET.Sdk -->
<CompilerVisibleProperty Include="GodotDisabledSourceGenerators" />
<CompilerVisibleProperty Include="GodotProjectDir" />
<CompilerVisibleProperty Include="GodotProjectDirBase64" />
<CompilerVisibleProperty Include="GodotSourceGenerators" />

View file

@ -13,7 +13,7 @@ namespace Godot.SourceGenerators
public void Execute(GeneratorExecutionContext context)
{
if (context.IsGodotToolsProject())
if (context.IsGodotToolsProject() || context.IsGodotSourceGeneratorDisabled("GodotPluginsInitializer"))
return;
string source =

View file

@ -16,7 +16,7 @@ namespace Godot.SourceGenerators
public void Execute(GeneratorExecutionContext context)
{
if (context.AreGodotSourceGeneratorsDisabled())
if (context.IsGodotSourceGeneratorDisabled("ScriptMethods"))
return;
INamedTypeSymbol[] godotClasses = context

View file

@ -14,7 +14,7 @@ namespace Godot.SourceGenerators
{
public void Execute(GeneratorExecutionContext context)
{
if (context.AreGodotSourceGeneratorsDisabled())
if (context.IsGodotSourceGeneratorDisabled("ScriptPathAttribute"))
return;
if (context.IsGodotToolsProject())

View file

@ -16,7 +16,7 @@ namespace Godot.SourceGenerators
public void Execute(GeneratorExecutionContext context)
{
if (context.AreGodotSourceGeneratorsDisabled())
if (context.IsGodotSourceGeneratorDisabled("ScriptProperties"))
return;
INamedTypeSymbol[] godotClasses = context

View file

@ -17,7 +17,7 @@ namespace Godot.SourceGenerators
public void Execute(GeneratorExecutionContext context)
{
if (context.AreGodotSourceGeneratorsDisabled())
if (context.IsGodotSourceGeneratorDisabled("ScriptPropertyDefVal"))
return;
INamedTypeSymbol[] godotClasses = context

View file

@ -16,7 +16,7 @@ namespace Godot.SourceGenerators
public void Execute(GeneratorExecutionContext context)
{
if (context.AreGodotSourceGeneratorsDisabled())
if (context.IsGodotSourceGeneratorDisabled("ScriptSerialization"))
return;
INamedTypeSymbol[] godotClasses = context

View file

@ -23,7 +23,7 @@ namespace Godot.SourceGenerators
public void Execute(GeneratorExecutionContext context)
{
if (context.AreGodotSourceGeneratorsDisabled())
if (context.IsGodotSourceGeneratorDisabled("ScriptSignals"))
return;
INamedTypeSymbol[] godotClasses = context