Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically calculating the paths to the analyzers to use in MergeAnalyzerMetadata script #4247

Merged
merged 3 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 22 additions & 49 deletions scripts/MergeAnalyzerMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,15 @@ Write-Output "Restoring packages"
$Artifacts = Join-Path -Path $PSScriptRoot -ChildPath "\..\artifacts" -Resolve
$DiagToolPath = "$Artifacts\bin\DiagConfig\Debug\net8.0\*"
$Diags = (Resolve-Path $PSScriptRoot).Path + "\..\eng\Diags"
# Project which will be used to fetch the analyzer list.
$AsyncStateProjectPath = (Resolve-Path $PSScriptRoot).Path + "\..\test\Libraries\Microsoft.AspNetCore.AsyncState.Tests\Microsoft.AspNetCore.AsyncState.Tests.csproj"

# TODO: needs to be auto-generated. This is a dump of the Analyzers items when compiling test/libraries/microsoft.aspnetcore.asyncstate
$analyzers = @(
'C:\src\dotnet\extensions\.dotnet\sdk\8.0.100-preview.7.23360.1\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll'
'C:\src\dotnet\extensions\.dotnet\sdk\8.0.100-preview.7.23360.1\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll'
'C:\src\dotnet\extensions\.dotnet\sdk\8.0.100-preview.7.23360.1\Sdks\Microsoft.NET.Sdk\targets\..\codestyle\cs\Microsoft.CodeAnalysis.CodeStyle.dll'
'C:\src\dotnet\extensions\.dotnet\sdk\8.0.100-preview.7.23360.1\Sdks\Microsoft.NET.Sdk\targets\..\codestyle\cs\Microsoft.CodeAnalysis.CodeStyle.Fixes.dll'
'C:\src\dotnet\extensions\.dotnet\sdk\8.0.100-preview.7.23360.1\Sdks\Microsoft.NET.Sdk\targets\..\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll'
'C:\src\dotnet\extensions\.dotnet\sdk\8.0.100-preview.7.23360.1\Sdks\Microsoft.NET.Sdk\targets\..\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes.dll'
'C:\Users\mataille\.nuget\packages\microsoft.extensions.logging.abstractions\8.0.0-rc.1.23402.13\analyzers\dotnet\roslyn4.4\cs\Microsoft.Extensions.Logging.Generators.dll'
'C:\Users\mataille\.nuget\packages\microsoft.extensions.options\8.0.0-rc.1.23402.13\analyzers\dotnet\roslyn4.4\cs\Microsoft.Extensions.Options.SourceGeneration.dll'
'C:\Users\mataille\.nuget\packages\microsoft.net.illink.tasks\8.0.0-preview.7.23359.1\analyzers\dotnet\cs\ILLink.CodeFixProvider.dll'
'C:\Users\mataille\.nuget\packages\microsoft.net.illink.tasks\8.0.0-preview.7.23359.1\analyzers\dotnet\cs\ILLink.RoslynAnalyzer.dll'
'C:\Users\mataille\.nuget\packages\microsoft.visualstudio.threading.analyzers\17.5.22\analyzers\cs\Microsoft.VisualStudio.Threading.Analyzers.CSharp.dll'
'C:\Users\mataille\.nuget\packages\microsoft.visualstudio.threading.analyzers\17.5.22\analyzers\cs\Microsoft.VisualStudio.Threading.Analyzers.CodeFixes.dll'
'C:\Users\mataille\.nuget\packages\microsoft.visualstudio.threading.analyzers\17.5.22\analyzers\cs\Microsoft.VisualStudio.Threading.Analyzers.dll'
'C:\Users\mataille\.nuget\packages\sonaranalyzer.csharp\8.52.0.60960\analyzers\Google.Protobuf.dll'
'C:\Users\mataille\.nuget\packages\sonaranalyzer.csharp\8.52.0.60960\analyzers\SonarAnalyzer.CFG.dll'
'C:\Users\mataille\.nuget\packages\sonaranalyzer.csharp\8.52.0.60960\analyzers\SonarAnalyzer.CSharp.dll'
'C:\Users\mataille\.nuget\packages\sonaranalyzer.csharp\8.52.0.60960\analyzers\SonarAnalyzer.dll'
'C:\Users\mataille\.nuget\packages\stylecop.analyzers.unstable\1.2.0.507\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll'
'C:\Users\mataille\.nuget\packages\stylecop.analyzers.unstable\1.2.0.507\analyzers\dotnet\cs\StyleCop.Analyzers.dll'
'C:\src\dotnet\extensions\artifacts\bin\Microsoft.Analyzers.Extra\Debug\netstandard2.0\Microsoft.Analyzers.Extra.dll'
'C:\src\dotnet\extensions\artifacts\bin\Microsoft.Analyzers.Local\Debug\netstandard2.0\Microsoft.Analyzers.Local.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.NETCore.App.Ref\8.0.0-preview.7.23359.1\analyzers/dotnet/cs/Microsoft.Interop.ComInterfaceGenerator.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.NETCore.App.Ref\8.0.0-preview.7.23359.1\analyzers/dotnet/cs/Microsoft.Interop.JavaScript.JSImportGenerator.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.NETCore.App.Ref\8.0.0-preview.7.23359.1\analyzers/dotnet/cs/Microsoft.Interop.LibraryImportGenerator.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.NETCore.App.Ref\8.0.0-preview.7.23359.1\analyzers/dotnet/cs/Microsoft.Interop.SourceGeneration.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.NETCore.App.Ref\8.0.0-preview.7.23359.1\analyzers/dotnet/cs/System.Text.Json.SourceGeneration.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.NETCore.App.Ref\8.0.0-preview.7.23359.1\analyzers/dotnet/cs/System.Text.RegularExpressions.Generator.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.AspNetCore.App.Ref\8.0.0-preview.7.23359.2\analyzers/dotnet/cs/Microsoft.AspNetCore.App.Analyzers.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.AspNetCore.App.Ref\8.0.0-preview.7.23359.2\analyzers/dotnet/cs/Microsoft.AspNetCore.App.CodeFixes.dll'
'C:\src\dotnet\extensions\.dotnet\packs\Microsoft.AspNetCore.App.Ref\8.0.0-preview.7.23359.2\analyzers/dotnet/cs/Microsoft.AspNetCore.Components.Analyzers.dll'
'C:\Users\mataille\.nuget\packages\xunit.analyzers\1.1.0\analyzers\dotnet\cs\xunit.analyzers.dll'
'C:\Users\mataille\.nuget\packages\xunit.analyzers\1.1.0\analyzers\dotnet\cs\xunit.analyzers.fixes.dll'
)
# In this section, we dynamically fetch the list of analyzers we should use by calling a target from one project which will return us the full list. To do so,
# we must capture the msbuild output of the invocation of that target which returns a list of strings (one string for each line of output). Then we join all of these
# lines into a single one, and we use a simple Regex to get the full list of analyzers.
$_outputArray = & dotnet msbuild $AsyncStateProjectPath /t:GetAnalyzersPassedToCompiler /p:TargetFramework=net8.0
$_output = $_outputArray -join "`n"
$analyzers = $_output -match "Analyzers: (.+)$" | ForEach-Object { $matches[1] -split ',' }

