Skip to content

Commit 2a98a93

Browse files
authored
CSHARP-5771: Install only required SDK/runtimes on EG test variants (#1797)
1 parent 4e2d73c commit 2a98a93

15 files changed

+249
-335
lines changed

build.cake

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ var mongoDbDriverPackageName = "MongoDB.Driver";
3131

3232
var solutionFile = solutionDirectory.CombineWithFilePath("CSharpDriver.sln");
3333
var solutionFullPath = solutionFile.FullPath;
34-
var srcProjectNames = new[]
35-
{
36-
"MongoDB.Bson",
37-
"MongoDB.Driver"
38-
};
3934

4035
Task("Default")
4136
.IsDependentOn("Test");
@@ -70,13 +65,6 @@ Task("Build")
7065
}
7166
};
7267

73-
if (buildConfig.IsReleaseMode)
74-
{
75-
Console.WriteLine("Build continuousIntegration is enabled");
76-
settings.MSBuildSettings = new DotNetMSBuildSettings();
77-
// configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.nupkg
78-
settings.MSBuildSettings.SetContinuousIntegrationBuild(continuousIntegrationBuild: true);
79-
}
8068
DotNetBuild(solutionFullPath, settings);
8169
});
8270

@@ -132,10 +120,6 @@ Task("Test")
132120
})
133121
.DeferOnError();
134122

135-
Task("TestNet472").IsDependentOn("Test");
136-
Task("TestNetStandard21").IsDependentOn("Test");
137-
Task("TestNet60").IsDependentOn("Test");
138-
139123
Task("TestAwsAuthentication")
140124
.IsDependentOn("Build")
141125
.DoesForEach(
@@ -184,10 +168,6 @@ Task("TestGssapi")
184168
action: (BuildConfig buildConfig, Path testProject) =>
185169
RunTests(buildConfig, testProject, filter: "Category=\"GssapiMechanism\""));
186170

187-
Task("TestGssapiNet472").IsDependentOn("TestGssapi");
188-
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
189-
Task("TestGssapiNet60").IsDependentOn("TestGssapi");
190-
191171
Task("TestMongoDbOidc")
192172
.IsDependentOn("Build")
193173
.DoesForEach(
@@ -208,35 +188,20 @@ Task("TestLoadBalanced")
208188
action: (BuildConfig buildConfig, Path testProject) =>
209189
RunTests(buildConfig, testProject, filter: "Category=\"SupportLoadBalancing\""));
210190

211-
Task("TestLoadBalancedNetStandard21").IsDependentOn("TestLoadBalanced");
212-
Task("TestLoadBalancedNet60").IsDependentOn("TestLoadBalanced");
213-
214-
Task("TestSocks5ProxyNet472").IsDependentOn("TestSocks5Proxy");
215-
Task("TestSocks5ProxyNetStandard21").IsDependentOn("TestSocks5Proxy");
216-
Task("TestSocks5ProxyNet60").IsDependentOn("TestSocks5Proxy");
217-
218191
Task("TestCsfleWithMockedKms")
219192
.IsDependentOn("TestLibMongoCrypt")
220193
.DoesForEach(
221194
items: GetFiles("./**/*.Tests.csproj"),
222195
action: (BuildConfig buildConfig, Path testProject) =>
223196
RunTests(buildConfig, testProject, filter: "Category=\"CSFLE\""));
224197

225-
Task("TestCsfleWithMockedKmsNet472").IsDependentOn("TestCsfleWithMockedKms");
226-
Task("TestCsfleWithMockedKmsNetStandard21").IsDependentOn("TestCsfleWithMockedKms");
227-
Task("TestCsfleWithMockedKmsNet60").IsDependentOn("TestCsfleWithMockedKms");
228-
229198
Task("TestCsfleWithMongocryptd")
230199
.IsDependentOn("TestLibMongoCrypt")
231200
.DoesForEach(
232201
items: GetFiles("./**/*.Tests.csproj"),
233202
action: (BuildConfig buildConfig, Path testProject) =>
234203
RunTests(buildConfig, testProject, filter: "Category=\"CSFLE\""));
235204

