Skip to content
Closed
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
29 changes: 29 additions & 0 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,35 @@
<Exec ConsoleToMsBuild="true" Command="$(DotnetCommand)" />
</Target>

<Target Name="BuildSqlClientNotSupportedSG"
DependsOnTargets="BuildSqlClientRef">

<PropertyGroup>
<DotnetCommand>
"$(DotnetPath)dotnet" build "$(SqlClientNotSupportedProjectPath)"
-v:minimal
-p:Configuration=$(Configuration)
-p:NotSupportedSG=true
$(SigningKeyPathArgument)

<!-- Versioning arguments -->
$(BuildNumberArgument)
$(BuildSuffixArgument)
$(PackageVersionSqlClientArgument)

<!-- Reference Type Arguments -->
$(ReferenceTypeArgument)
$(PackageVersionAbstractionsArgument)
$(PackageVersionLoggingArgument)
</DotnetCommand>
<!-- Convert more than one whitespace character into one space -->
<DotnetCommand>$([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " "))</DotnetCommand>
</PropertyGroup>

<Message Text=">>> Building source generated not supported binaries project via command: '$(DotnetCommand)'"/>
<Exec ConsoleToMsBuild="true" Command="$(DotnetCommand)" />
</Target>

<!-- BuildSqlClientRef: Builds the ref binaries project for SqlClient, which is OS-agnostic -->
<PropertyGroup>
<BuildSqlClientRefDependsOn Condition="'$(ReferenceType.ToLower())' == 'package' AND '$(SkipDependencyPack)' != 'true'">PackLogging;PackAbstractions;PackSqlServer</BuildSqlClientRefDependsOn>
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Data.SqlClient.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<Project Path="../tools/GenAPI/Microsoft.DotNet.GenAPI/Microsoft.DotNet.GenAPI.csproj">
<Build Project="false" />
</Project>
<Project Path="../tools/GenAPI/Microsoft.Data.SqlClient.SourceGenerator/Microsoft.Data.SqlClient.SourceGenerator.csproj" />
<Project Path="Microsoft.Data.SqlClient/notsupported/Microsoft.Data.SqlClient.csproj">
<Build Project="false" />
</Project>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<!--
Everybody hold onto your pants because this is going to get a bit ugly.

Expand Down Expand Up @@ -70,6 +70,8 @@

<!-- Disable obsolete member usage warning -->
<NoWarn>$(NoWarn);CS0618</NoWarn>

<DefineConstants Condition="'$(NotSupportedSG)' == 'true'">$(DefineConstants);NOTSUPPORTED</DefineConstants>
</PropertyGroup>

<!-- Versioning ====================================================== -->
Expand All @@ -94,6 +96,7 @@
nice to have a flatter directory structure, it's more hassle than its worth.
-->
<OutputPath>$(RepoRoot)artifacts/$(AssemblyName).notsupported/$(ReferenceType)-$(Configuration)/</OutputPath>
<OutputPath Condition="'$(NotSupportedSG)' == 'true'">$(RepoRoot)artifacts/$(AssemblyName).notsupported/$(ReferenceType)-$(Configuration)-SG/</OutputPath>
</PropertyGroup>

<!-- References ====================================================== -->
Expand Down Expand Up @@ -185,10 +188,20 @@

<!-- Generate "Not Supported" Source ================================= -->
<PropertyGroup>
<NotSupportedSourceFile>$(AssemblyName).$(TargetFramework).notsupported.cs</NotSupportedSourceFile>
<NotSupportedSourceFile Condition="'$(NotSupportedSG)' != 'true'">$(AssemblyName).$(TargetFramework).notsupported.cs</NotSupportedSourceFile>
<NotSupportedSourceFile Condition="'$(NotSupportedSG)' == 'true'">Microsoft.Data.SqlClient.SourceGenerator/Microsoft.Data.SqlClient.SourceGenerator.RefToNotSupportedGenerator/$(AssemblyName).$(TargetFramework).notsupported.g.cs</NotSupportedSourceFile>
</PropertyGroup>

<Target Name="BuildAndCompare"
Condition="'$(NotSupportedSG)' == 'true'"
BeforeTargets="CoreCompile">
<ItemGroup>
<Compile Include="$(NotSupportedSourceFile)" />
</ItemGroup>
</Target>

<Target Name="GenerateNotSupportedSource"
Condition="'$(NotSupportedSG)' != 'true'"
BeforeTargets="CoreCompile"
DependsOnTargets="ResolveReferences">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<!-- General Properties ============================================== -->
<PropertyGroup>
<AssemblyName>Microsoft.Data.SqlClient</AssemblyName>
Expand All @@ -8,6 +8,8 @@
<!-- Compiler Options ================================================ -->
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>../notsupported</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<!-- Versioning ====================================================== -->
Expand All @@ -21,6 +23,10 @@
<Version>$(SqlClientPackageVersion)</Version>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="TargetFramework" />
</ItemGroup>