Write-Output "Processing analyzer assemblies"

Expand All @@ -75,20 +48,20 @@ try {

Copy-Item -Path $DiagToolPath -Destination $tempDir

& .\DiagConfig.exe $Diags analyzer merge Microsoft.Analyzers.Extra.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.Analyzers.Local.dll
& .\DiagConfig.exe $Diags analyzer merge StyleCop.Analyzers.dll
& .\DiagConfig.exe $Diags analyzer merge SonarAnalyzer.CSharp.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.VisualStudio.Threading.Analyzers.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.VisualStudio.Threading.Analyzers.CSharp.dll
& .\DiagConfig.exe $Diags analyzer merge xunit.analyzers.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.CodeAnalysis.CodeStyle.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.CodeAnalysis.CSharp.CodeStyle.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.CodeAnalysis.NetAnalyzers.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll
& .\DiagConfig.exe $Diags analyzer merge ILlink.RoslynAnalyzer.dll
# & .\DiagConfig.exe $Diags analyzer merge Microsoft.AspNetCore.App.Analyzers.dll
& .\DiagConfig.exe $Diags analyzer merge Microsoft.AspNetCore.Components.Analyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.Analyzers.Extra.dll
joperezr marked this conversation as resolved.
Show resolved Hide resolved
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.Analyzers.Local.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge StyleCop.Analyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge SonarAnalyzer.CSharp.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.VisualStudio.Threading.Analyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.VisualStudio.Threading.Analyzers.CSharp.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge xunit.analyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.CodeAnalysis.CodeStyle.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.CodeAnalysis.CSharp.CodeStyle.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.CodeAnalysis.NetAnalyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge ILlink.RoslynAnalyzer.dll
# & dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.AspNetCore.App.Analyzers.dll
& dotnet exec .\DiagConfig.dll $Diags analyzer merge Microsoft.AspNetCore.Components.Analyzers.dll
} finally {
Pop-Location
Remove-Item -Path $tempDir -Recurse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<PropertyGroup>
<RootNamespace>Microsoft.AspNetCore.AsyncState.Test</RootNamespace>
<Description>Unit tests for Microsoft.AspNetCore.AsyncState.</Description>
<!-- Setting IsTrimmable to true so that the ILLink Analyzers are also used in this project. -->
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,4 +13,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>

<!-- This target will simply print out the full path to all of the Analyzers that get passed to the compiler each
time this project gets built. This is called from MergeAnalyzerMetadata.ps1 script in order to generate the
right config files. For more info, please check out the MergeAnalyzerMetadata.ps1 script in the scripts folder
located on the root of the repo. -->
<Target Name="GetAnalyzersPassedToCompiler"
DependsOnTargets="ResolveReferences">
<Message Importance="High" Text="Analyzers: @(Analyzer->'%(FullPath)', ',')" />
</Target>
</Project>