mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Enforce source generation testing with OptimizationLevel
This commit is contained in:
@@ -76,7 +76,7 @@ namespace osu.Framework.SourceGeneration.Tests
|
||||
{
|
||||
Compilation = CSharpCompilation.Create("test",
|
||||
references: new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) },
|
||||
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release));
|
||||
}
|
||||
|
||||
public GeneratorDriverRunResult RunGenerators(ref GeneratorDriver driver)
|
||||
|
||||
@@ -35,8 +35,6 @@ namespace osu.Framework.SourceGeneration.Tests.Verifiers
|
||||
driver = CSharpGeneratorDriver.Create(generator = new TSourceGenerator());
|
||||
driver = driver.WithUpdatedParseOptions(CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion));
|
||||
|
||||
generator.ForceRun = true;
|
||||
|
||||
this.commonSources = commonSources;
|
||||
this.commonGenerated = commonGenerated;
|
||||
this.multiPhaseSources = multiPhaseSources;
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace osu.Framework.SourceGeneration.Tests.Verifiers
|
||||
|
||||
protected override IEnumerable<Type> GetSourceGenerators() => [typeof(TSourceGenerator)];
|
||||
|
||||
protected override CompilationOptions CreateCompilationOptions()
|
||||
{
|
||||
return base.CreateCompilationOptions().WithOptimizationLevel(OptimizationLevel.Release);
|
||||
}
|
||||
|
||||
protected override ParseOptions CreateParseOptions()
|
||||
{
|
||||
return ((CSharpParseOptions)base.CreateParseOptions()).WithLanguageVersion(LanguageVersion);
|
||||
|
||||
@@ -14,11 +14,6 @@ namespace osu.Framework.SourceGeneration.Generators
|
||||
{
|
||||
public readonly GeneratorEventDriver EventDriver = new GeneratorEventDriver();
|
||||
|
||||
/// <summary>
|
||||
/// Whether the generator should be forcefully run, even if building as debug.
|
||||
/// </summary>
|
||||
public bool ForceRun;
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
// Stage 1: Create SyntaxTarget objects for all classes.
|
||||
@@ -28,7 +23,7 @@ namespace osu.Framework.SourceGeneration.Generators
|
||||
(ctx, _) => returnWithEvent(new IncrementalSyntaxTarget((ClassDeclarationSyntax)ctx.Node, ctx.SemanticModel), EventDriver.OnSyntaxTargetCreated))
|
||||
.Select((t, _) => t.WithName())
|
||||
.Combine(context.CompilationProvider)
|
||||
.Where(c => ForceRun || c.Right.Options.OptimizationLevel == OptimizationLevel.Release)
|
||||
.Where(c => c.Right.Options.OptimizationLevel == OptimizationLevel.Release)
|
||||
.Select((t, _) => t.Item1)
|
||||
.Select((t, _) => returnWithEvent(t.WithSemanticTarget(CreateSemanticTarget), EventDriver.OnSemanticTargetCreated));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user