<!-- CLS Compliance ================================================== -->
<ItemGroup>
<AssemblyAttribute Include="System.CLSCompliantAttribute">
Expand Down Expand Up @@ -91,6 +97,10 @@
<ItemGroup>
<ProjectReference Include="$(RepoRoot)src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj"
Condition="'$(ReferenceType)' != 'Package'" />
<ProjectReference Include="../../../tools/GenAPI/Microsoft.Data.SqlClient.SourceGenerator/Microsoft.Data.SqlClient.SourceGenerator.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Analyzer</OutputItemType>
</ProjectReference>
<PackageReference Include="Microsoft.Data.SqlClient.Extensions.Abstractions"
Condition="'$(ReferenceType)' == 'Package'" />
</ItemGroup>
Expand Down
33 changes: 17 additions & 16 deletions tools/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<!-- Tools dependencies -->
<ItemGroup>
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="2.3.0" />
<PackageVersion Include="Microsoft.Cci" Version="4.0.0-rc3-24214-00" />
<PackageVersion Include="System.Composition" Version="10.0.5" />
<PackageVersion Include="System.Diagnostics.Contracts" Version="4.3.0" />
<PackageVersion Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
<PackageVersion Include="System.Diagnostics.TraceSource" Version="4.3.0" />
<PackageVersion Include="System.IO.FileSystem" Version="4.3.0" />
<PackageVersion Include="System.Memory" Version="4.6.3" />
<PackageVersion Include="System.Reflection.Metadata" Version="10.0.3" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
</ItemGroup>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<!-- Tools dependencies -->
<ItemGroup>
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="2.3.0" />
<PackageVersion Include="Microsoft.Cci" Version="4.0.0-rc3-24214-00" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
<PackageVersion Include="System.Composition" Version="10.0.5" />
<PackageVersion Include="System.Diagnostics.Contracts" Version="4.3.0" />
<PackageVersion Include="System.Diagnostics.TextWriterTraceListener" Version="4.3.0" />
<PackageVersion Include="System.Diagnostics.TraceSource" Version="4.3.0" />
<PackageVersion Include="System.IO.FileSystem" Version="4.3.0" />
<PackageVersion Include="System.Memory" Version="4.6.3" />
<PackageVersion Include="System.Reflection.Metadata" Version="10.0.3" />
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsRoslynComponent>true</IsRoslynComponent>
<IncludeBuildOutput>false</IncludeBuildOutput>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>$(DefineConstants);GENAPI_COMPAT</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Debug SG": {
"commandName": "DebugRoslynComponent",
"targetProject": "..\\..\\..\\src\\Microsoft.Data.SqlClient\\ref\\Microsoft.Data.SqlClient.csproj"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Microsoft.Data.SqlClient.SourceGenerator
{
[Generator]
public class RefToNotSupportedGenerator : IIncrementalGenerator
{
private const string DefaultFileHeader =
"//------------------------------------------------------------------------------\r\n" +
"// <auto-generated>\r\n" +
"// This code was generated by a tool.\r\n" +
"// {0}\r\n" +
"//\r\n" +
"// Changes to this file may cause incorrect behavior and will be lost if\r\n" +
"// the code is regenerated.\r\n" +
"// </auto-generated>\r\n" +
"//------------------------------------------------------------------------------\r\n";

public void Initialize(IncrementalGeneratorInitializationContext context)
{
IncrementalValuesProvider<SyntaxNode> modelsProvider = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: (s, _) => IsSyntaxTargetForGeneration(s),
transform: (ctx, _) => ctx.Node)
.Where(m => m != null); // Filter out errors that we don't care about

var modelProvider = modelsProvider
.Collect()
.Combine(context.AnalyzerConfigOptionsProvider);

context.RegisterSourceOutput(
modelProvider,
(ctx, compilation) =>
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(DefaultFileHeader, nameof(RefToNotSupportedGenerator));
using (StringWriter writer = new StringWriter(sb))
{
if (!compilation.Right.GlobalOptions.TryGetValue("build_property.targetframework", out string framework))
{
throw new KeyNotFoundException("build_property.targetframework");
}

try
{
sb.AppendLine("using System;");
sb.AppendLine("#if NOTSUPPORTED");

RefToNotsupportedTypeRewriter visitor = new RefToNotsupportedTypeRewriter();
// Group all collected types by namespace. Expects source file name from ref library to match namespace of all incuded types
foreach (var group in compilation.Left
.GroupBy(c => c.GetLocation().SourceTree.FilePath)
.OrderBy(cg => cg.Key)
)
{

sb.Append("namespace ");
sb.AppendLine(Path.GetFileNameWithoutExtension(group.Key));
sb.AppendLine("{");
foreach (SyntaxNode model in group)
{
SyntaxNode result = visitor.Visit(model);
result.WriteTo(writer);
}
sb.AppendLine("}");
}

sb.AppendLine("#endif");

}
catch (Exception ex)
{
sb.AppendLine($"// Exception: {ex.Message}\r\n// StackTrace: {ex.StackTrace}");
}

ctx.AddSource($"Microsoft.Data.SqlClient.{framework}.notsupported.g.cs", sb.ToString());
}
});
}

private static bool IsSyntaxTargetForGeneration(SyntaxNode node)
{
// Public delegates
if (node is DelegateDeclarationSyntax membDecl && membDecl.Modifiers.Any(SyntaxKind.PublicKeyword))
{
return true;
}
// Public, or internal types
if (node is BaseTypeDeclarationSyntax typeDecl &&
(typeDecl.Modifiers.Any(SyntaxKind.PublicKeyword) || typeDecl.Modifiers.Any(SyntaxKind.InternalKeyword)))
{
return true;
}

return false;
}
}
}
Loading
Loading