236-
Task("TestCsfleWithMongocryptdNet472").IsDependentOn("TestCsfleWithMongocryptd");
237-
Task("TestCsfleWithMongocryptdNetStandard21").IsDependentOn("TestCsfleWithMongocryptd");
238-
Task("TestCsfleWithMongocryptdNet60").IsDependentOn("TestCsfleWithMongocryptd");
239-
240205
Task("TestCsfleWithAzureKms")
241206
.IsDependentOn("TestLibMongoCrypt")
242207
.DoesForEach(
@@ -258,8 +223,6 @@ Task("TestX509")
258223
action: (BuildConfig buildConfig, Path testProject) =>
259224
RunTests(buildConfig, testProject, filter: "Category=\"X509\""));
260225

261-
Task("TestX509Net60").IsDependentOn("TestX509");
262-
263226
Task("TestSocks5Proxy")
264227
.IsDependentOn("Build")
265228
.DoesForEach(
@@ -376,12 +339,6 @@ Task("SmokeTests")
376339
});
377340
});
378341

379-
Task("SmokeTestsNet472").IsDependentOn("SmokeTests");
380-
Task("SmokeTestsNetCoreApp31").IsDependentOn("SmokeTests");
381-
Task("SmokeTestsNet50").IsDependentOn("SmokeTests");
382-
Task("SmokeTestsNet60").IsDependentOn("SmokeTests");
383-
Task("SmokeTestsNet80").IsDependentOn("SmokeTests");
384-
385342
Setup<BuildConfig>(
386343
setupContext =>
387344
{
@@ -392,37 +349,28 @@ Setup<BuildConfig>(
392349
var unknownArchitecture => throw new Exception($"Unknown CPU architecture: {unknownArchitecture}.")
393350
};
394351

395-
var lowerTarget = target.ToLowerInvariant();
396-
var framework = lowerTarget switch
352+
var framework = Environment.GetEnvironmentVariable("FRAMEWORK");
353+
if (string.Equals(framework, "netstandard2.1", StringComparison.InvariantCultureIgnoreCase))
397354
{
398-
string s when s.EndsWith("netstandard21") || s.EndsWith("netcoreapp31") => "netcoreapp3.1",
399-
string s when s.EndsWith("net472") => "net472",
400-
string s when s.EndsWith("net50") => "net5.0",
401-
string s when s.EndsWith("net60") => "net6.0",
402-
string s when s.EndsWith("net80") => "net8.0",
403-
_ => null
404-
};
405-
406-
var isReleaseMode = lowerTarget.StartsWith("package") || lowerTarget == "release";
407-
var packageVersion = lowerTarget.StartsWith("smoketests") ? Environment.GetEnvironmentVariable("PACKAGE_VERSION") : gitVersion.LegacySemVer;
355+
framework = "netcoreapp3.1";
356+
}
408357

409-
Console.WriteLine($"Framework: {framework ?? "null (not set)"}, TargetPlatform: {targetPlatform}, IsReleaseMode: {isReleaseMode}, PackageVersion: {packageVersion}");
358+
var packageVersion = target.ToLowerInvariant().StartsWith("smoketests") ? Environment.GetEnvironmentVariable("PACKAGE_VERSION") : gitVersion.LegacySemVer;
359+
Console.WriteLine($"Framework: {framework ?? "null (not set)"}, TargetPlatform: {targetPlatform}, PackageVersion: {packageVersion}");
410360

411-
return new BuildConfig(isReleaseMode, framework, targetPlatform, packageVersion);
361+
return new BuildConfig(framework, targetPlatform, packageVersion);
412362
});
413363

414364
RunTarget(target);
415365

416366
public class BuildConfig
417367
{
418-
public bool IsReleaseMode { get; }
419368
public string Framework { get; }
420369
public string PackageVersion { get; }
421370
public string TargetPlatform { get; }
422371

423-
public BuildConfig(bool isReleaseMode, string framework, string targetPlatform, string packageVersion)
372+
public BuildConfig(string framework, string targetPlatform, string packageVersion)
424373
{
425-
IsReleaseMode = isReleaseMode;
426374
Framework = framework;
427375
TargetPlatform = targetPlatform;
428376
PackageVersion = packageVersion;

build.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#!/usr/bin/env bash
22
CAKE_VERSION=2.3.0
3-
DOTNET_VERSION=8.0.204

build.ps1

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@ $DotNetChannel = 'LTS'
55
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
66

77
[string] $CakeVersion = ''
8-
[string] $DotNetVersion= ''
98
foreach($line in Get-Content (Join-Path $PSScriptRoot 'build.config'))
109
{
1110
if ($line -like 'CAKE_VERSION=*') {
1211
$CakeVersion = $line.SubString(13)
1312
}
14-
elseif ($line -like 'DOTNET_VERSION=*') {
15-
$DotNetVersion =$line.SubString(15)
16-
}
1713
}
1814

1915

20-
if ([string]::IsNullOrEmpty($CakeVersion) -or [string]::IsNullOrEmpty($DotNetVersion)) {
21-
'Failed to parse Cake / .NET Core SDK Version'
16+
if ([string]::IsNullOrEmpty($CakeVersion)) {
17+
'Failed to parse Cake Version'
2218
exit 1
2319
}
2420

@@ -46,81 +42,6 @@ if ($PSVersionTable.PSEdition -ne 'Core') {
4642
}
4743
}
4844

49-
###########################################################################
50-
# INSTALL .NET CORE CLI
51-
###########################################################################
52-
53-
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
54-
$env:DOTNET_CLI_TELEMETRY_OPTOUT=1
55-
$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
56-
57-
58-
Function Remove-PathVariable([string]$VariableToRemove)
59-
{
60-
$SplitChar = ';'
61-
if ($IsMacOS -or $IsLinux) {
62-
$SplitChar = ':'
63-
}
64-
65-
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
66-
if ($path -ne $null)
67-
{
68-
$newItems = $path.Split($SplitChar, [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
69-
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join($SplitChar, $newItems), "User")
70-
}
71-
72-
$path = [Environment]::GetEnvironmentVariable("PATH", "Process")
73-
if ($path -ne $null)
74-
{
75-
$newItems = $path.Split($SplitChar, [StringSplitOptions]::RemoveEmptyEntries) | Where-Object { "$($_)" -inotlike $VariableToRemove }
76-
[Environment]::SetEnvironmentVariable("PATH", [System.String]::Join($SplitChar, $newItems), "Process")
77-
}
78-
}
79-
80-
# Get .NET Core CLI path if installed.
81-
$FoundDotNetCliVersion = $null;
82-
if (Get-Command dotnet -ErrorAction SilentlyContinue) {
83-
$FoundDotNetCliVersion = dotnet --version;
84-
}
85-
86-
if($FoundDotNetCliVersion -ne $DotNetVersion) {
87-
$InstallPath = Join-Path $PSScriptRoot ".dotnet"
88-
if (!(Test-Path $InstallPath)) {
89-
New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null;
90-
}
91-
92-
# N.B. We explicitly install .NET Core 3.1 because .NET 5.0 SDK can build those TFMs
93-
# but will silently upgrade to a more recent runtime to execute tests if the desired runtime
94-
# isn't available. For example, `dotnet run --framework netcoreapp3.0` will silently run
95-
# on .NET 5.0 if .NET Core 3.0 and 3.1 aren't installed.
96-
# This solution is admittedly hacky as .NET Core 3.1 won't be installed if
97-
# $DOTNET_VERSION matches $DOTNET_INSTALLED_VERSION, but it minimizes the changes required
98-
# to install required dependencies on Evergreen.
99-
if ($IsMacOS -or $IsLinux) {
100-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.sh'
101-
(New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath);
102-
& bash $ScriptPath --install-dir "$InstallPath" --channel 3.1 --no-path
103-
& bash $ScriptPath --install-dir "$InstallPath" --channel 5.0 --no-path
104-
& bash $ScriptPath --install-dir "$InstallPath" --channel 6.0 --no-path
105-
& bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path
106-
107-
Remove-PathVariable "$InstallPath"
108-
$env:PATH = "$($InstallPath):$env:PATH"
109-
}
110-
else {
111-
$ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1'
112-
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath);
113-
& $ScriptPath -Channel 3.1 -InstallDir $InstallPath;
114-
& $ScriptPath -Channel 5.0 -InstallDir $InstallPath;
115-
& $ScriptPath -Channel 6.0 -InstallDir $InstallPath;
116-
& $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath;
117-
118-
Remove-PathVariable "$InstallPath"
119-
$env:PATH = "$InstallPath;$env:PATH"
120-
}
121-
$env:DOTNET_ROOT=$InstallPath
122-
}
123-
12445
###########################################################################
12546
# INSTALL CAKE
12647
###########################################################################

build.sh

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ TOOLS_DIR=$SCRIPT_DIR/tools
66
CAKE_EXE=$TOOLS_DIR/dotnet-cake
77
CAKE_PATH=$TOOLS_DIR/.store/cake.tool/$CAKE_VERSION
88

9-
if [ "$CAKE_VERSION" = "" ] || [ "$DOTNET_VERSION" = "" ]; then
10-
echo "An error occured while parsing Cake / .NET Core SDK version."
9+
if [ "$CAKE_VERSION" = "" ]; then
10+
echo "An error occured while parsing Cake version."
1111
exit 1
1212
fi
1313

@@ -16,48 +16,11 @@ if [ ! -d "$TOOLS_DIR" ]; then
1616
mkdir "$TOOLS_DIR"
1717
fi
1818

19-
###########################################################################
20-
# INSTALL .NET CORE CLI
21-
###########################################################################
22-
23-
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
24-
export DOTNET_CLI_TELEMETRY_OPTOUT=1
25-
export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
26-
export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
27-
28-
DOTNET_INSTALLED_VERSION=$(dotnet --version 2>&1)
29-
30-
if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then
31-
echo "Installing .NET CLI..."
32-
if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then
33-
mkdir "$SCRIPT_DIR/.dotnet"
34-
fi
35-
curl -Lfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.sh
36-
# N.B. We explicitly install .NET Core 3.1 because .NET 6.0 SDK can build those TFMs
37-
# but will silently upgrade to a more recent runtime to execute tests if the desired runtime
38-
# isn't available. For example, `dotnet run --framework netcoreapp3.0` will silently run
39-
# on .NET 6.0 if .NET Core 3.0 and 3.1 aren't installed.
40-
# This solution is admittedly hacky as .NET Core 3.1 won't be installed if
41-
# $DOTNET_VERSION matches $DOTNET_INSTALLED_VERSION, but it minimizes the changes required
42-
# to install required dependencies on Evergreen.
43-
# Since ARM64 support was first added in .NET 6.0, the following commands will install:
44-
# | CPU | 2.1 | 3.1 | Latest |
45-
# | x64 | x64 | x64 | x64 |
46-
# | arm64 | x64 | x64 | arm64 |
47-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 3.1 --architecture x64 --install-dir .dotnet --no-path
48-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 5.0 --architecture x64 --install-dir .dotnet --no-path
49-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --channel 6.0 --install-dir .dotnet --no-path
50-
bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path
51-
export PATH="$SCRIPT_DIR/.dotnet":$PATH
52-
export DOTNET_ROOT="$SCRIPT_DIR/.dotnet"
53-
fi
54-
5519
###########################################################################
5620
# INSTALL CAKE
5721
###########################################################################
5822

59-
CAKE_INSTALLED_VERSION=$(dotnet-cake --version 2>&1)
60-
23+
CAKE_INSTALLED_VERSION=$(dotnet-cake --version 2>&1) || true
6124
if [ "$CAKE_VERSION" != "$CAKE_INSTALLED_VERSION" ]; then
6225
if [ ! -f "$CAKE_EXE" ] || [ ! -d "$CAKE_PATH" ]; then
6326
if [ -f "$CAKE_EXE" ]; then

evergreen/compile.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)