Skip to content

VS-156: Support Strong Named 2.28 Driver #84

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

Merged
merged 16 commits into from
Jul 29, 2024
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
36 changes: 29 additions & 7 deletions MongoDB.Analyzer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{2D18C947
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "MongoDB.Analyzer.Tests.Common", "tests\MongoDB.Analyzer.Tests.Common\MongoDB.Analyzer.Tests.Common.shproj", "{4F59BE68-9AB5-4DCC-8049-04AD7BB36AB6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Analyzer.Tests.Common.ClassLibrary", "tests\MongoDB.Analyzer.Tests.Common.ClassLibrary\MongoDB.Analyzer.Tests.Common.ClassLibrary.csproj", "{41218684-A8E3-41AC-8F85-58B9B2F43B09}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "MongoDB.Analyzer.Tests.Common.TestCases", "tests\MongoDB.Analyzer.Tests.Common.TestCases\MongoDB.Analyzer.Tests.Common.TestCases.shproj", "{1845551F-DEFF-4082-B2DB-3548A44F83AF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoDB.Analyzer.Helpers", "src\MongoDB.Analyzer.Helpers\MongoDB.Analyzer.Helpers.csproj", "{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}"
Expand All @@ -26,32 +24,56 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Analyzer.Tests.Common.ClassLibrary", "tests\MongoDB.Analyzer.Tests.Common.ClassLibrary\MongoDB.Analyzer.Tests.Common.ClassLibrary.csproj", "{8335EFD4-C859-4E7B-B7D5-C57FC443700C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
DRIVER_2_27_OR_LOWER|Any CPU = DRIVER_2_27_OR_LOWER|Any CPU
DRIVER_2_28_OR_GREATER|Any CPU = DRIVER_2_28_OR_GREATER|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.Release|Any CPU.Build.0 = Release|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = Debug|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = Debug|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = Debug|Any CPU
{F65EE23C-7B5B-4B8B-B9A7-386D08BDD3F5}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = Debug|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Debug|Any CPU.Build.0 = Debug|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Release|Any CPU.ActiveCfg = Release|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.Release|Any CPU.Build.0 = Release|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = Debug|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = Debug|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = Debug|Any CPU
{612B7D09-FEF8-4C12-B31A-04B02EC1F297}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = Debug|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.Release|Any CPU.Build.0 = Release|Any CPU
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41218684-A8E3-41AC-8F85-58B9B2F43B09}.Release|Any CPU.Build.0 = Release|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = Debug|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = Debug|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = Debug|Any CPU
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = Debug|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Debug|Any CPU.ActiveCfg = DRIVER_2_19|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Debug|Any CPU.Build.0 = DRIVER_2_19|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Release|Any CPU.ActiveCfg = DRIVER_2_19|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.Release|Any CPU.Build.0 = DRIVER_2_19|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = DRIVER_2_12|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = DRIVER_2_12|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = DRIVER_2_12|Any CPU
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = DRIVER_2_12|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Debug|Any CPU.ActiveCfg = DRIVER_2_28_OR_GREATER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Debug|Any CPU.Build.0 = DRIVER_2_28_OR_GREATER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Release|Any CPU.ActiveCfg = DRIVER_2_27_OR_LOWER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.Release|Any CPU.Build.0 = DRIVER_2_27_OR_LOWER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_27_OR_LOWER|Any CPU.ActiveCfg = DRIVER_2_27_OR_LOWER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_27_OR_LOWER|Any CPU.Build.0 = DRIVER_2_27_OR_LOWER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_28_OR_GREATER|Any CPU.ActiveCfg = DRIVER_2_28_OR_GREATER|Any CPU
{8335EFD4-C859-4E7B-B7D5-C57FC443700C}.DRIVER_2_28_OR_GREATER|Any CPU.Build.0 = DRIVER_2_28_OR_GREATER|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -61,9 +83,9 @@ Global
{612B7D09-FEF8-4C12-B31A-04B02EC1F297} = {3CBBF53B-DAE1-49C2-A97D-19FC6DAF8867}
{ACB908A0-7F5C-44DA-B9D2-CCFBCAEADD1D} = {2D18C947-A75E-4330-A272-213658715E74}
{4F59BE68-9AB5-4DCC-8049-04AD7BB36AB6} = {2D18C947-A75E-4330-A272-213658715E74}
{41218684-A8E3-41AC-8F85-58B9B2F43B09} = {2D18C947-A75E-4330-A272-213658715E74}
{1845551F-DEFF-4082-B2DB-3548A44F83AF} = {2D18C947-A75E-4330-A272-213658715E74}
{C9D49CAA-3F1F-4969-BDC1-0D17F9DB2B65} = {3CBBF53B-DAE1-49C2-A97D-19FC6DAF8867}
{8335EFD4-C859-4E7B-B7D5-C57FC443700C} = {2D18C947-A75E-4330-A272-213658715E74}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92FC99D4-1527-4D7F-AD28-B0949CD5BE72}
Expand Down
3 changes: 2 additions & 1 deletion evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ echo Testing with driver: "${DRIVER_VERSION}" "${TARGET_FRAMEWORK}"

dotnet clean "./MongoDB.Analyzer.sln"

dotnet build "./tests/MongoDB.Analyzer.Tests.Common.ClassLibrary" -f netstandard2.0 -c Debug
dotnet build "./tests/MongoDB.Analyzer.Tests.Common.ClassLibrary" -f netstandard2.0 -c DRIVER_2_27_OR_LOWER
dotnet build "./tests/MongoDB.Analyzer.Tests.Common.ClassLibrary" -f netstandard2.0 -c DRIVER_2_28_OR_GREATER

dotnet test "./MongoDB.Analyzer.sln" -e DRIVER_VERSION="${DRIVER_VERSION}" --framework "${TARGET_FRAMEWORK}" -c Release --results-directory ./build/test-results --logger "junit;LogFileName=TEST-MongoDB.Analyzer.xml;FailureBodyFormat=Verbose"
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ namespace MongoDB.Analyzer.Core.Utilities;

internal static class AnalysisCodeGeneratorUtilities
{
private const string AnalysisAssemblyName = "DynamicProxyGenAssembly2";
private const string AnalysisAssemblyNameDriver_2_27_OrLower = "DynamicProxyGenAssembly2";
private const string AnalysisAssemblyNameDriver_2_28_OrGreater = "MongoDB.Analyzer.MQLGenerator";
private static readonly Version s_driverVersion_2_28 = new(2, 28);
private static readonly ImmutableArray<byte> s_publicKey = new byte[160] { 0, 36, 0, 0, 4, 128, 0, 0, 148, 0, 0, 0, 6, 2, 0, 0, 0, 36, 0, 0, 82, 83, 65, 49, 0, 4, 0, 0, 1, 0, 1, 0, 53, 40, 127, 13, 56, 131, 192, 160, 117, 200, 142, 12, 218, 60, 233, 59, 98, 16, 3, 236, 189, 94, 146, 13, 74, 140, 114, 56, 86, 79, 77, 47, 79, 104, 17, 106, 202, 40, 201, 178, 19, 65, 220, 58, 135, 118, 121, 193, 69, 86, 25, 43, 43, 47, 95, 226, 193, 29, 98, 78, 8, 148, 211, 8, 255, 123, 148, 191, 111, 215, 42, 239, 27, 65, 1, 127, 254, 37, 114, 233, 144, 25, 209, 198, 25, 99, 230, 140, 208, 237, 103, 115, 74, 66, 203, 51, 59, 128, 142, 56, 103, 203, 230, 49, 147, 114, 20, 227, 46, 64, 159, 177, 250, 98, 253, 182, 157, 73, 76, 37, 48, 230, 74, 64, 228, 23, 214, 238 }.ToImmutableArray();

public static Type CompileAndGetGeneratorType(AnalysisType analysisType, MongoAnalysisContext context, ReferencesContainer referencesContainer, IEnumerable<SyntaxTree> syntaxTrees)
{
var assemblyName = referencesContainer.Version >= s_driverVersion_2_28 ? AnalysisAssemblyNameDriver_2_28_OrGreater : AnalysisAssemblyNameDriver_2_27_OrLower;
var compilation = CSharpCompilation.Create(
AnalysisAssemblyName,
assemblyName,
syntaxTrees,
referencesContainer.References,
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, publicSign: true, cryptoPublicKey: s_publicKey));

using var memoryStream = new MemoryStream();
var emitResult = compilation.Emit(memoryStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9</LangVersion>
<Configurations>DRIVER_2_27_OR_LOWER;DRIVER_2_28_OR_GREATER</Configurations>
</PropertyGroup>

<Import Project="..\MongoDB.Analyzer.Tests.Common\MongoDB.Analyzer.Tests.Common.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.19.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="MongoDB.Driver" Version="2.12.4" Condition="'$(Configuration)' == 'DRIVER_2_27_OR_LOWER'" />
<PackageReference Include="MongoDB.Driver" Version="2.28.0" Condition="'$(Configuration)' == 'DRIVER_2_28_OR_GREATER'" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions tests/MongoDB.Analyzer.Tests.Common/DriverVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public static class DriverVersions
public const string V2_22_OrLower = "(, 2.23.0)";
public const string V2_23_OrGreater = "[2.23.0,)";
public const string V2_19_to_2_20= "[2.19.0, 2.20.0)";
public const string V2_27_OrLower = "(, 2.28.0)";
public const string V2_28_OrGreater = "[2.28.0, )";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static async Task<ImmutableArray<Diagnostic>> Analyze(
Common.LinqVersion linqVersion,
Common.PocoAnalysisVerbosity jsonAnalyzerVerbosity)
{
PathUtilities.VerifyTestDataModelAssembly();
var testDataModelAssembly = PathUtilities.GetTestDataModelAssemblyPath(driverVersion);

#if NET472
var netReferences = ReferenceAssemblies.NetFramework.Net472.Default.AddAssemblies(ImmutableArray.Create("System.Drawing"));
Expand All @@ -46,15 +46,15 @@ public static async Task<ImmutableArray<Diagnostic>> Analyze(

var allReferences = netReferences
.AddPackages(packages)
.AddAssemblies(ImmutableArray.Create(PathUtilities.TestDataModelAssemblyPath))
.AddAssemblies(ImmutableArray.Create(testDataModelAssembly))
.WithNuGetConfigFilePath(PathUtilities.NugetConfigPath);

var metadataReferences = await allReferences.ResolveAsync(LanguageNames.CSharp, default);

var testCodeText = File.ReadAllText(testCodeFilename);
var testCodeSyntaxTree = CSharpSyntaxTree.ParseText(testCodeText);
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);

var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
var compilation = CSharpCompilation.Create(
"TestAssembly",
new[] { testCodeSyntaxTree },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ static DriverVersionHelper()
// NuGetVersion.Parse("2.18.0"),
// NuGetVersion.Parse("2.19.0"),
// NuGetVersion.Parse("2.21.0"),
// NuGetVersion.Parse("2.25.0")
// }
// NuGetVersion.Parse("2.25.0"),
// NuGetVersion.Parse("2.27.0"),
// NuGetVersion.Parse("2.28.0")
// };
}

public static NuGetVersion[] FilterVersionForRange(string versionRange)
Expand Down
18 changes: 13 additions & 5 deletions tests/MongoDB.Analyzer.Tests/Infrastructure/PathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

using System.IO;
using MongoDB.Analyzer.Tests.Common;
using NuGet.Versioning;

namespace MongoDB.Analyzer.Tests.Infrastructure;

Expand All @@ -23,7 +25,8 @@ internal static class PathUtilities
private static readonly string s_projectParentFolderPrefix = Path.Combine("..", "..", "..", "..");
private static readonly string s_testCasesPath = GetFullPathRelativeToParent(s_testCasesBaseFolder);

public static string TestDataModelAssemblyPath { get; } = GetFullPathRelativeToParent("MongoDB.Analyzer.Tests.Common.ClassLibrary", "bin", "Debug", "netstandard2.0", "MongoDB.Analyzer.Tests.Common.ClassLibrary");
public static string TestDataModelAssemblyPathDriver_2_27_OrLower { get; } = GetFullPathRelativeToParent("MongoDB.Analyzer.Tests.Common.ClassLibrary", "bin", "DRIVER_2_27_OR_LOWER", "netstandard2.0", "MongoDB.Analyzer.Tests.Common.ClassLibrary");
public static string TestDataModelAssemblyPathDriver_2_28_OrGreater { get; } = GetFullPathRelativeToParent("MongoDB.Analyzer.Tests.Common.ClassLibrary", "bin", "DRIVER_2_28_OR_GREATER", "netstandard2.0", "MongoDB.Analyzer.Tests.Common.ClassLibrary");
public static string NugetConfigPath { get; } = GetFullPathRelativeToParent("..", "nuget.config");

public static string GetTestCaseFileFullPathFromName(string testCaseFullyQualifiedName)
Expand All @@ -37,15 +40,20 @@ public static string GetTestCaseFileFullPathFromName(string testCaseFullyQualifi
return result;
}

public static void VerifyTestDataModelAssembly()
public static string GetTestDataModelAssemblyPath(string driverVersion)
{
var fileName = $"{TestDataModelAssemblyPath}.dll";
if (!File.Exists(fileName))
var testDataModelAssembly = IsDriverVersion_2_28_OrGreater(driverVersion) ? TestDataModelAssemblyPathDriver_2_28_OrGreater : TestDataModelAssemblyPathDriver_2_27_OrLower;

if (!File.Exists($"{testDataModelAssembly}.dll"))
{
throw new FileNotFoundException($"DataModel assembly {fileName} not found", fileName);
throw new FileNotFoundException($"DataModel assembly {testDataModelAssembly} not found", testDataModelAssembly);
}

return testDataModelAssembly;
}

private static string GetFullPathRelativeToParent(params string[] pathComponents) =>
Path.GetFullPath(Path.Combine(s_projectParentFolderPrefix, pathComponents.Length == 1 ? pathComponents[0] : Path.Combine(pathComponents)));

private static bool IsDriverVersion_2_28_OrGreater(string driverVersion) => VersionRange.Parse(DriverVersions.V2_28_OrGreater).Satisfies(NuGetVersion.Parse(driverVersion));
}