Skip to content

Commit

Permalink
Make UnionAttribute a direct reference
Browse files Browse the repository at this point in the history
- Splits the library into 2 projects, the attribute and the generator
- Moves common project items to the Directory.Build.props
- Updates Benchmarks to remove covering code that is no longer generated
- Updates tests to work with new project layout
- Adds SDK reference to PackAsAnalyzer
- Updates namespaces
  • Loading branch information
hwoodiwiss committed Jan 3, 2024
1 parent b750c4e commit 2b2de01
Show file tree
Hide file tree
Showing 27 changed files with 138 additions and 128 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# JetBrains IDE metadata
.idea/
23 changes: 23 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
<Project>
<Sdk Name="ViHo.PackAsAnalyzer" Version="1.0.1" />

<PropertyGroup>
<Nullable>enable</Nullable>
<Version>1.11.0</Version>
<SignAssembly>False</SignAssembly>
</PropertyGroup>

<PropertyGroup Label="Package Attributes">
<Authors>domn1995</Authors>
<Company />
<Description>A simple source generator for discriminated unions in C#.</Description>
<PackageProjectUrl>https://github.com/domn1995/dunet</PackageProjectUrl>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/domn1995/dunet</RepositoryUrl>
<PackageTags>source; generator; discriminated; union; functional; tagged;</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>https://github.com/domn1995/dunet/releases</PackageReleaseNotes>
<RepositoryType>git</RepositoryType>
<PackageIcon>favicon.png</PackageIcon>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
Expand All @@ -10,4 +28,9 @@
<Target Name="DotnetToolRestore" BeforeTargets="Restore">
<Exec Command="dotnet tool restore" />
</Target>

