Skip to content

Commit

Permalink
#47 Roslyn 4.8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Mar 24, 2024
1 parent 7751522 commit 09dbeaa
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ benchmarks/data/results/*.md
_ReSharper.Caches/
.idea
.logs
.packages

13 changes: 9 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
<Description>Coding in a pure DI paradigm without frameworks!</Description>
<Product>$(BasePackageId)</Product>
<Copyright>Copyright (C) $([System.DateTime]::Now.Year) Nikolay Pianikov</Copyright>
<AnalyzerRoslynVersion Condition="'$(AnalyzerRoslynVersion)'==''">4.3</AnalyzerRoslynVersion>
<AnalyzerRoslynPackageVersion Condition="'$(AnalyzerRoslynPackageVersion)'==''">4.3.1</AnalyzerRoslynPackageVersion>
<BaseIntermediateOutputPath>obj\roslyn$(AnalyzerRoslynVersion)</BaseIntermediateOutputPath>
<BaseOutputPath>bin\roslyn$(AnalyzerRoslynVersion)</BaseOutputPath>
<EnableWindowsTargeting>true</EnableWindowsTargeting>

<!--<AnalyzerRoslynVersion Condition="'$(AnalyzerRoslynVersion)'==''">4.3</AnalyzerRoslynVersion>
<AnalyzerRoslynPackageVersion Condition="'$(AnalyzerRoslynPackageVersion)'==''">4.3.1</AnalyzerRoslynPackageVersion>-->

<AnalyzerRoslynVersion Condition="'$(AnalyzerRoslynVersion)'==''">4.8</AnalyzerRoslynVersion>
<AnalyzerRoslynPackageVersion Condition="'$(AnalyzerRoslynPackageVersion)'==''">4.8.0</AnalyzerRoslynPackageVersion>

<RolsynVersions Condition="'$(RolsynVersions)'==''">ROSLYN4_8_OR_GREATER;ROSLYN4_3_OR_GREATER</RolsynVersions>
<DefineConstants>$(DefineConstants);$(RolsynVersions)</DefineConstants>
</PropertyGroup>

<Target Name="Info" BeforeTargets="Build">
Expand Down
1 change: 1 addition & 0 deletions Pure.DI.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=reentrancy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rewriter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rolsyn/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=seealso/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shroedingers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Singleline/@EntryIndexedValue">True</s:Boolean>
Expand Down
53 changes: 36 additions & 17 deletions build/GeneratorTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
namespace Build;

using System.IO.Compression;
using NuGet.Versioning;

internal class GeneratorTarget(
Settings settings,
Commands commands)
: IInitializable, ITarget<Package>
{
private const string PackagesDir = ".packages";

private string PackageName => $"Pure.DI.{settings.Version}.nupkg";

public Task InitializeAsync() => commands.Register(
this,
"Builds and tests generator",
Expand All @@ -27,37 +30,55 @@ public Task<Package> RunAsync(CancellationToken cancellationToken)
// Generator package
var generatorProjectDirectory = Path.Combine("src", "Pure.DI");
var generatorPackages = settings.CodeAnalysis
.Select(codeAnalysis => CreateGeneratorPackage(settings.Version, codeAnalysis, generatorProjectDirectory));
.Select(codeAnalysis => CreateGeneratorPackage(codeAnalysis, generatorProjectDirectory))
.ToList();

return Task.FromResult(
new Package(
Path.GetFullPath(MergeGeneratorPackages(settings.Version, generatorPackages, generatorProjectDirectory)),
Path.GetFullPath(MergeGeneratorPackages(generatorPackages, generatorProjectDirectory)),
true));
}

private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis codeAnalysis, string projectDirectory)
private string CreateGeneratorPackage(CodeAnalysis codeAnalysis, string projectDirectory)
{
var analyzerRoslynPackageVersion = codeAnalysis.AnalyzerRoslynPackageVersion;
var analyzerRoslynVersion = new Version(analyzerRoslynPackageVersion.Major, analyzerRoslynPackageVersion.Minor);
Info($"Build package for Roslyn {analyzerRoslynVersion}.");

var rolsynVersions = string.Join(
';',
settings.CodeAnalysis
.Where(i => i.AnalyzerRoslynPackageVersion <= codeAnalysis.AnalyzerRoslynPackageVersion)
.Select(i => $"ROSLYN{i.AnalyzerRoslynPackageVersion.Major}_{i.AnalyzerRoslynPackageVersion.Minor}_OR_GREATER"));

List<(string, string)> props =
[
("configuration", settings.Configuration),
("version", packageVersion.ToString()),
("version", settings.Version.ToString()),
("AnalyzerRoslynVersion", analyzerRoslynVersion.ToString()),
("AnalyzerRoslynPackageVersion", analyzerRoslynPackageVersion.ToString())
("AnalyzerRoslynPackageVersion", analyzerRoslynPackageVersion.ToString()),
("RolsynVersions", $"\"{rolsynVersions}\""),
];

if (settings.BuildServer)
{
props.Add(("CI", "true"));
}

new MSBuild()
var bin = Path.Combine(projectDirectory, "bin");
if (Directory.Exists(bin))
{
Directory.Delete(bin, true);
}

var obj = Path.Combine(projectDirectory, "obj");
if (Directory.Exists(obj))
{
Directory.Delete(obj, true);
}

new DotNetBuild()
.WithShortName($"Building {codeAnalysis.AnalyzerRoslynPackageVersion}")
.WithTarget("clean;rebuild")
.WithRestore(true)
.WithProps(props)
.Build()
.Succeed();
Expand All @@ -73,27 +94,25 @@ private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis
WriteLine(testResult.ToString(), Color.Details);
testResult.Succeed();

var packagePath = Path.Combine(PackagesDir, analyzerRoslynVersion.ToString());

new DotNetPack()
.WithShortName($"Packing {codeAnalysis.AnalyzerRoslynPackageVersion}")
.WithProps(props)
.WithConfiguration(settings.Configuration)
.WithNoBuild(true)
.WithNoLogo(true)
.WithProject(Path.Combine(projectDirectory, "Pure.DI.csproj"))
.WithOutput(Path.Combine(projectDirectory, packagePath))
.Build()
.Succeed();

return Path.Combine(
projectDirectory,
"bin",
$"roslyn{analyzerRoslynVersion}",
settings.Configuration,
$"Pure.DI.{packageVersion.ToString()}.nupkg");
return Path.Combine(projectDirectory, packagePath, PackageName);
}

private string MergeGeneratorPackages(NuGetVersion packageVersion, IEnumerable<string> mergingPackages, string projectDirectory)
private string MergeGeneratorPackages(IEnumerable<string> mergingPackages, string projectDirectory)
{
var targetPackage = Path.GetFullPath(Path.Combine(projectDirectory, "bin", settings.Configuration, $"Pure.DI.{packageVersion}.nupkg"));
var targetPackage = Path.GetFullPath(Path.Combine(projectDirectory, PackagesDir, PackageName));
Info($"Creating NuGet package {targetPackage}");
var targetDir = Path.GetDirectoryName(targetPackage);
if (!string.IsNullOrWhiteSpace(targetDir))
Expand Down
1 change: 1 addition & 0 deletions build/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class Settings(

public ImmutableArray<CodeAnalysis> CodeAnalysis { get; } =
[
new CodeAnalysis(new Version(4, 8, 0)),
new CodeAnalysis(new Version(4, 3, 1))
];

Expand Down

0 comments on commit 09dbeaa

Please sign in to comment.