Skip to content

Commit

Permalink
Merge pull request #5938 from smoogipoo/debug-disable-sgen
Browse files Browse the repository at this point in the history
Change source generators to only run for release builds
  • Loading branch information
peppy authored Jul 20, 2023
2 parents 4e468c4 + 49781c6 commit 07236ad
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 16 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ jobs:
fail-fast: false
matrix:
os:
- { prettyname: Windows, fullname: windows-latest }
- { prettyname: macOS, fullname: macos-latest }
- { prettyname: Linux, fullname: ubuntu-latest }
- { prettyname: Windows, fullname: windows-latest, configuration: Debug }
- { prettyname: macOS, fullname: macos-latest, configuration: Debug }
- { prettyname: Linux, fullname: ubuntu-latest, configuration: Debug }
- { prettyname: Linux, fullname: ubuntu-latest, configuration: Release }
threadingMode: ['SingleThread', 'MultiThreaded']
timeout-minutes: 60

Expand All @@ -84,10 +85,10 @@ jobs:
shell: bash

- name: Compile
run: dotnet build -c Debug -warnaserror osu-framework.Desktop.slnf
run: dotnet build -c ${{matrix.os.configuration}} -warnaserror osu-framework.Desktop.slnf

- name: Test
run: dotnet test $pwd/**/*.Tests/bin/Debug/*/*.Tests.dll --settings $pwd/build/vstestconfig.runsettings --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}-${{matrix.threadingMode}}.trx"
run: dotnet test $pwd/**/*.Tests/bin/${{matrix.os.configuration}}/*/*.Tests.dll --no-build --settings $pwd/build/vstestconfig.runsettings --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}-${{matrix.threadingMode}}-${{matrix.os.configuration}}.trx"
shell: pwsh

# Attempt to upload results even if test fails.
Expand All @@ -96,8 +97,8 @@ jobs:
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: osu-framework-test-results-${{matrix.os.prettyname}}-${{matrix.threadingMode}}
path: ${{github.workspace}}/TestResults/TestResults-${{matrix.os.prettyname}}-${{matrix.threadingMode}}.trx
name: osu-framework-test-results-${{matrix.os.prettyname}}-${{matrix.threadingMode}}-${{matrix.os.configuration}}
path: ${{github.workspace}}/TestResults/TestResults-${{matrix.os.prettyname}}-${{matrix.threadingMode}}-${{matrix.os.configuration}}.trx

build-only-android:
name: Build only (Android)
Expand Down
2 changes: 2 additions & 0 deletions osu-framework.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterHidesMember/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterOnlyUsedForPreconditionCheck_002EGlobal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ParameterOnlyUsedForPreconditionCheck_002ELocal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PartialMethodWithSinglePart/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PartialTypeWithSinglePart/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PatternAlwaysOfType/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleInterfaceMemberAmbiguity/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleMultipleEnumeration/@EntryIndexedValue">HINT</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public Test(
{
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using osu.Framework.SourceGeneration.Generators;

namespace osu.Framework.SourceGeneration.Tests.Verifiers
{
public partial class CSharpSourceGeneratorVerifier<TSourceGenerator>
where TSourceGenerator : IIncrementalGenerator, new()
where TSourceGenerator : AbstractIncrementalGenerator, new()
{
public static async Task VerifyAsync(
(string filename, string content)[] commonSources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;
using osu.Framework.SourceGeneration.Generators;

namespace osu.Framework.SourceGeneration.Tests.Verifiers
{
public partial class CSharpSourceGeneratorVerifier<TSourceGenerator>
where TSourceGenerator : IIncrementalGenerator, new()
where TSourceGenerator : AbstractIncrementalGenerator, new()
{
public class Test : CSharpSourceGeneratorTest<EmptySourceGeneratorProvider, XUnitVerifier>
{
public LanguageVersion LanguageVersion { get; set; } = LanguageVersion.Default;

protected override IEnumerable<ISourceGenerator> GetSourceGenerators() => new[]
{
new TSourceGenerator().AsSourceGenerator()
new TSourceGenerator { ForceRun = true }.AsSourceGenerator()
};

protected override ParseOptions CreateParseOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public abstract class AbstractIncrementalGenerator : IIncrementalGenerator
{
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.
Expand All @@ -22,6 +27,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
(n, _) => isSyntaxTarget(n),
(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)
.Select((t, _) => t.Item1)
.Select((t, _) => returnWithEvent(t.WithSemanticTarget(CreateSemanticTarget), EventDriver.OnSemanticTargetCreated));

// Stage 2: Separate out the old and new syntax targets for the same class object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;

namespace osu.Framework.SourceGeneration.Generators
{
Expand Down Expand Up @@ -47,7 +46,10 @@ public void OnEmit(IncrementalSemanticTarget candidate)
conditionalInvoke(Emit, candidate);
}

[Conditional("DEBUG")]
// Since we're running source generators in release configuration along with tests,
// we need this to always fire. Because we're not really worried about the compile
// overhead (due to only incurring on release builds) this isn't seen as a huge issue.
// [Conditional("DEBUG")]
private void conditionalInvoke<T>(Action<T>? @event, T arg)
{
@event?.Invoke(arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using osu.Framework.Allocation;
using osu.Framework.Testing.Dependencies;

// ReSharper disable ValueParameterNotUsed
#pragma warning disable IDE0052 // Unread private member
#pragma warning disable CS0169 // Private unused fields

namespace osu.Framework.Tests.Dependencies.Reflection
{
Expand Down Expand Up @@ -458,7 +460,6 @@ private class Provider22 : IDependencyInjectionCandidate
public object Provided1
{
get => null;
// ReSharper disable once ValueParameterNotUsed
set
{
}
Expand All @@ -470,7 +471,6 @@ private class Provider23 : IDependencyInjectionCandidate
[Cached]
public object Provided1
{
// ReSharper disable once ValueParameterNotUsed
set
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Testing.Dependencies;

#pragma warning disable IDE0052 // Unread private member
#pragma warning disable CS0169 // Private unused fields

namespace osu.Framework.Tests.Dependencies.SourceGeneration
{
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Drawable_HandleInputCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ internal static class HandleInputCache

public static bool RequestsPositionalInput(Drawable drawable)
{
// ReSharper disable once SuspiciousTypeConversion.Global (this is used by source generators, but only in release builds).
if (drawable is ISourceGeneratedHandleInputCache sgInput && sgInput.KnownType == drawable.GetType())
return sgInput.RequestsPositionalInput;

Expand All @@ -94,6 +95,7 @@ public static bool RequestsPositionalInput(Drawable drawable)

public static bool RequestsNonPositionalInput(Drawable drawable)
{
// ReSharper disable once SuspiciousTypeConversion.Global (this is used by source generators, but only in release builds).
if (drawable is ISourceGeneratedHandleInputCache sgInput && sgInput.KnownType == drawable.GetType())
return sgInput.RequestsNonPositionalInput;

Expand Down
1 change: 1 addition & 0 deletions osu.Framework/Graphics/Drawable_IsLongRunning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal bool IsLongRunning
{
get
{
// ReSharper disable once SuspiciousTypeConversion.Global (this is used by source generators, but only in release builds).
if (this is ISourceGeneratedLongRunningLoadCache sgCache && sgCache.KnownType == GetType())
return sgCache.IsLongRunning;

Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="ppy.osuTK.NS20" Version="1.0.211" />
<PackageReference Include="StbiSharp" Version="1.1.0" />
<PackageReference Include="ppy.SDL2-CS" Version="1.0.671-alpha" />
<PackageReference Include="ppy.osu.Framework.SourceGeneration" Version="2023.709.0" />
<PackageReference Include="ppy.osu.Framework.SourceGeneration" Version="2023.720.0" />

<!-- DO NOT use ProjectReference for native packaging project.
See https://github.com/NuGet/Home/issues/4514 and https://github.com/dotnet/sdk/issues/765 . -->
Expand Down

0 comments on commit 07236ad

Please sign in to comment.