<ItemGroup Condition=" '$(IsPublishable)' == 'True' ">
<None Include="$(MSBuildThisFileDirectory)\README.md" Pack="true" PackagePath="\"/>
<None Include="$(MSBuildThisFileDirectory)\favicon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>
8 changes: 7 additions & 1 deletion Dunet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32519.379
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dunet", "src\Dunet.csproj", "{13C0B629-4C48-4C73-AECB-06A476871C5B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dunet.Generator", "src\Dunet.Generator\Dunet.Generator.csproj", "{13C0B629-4C48-4C73-AECB-06A476871C5B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dunet.Test", "test\Dunet.Test.csproj", "{573E6767-C044-415B-9AD3-A1734B0DD684}"
EndProject
Expand All @@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExpressionCalculatorWithSta
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dunet.Benchmark", "benchmark\Dunet.Benchmark\Dunet.Benchmark.csproj", "{44A04A62-D495-4450-8C15-2BD67DF5159A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dunet", "src\Dunet\Dunet.csproj", "{9CC5D86B-26B5-47B5-8305-D099B171B1CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -71,6 +73,10 @@ Global
{44A04A62-D495-4450-8C15-2BD67DF5159A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44A04A62-D495-4450-8C15-2BD67DF5159A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44A04A62-D495-4450-8C15-2BD67DF5159A}.Release|Any CPU.Build.0 = Release|Any CPU
{9CC5D86B-26B5-47B5-8305-D099B171B1CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9CC5D86B-26B5-47B5-8305-D099B171B1CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CC5D86B-26B5-47B5-8305-D099B171B1CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CC5D86B-26B5-47B5-8305-D099B171B1CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion benchmark/Dunet.Benchmark/Dunet.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Dunet.csproj" />
<ProjectReference Include="..\..\src\Dunet\Dunet.csproj" />
<ProjectReference Include="..\..\src\Dunet.Generator\Dunet.Generator.csproj" />
</ItemGroup>

</Project>
13 changes: 8 additions & 5 deletions benchmark/Dunet.Benchmark/SourceGeneratorBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using BenchmarkDotNet.Attributes;
using Dunet.UnionAttributeGeneration;
using Dunet.UnionGeneration;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System.Reflection;
using Dunet.Generator.UnionGeneration;

namespace Dunet.Benchmark;

Expand Down Expand Up @@ -58,9 +57,8 @@ partial record None();
throw new InvalidOperationException("Compilation returned null");

var unionGenerator = new UnionGenerator();
var unionAttributeGenerator = new UnionAttributeGenerator();

var driver = CSharpGeneratorDriver.Create(unionGenerator, unionAttributeGenerator);
var driver = CSharpGeneratorDriver.Create(unionGenerator);

return (compilation, driver);
}
Expand All @@ -87,7 +85,12 @@ private static Compilation CreateCompilation(params string[] sources) =>
sources.Select(static source => CSharpSyntaxTree.ParseText(source)),
new[]
{
MetadataReference.CreateFromFile(typeof(Binder).GetTypeInfo().Assembly.Location)
// Resolves to System.Private.CoreLib.dll
MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location),
// Resolves to System.Runtime.dll, which is needed for the Attribute type
// Can't use typeof(Attribute).GetTypeInfo().Assembly.Location because it resolves to System.Private.CoreLib.dll
MetadataReference.CreateFromFile(AppDomain.CurrentDomain.GetAssemblies().First(f => f.FullName?.Contains("System.Runtime") == true).Location),
MetadataReference.CreateFromFile(typeof(UnionAttribute).GetTypeInfo().Assembly.Location)
},
new CSharpCompilationOptions(OutputKind.ConsoleApplication)
);
Expand Down
2 changes: 1 addition & 1 deletion integration/Dunet.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dunet" Version="1.10.0" />
<PackageReference Include="Dunet" Version="1.11.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.4" />
Expand Down
30 changes: 30 additions & 0 deletions src/Dunet.Generator/Dunet.Generator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12.0</LangVersion>
<IsPublishable>True</IsPublishable>
<NoWarn>$(NoWarn);NU5128</NoWarn>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<RootNamespace>Dunet.Generator</RootNamespace>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>

<ItemGroup>
<None Include="$(OutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dunet;
namespace Dunet.Generator;

internal static class IdentifierExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Dunet;
namespace Dunet.Generator;

internal static class SyntaxExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Dunet.Generator.UnionAttributeGeneration;

internal static class UnionAttributeSource
{
public const string Namespace = "Dunet";
public const string Name = "UnionAttribute";
public const string FullyQualifiedName = $"{Namespace}.{Name}";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Dunet.UnionGeneration;
using System.Text;
using System.Text;
using Dunet.Generator.UnionGeneration;

namespace Dunet.UnionExtensionsGeneration;
namespace Dunet.Generator.UnionExtensionsGeneration;

internal static class UnionExtensionsSourceBuilder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
namespace Dunet.UnionGeneration;
using System.Collections;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Dunet.Generator.UnionGeneration;

public static class ImmutableEquatableArray
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.CodeAnalysis;

namespace Dunet.UnionGeneration;
namespace Dunet.Generator.UnionGeneration;

/// <summary>
/// Provides extension methods for an <see cref="IncrementalValuesProvider{TValues}"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Dunet.UnionAttributeGeneration;
using Dunet.Generator.UnionAttributeGeneration;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Dunet.UnionGeneration;
namespace Dunet.Generator.UnionGeneration;

/// <summary>
/// Retrieves semantic information from record declarations.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text;

namespace Dunet.UnionGeneration;
namespace Dunet.Generator.UnionGeneration;

internal static class StringBuilderExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.CodeAnalysis;

namespace Dunet.UnionGeneration;
namespace Dunet.Generator.UnionGeneration;

internal sealed record UnionDeclaration(
ImmutableEquatableArray<string> Imports,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Dunet.UnionExtensionsGeneration;
using System.Collections.Immutable;
using System.Text;
using Dunet.Generator.UnionExtensionsGeneration;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using System.Collections.Immutable;
using System.Text;

namespace Dunet.UnionGeneration;
namespace Dunet.Generator.UnionGeneration;

[Generator]
public sealed class UnionGenerator : IIncrementalGenerator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text;

namespace Dunet.UnionGeneration;
namespace Dunet.Generator.UnionGeneration;

internal static class UnionSourceBuilder
{
Expand Down
52 changes: 0 additions & 52 deletions src/Dunet.csproj

This file was deleted.

15 changes: 15 additions & 0 deletions src/Dunet/Dunet.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12.0</LangVersion>
<IsPublishable>True</IsPublishable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Dunet.Generator\Dunet.Generator.csproj" PackAsAnalyzer="true" PrivateAssets="all" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions src/Dunet/UnionAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Dunet;

/// <summary>
/// Enables dunet union source generation for the decorated partial record.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class UnionAttribute : Attribute {}
18 changes: 0 additions & 18 deletions src/UnionAttributeGeneration/UnionAttributeGenerator.cs

This file was deleted.

20 changes: 0 additions & 20 deletions src/UnionAttributeGeneration/UnionAttributeSource.cs

This file was deleted.

Loading

0 comments on commit 2b2de01

Please sign in to comment.