[Roslyn] Add base setup for a Roslyn integration into Stride.Core (#1847)
* Set up analyzer project to be included in every project * Create basic structure * Add Tests project * Remove generator, fixup tests * Remove test analyzer * Add compiler services to unit tests projects
This commit is contained in:
Родитель
c9ded2ea2e
Коммит
9f96ca3f99
|
@ -11,6 +11,7 @@ EndProject
|
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00-Targets.Private", "00-Targets.Private", "{97978864-95DD-43A6-9159-AA1C881BE99F}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\sources\native\Stride.Native.targets = ..\sources\native\Stride.Native.targets
|
||||
..\sources\targets\Stride.Core.CompilerServices.props = ..\sources\targets\Stride.Core.CompilerServices.props
|
||||
..\sources\targets\Stride.Core.PostSettings.Dependencies.targets = ..\sources\targets\Stride.Core.PostSettings.Dependencies.targets
|
||||
..\sources\targets\Stride.Core.props = ..\sources\targets\Stride.Core.props
|
||||
..\sources\targets\Stride.Core.TargetFrameworks.Editor.props = ..\sources\targets\Stride.Core.TargetFrameworks.Editor.props
|
||||
|
@ -315,6 +316,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stride.Importer.Assimp", ".
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stride.Importer.Common", "..\sources\tools\Stride.Importer.Common\Stride.Importer.Common.csproj", "{806AA078-6070-4BB6-B05B-6EE6B21B1CDE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stride.Core.CompilerServices", "..\sources\core\Stride.Core.CompilerServices\Stride.Core.CompilerServices.csproj", "{D62BBD65-AB1C-41C7-8EC3-88949993C71E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Stride.Core.CompilerServices.Tests", "..\sources\core\Stride.Core.CompilerServices.Tests\Stride.Core.CompilerServices.Tests.csproj", "{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -1402,6 +1407,30 @@ Global
|
|||
{806AA078-6070-4BB6-B05B-6EE6B21B1CDE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{806AA078-6070-4BB6-B05B-6EE6B21B1CDE}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{806AA078-6070-4BB6-B05B-6EE6B21B1CDE}.Release|Win32.Build.0 = Release|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Debug|Win32.Build.0 = Debug|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E}.Release|Win32.Build.0 = Release|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Debug|Win32.Build.0 = Debug|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE}.Release|Win32.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1520,6 +1549,8 @@ Global
|
|||
{1C94168A-3C0D-4C6B-883B-91627D2EF3A1} = {A7ED9F01-7D78-4381-90A6-D50E51C17250}
|
||||
{967BA05D-4AC4-4848-AEFD-894EF2309E4D} = {6F473FA6-4F8B-4FBA-AE33-EE5AF997D50C}
|
||||
{806AA078-6070-4BB6-B05B-6EE6B21B1CDE} = {6F473FA6-4F8B-4FBA-AE33-EE5AF997D50C}
|
||||
{D62BBD65-AB1C-41C7-8EC3-88949993C71E} = {2E93E2B5-4500-4E47-9B65-E705218AB578}
|
||||
{BACD76E5-35D0-4389-9BB9-8743AC4D89DE} = {22ADD4CD-092E-4ADC-A21E-64CF42230152}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FF877973-604D-4EA7-B5F5-A129961F9EF2}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
using System.Reflection;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
|
||||
namespace Stride.Core.CompilerServices.Tests
|
||||
{
|
||||
public static class CompilerUtils
|
||||
{
|
||||
private static string assembliesDirectory = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location);
|
||||
|
||||
/// <summary>
|
||||
/// Runs compilation over <paramref name="source"/> and applies generator <typeparamref name="TGenerator"/> over it.
|
||||
/// </summary>
|
||||
public static (Compilation Compilation, ImmutableArray<Diagnostic> Diagnostics) CompileWithGenerator<TGenerator>(string assemblyName, string source)
|
||||
where TGenerator : ISourceGenerator, new()
|
||||
{
|
||||
var generator = new TGenerator();
|
||||
GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);
|
||||
driver.RunGeneratorsAndUpdateCompilation(CreateCompilation(assemblyName, source), out var compilation, out var diagnostics);
|
||||
return (compilation, diagnostics);
|
||||
}
|
||||
|
||||
private static Compilation CreateCompilation(string assemblyName, string source)
|
||||
=> CSharpCompilation.Create(assemblyName,
|
||||
new[] { CSharpSyntaxTree.ParseText(source) },
|
||||
new[]
|
||||
{
|
||||
// System.Runtime.dll
|
||||
MetadataReference.CreateFromFile($"{assembliesDirectory}/System.Runtime.dll"),
|
||||
// System.Private.CoreLib.dll
|
||||
MetadataReference.CreateFromFile($"{assembliesDirectory}/System.Private.CoreLib.dll"),
|
||||
// Stride.Core.dll
|
||||
MetadataReference.CreateFromFile($"{assembliesDirectory}/Stride.Core.dll"),
|
||||
},
|
||||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<Project>
|
||||
<Import Project="..\..\targets\Stride.UnitTests.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
|
||||
<StrideAssemblyProcessor>true</StrideAssemblyProcessor>
|
||||
<StrideAssemblyProcessorOptions>--auto-module-initializer</StrideAssemblyProcessorOptions>
|
||||
<StrideBuildTags>Windows;Android;iOS</StrideBuildTags>
|
||||
<LangVersion>preview</LangVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\shared\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\tests\xunit.runner.stride\xunit.runner.stride.csproj" />
|
||||
<ProjectReference Include="..\Stride.Core\Stride.Core.csproj" ReferenceOutputAssembly="false" OutputItemType="Content" CopyToOutputDirectory="Always" />
|
||||
<ProjectReference Include="..\Stride.Core.CompilerServices\Stride.Core.CompilerServices.csproj" />
|
||||
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit " Version="1.1.1" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\targets\Stride.UnitTests.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,31 @@
|
|||
// This file together with the property in csproj looks at LAUNCH_DEBUGGER constant
|
||||
// If it is present it will launch the debugger when the assembly is loaded into MSBuild
|
||||
// Note that MSBuild can sometimes load multiple instances of the analyzer.
|
||||
//
|
||||
// The ModuleInitializerAttribute had to be defined as it's not present normally for netstandard2.0
|
||||
// but the C# compiler understands it anyways.
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
using System;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
||||
public sealed class ModuleInitializerAttribute : Attribute { }
|
||||
}
|
||||
|
||||
namespace Stride.Core.CompilerServices
|
||||
{
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public class DebugAttacher
|
||||
{
|
||||
[ModuleInitializer]
|
||||
public static void Attach()
|
||||
{
|
||||
#if LAUNCH_DEBUGGER
|
||||
Debugger.Launch();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<Project>
|
||||
<Import Project="..\..\targets\Stride.Core.props" />
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Description>Code generators for Stride.Core and its dependents</Description>
|
||||
<StrideSkipAutoPack>true</StrideSkipAutoPack>
|
||||
<Nullable>enable</Nullable>
|
||||
<!--<DefineConstants>LAUNCH_DEBUGGER;$(DefineConstants)</DefineConstants>-->
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\shared\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Analyzers\" />
|
||||
<Folder Include="CodeFixes\" />
|
||||
<Folder Include="Common\" />
|
||||
<Folder Include="Generators\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(StrideSdkTargets)" />
|
||||
</Project>
|
|
@ -21,7 +21,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="ServiceWire" Version="5.3.4" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.NETCore.Platforms" Version="6.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -33,6 +33,10 @@
|
|||
<None Include="build\**\*.targets" PackagePath="buildTransitive\" Pack="true" />
|
||||
<None Include="build\**\*.props" PackagePath="buildTransitive\" Pack="true" />
|
||||
<None Include="..\..\..\deps\AssemblyProcessor\**\*.*" Exclude="..\..\..\deps\AssemblyProcessor\.gitignore" PackagePath="tools\AssemblyProcessor\" Pack="true" />
|
||||
|
||||
<!-- The following line packages up the analyzer into Stride.Core - this way it will be transiently invoked in packages that depend on Stride.Core -->
|
||||
<!-- You need to rebuild this project if the file changes (VS caches it somewhere) -->
|
||||
<None Include="$(MSBuildThisFileDirectory)\..\Stride.Core.CompilerServices\bin\$(Configuration)\netstandard2.0\Stride.Core.CompilerServices.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Condition="!$(MSBuildProjectName.StartsWith(Stride.Core.CompilerServices))">
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)../core/Stride.Core.CompilerServices/Stride.Core.CompilerServices.csproj"
|
||||
OutputItemType="Analyzer"
|
||||
SetTargetFramework="TargetFramework=netstandard2.0"
|
||||
ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -244,6 +244,9 @@
|
|||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<!-- Include Stride analyzer/code generator -->
|
||||
<Import Project="$(MSBuildThisFileDirectory)Stride.Core.CompilerServices.props"/>
|
||||
|
||||
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition="'$(StrideProjectType)' != 'Cpp'" />
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -42,7 +42,10 @@
|
|||
BeforeTargets="CoreCompile"
|
||||
Condition="'$(StrideEnableCodeAnalysis)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Analyzer Remove="@(Analyzer)"/>
|
||||
<!-- We want to include Stride analyzers by default -->
|
||||
<AnalyzersNotToRemove Include="@(Analyzer)" Condition="$([System.String]::Copy(%(FullPath)).Contains('Stride'))" />
|
||||
<AnalyzersToRemove Include="@(Analyzer)" Exclude="@(AnalyzersNotToRemove)" />
|
||||
<Analyzer Remove="@(AnalyzersToRemove)"/>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
|
|
|
@ -25,5 +25,8 @@
|
|||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Include Stride analyzer/code generator -->
|
||||
<Import Project="$(MSBuildThisFileDirectory)Stride.Core.CompilerServices.props"/>
|
||||
|
||||
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче