Skip to content

Commit 4de7d7b

Browse files
authored
Move .NET 6 SDK hack from buildspec to test base (#3095)
1 parent f929931 commit 4de7d7b

File tree

5 files changed

+60
-12
lines changed

5 files changed

+60
-12
lines changed

buildspec/linuxIntegrationTests.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ phases:
1919
- export DOCKER_USERNAME=`echo $DOCKER_HUB_TOKEN | jq -r '.username'`
2020
- export DOCKER_PASSWORD=`echo $DOCKER_HUB_TOKEN | jq -r '.password'`
2121
- docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD || true
22-
- |
23-
if [ "$ALTERNATIVE_IDE_PROFILE_NAME" != "2021.1" ]; then
24-
DOTNET_ROOT="/root/.dotnet" /usr/local/bin/dotnet-install.sh --channel 6.0
25-
fi
22+
- DOTNET_ROOT="/root/.dotnet" /usr/local/bin/dotnet-install.sh --channel 6.0
2623

2724
build:
2825
commands:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package base
5+
6+
import com.jetbrains.rider.test.scriptingApi.setUpCustomToolset
7+
8+
// FIX_WHEN_MIN_IS_221: signature changed in 221
9+
fun setUpCustomToolset(path: String, host: com.jetbrains.rdclient.protocol.IProtocolHost) =
10+
setUpCustomToolset(path)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package base
5+
6+
import com.jetbrains.rider.test.scriptingApi.setUpCustomToolset
7+
8+
// FIX_WHEN_MIN_IS_221: signature changed in 221
9+
fun setUpCustomToolset(path: String, host: com.jetbrains.rdclient.protocol.IProtocolHost) =
10+
setUpCustomToolset(path, host)

jetbrains-rider/tst/base/AwsReuseSolutionTestBase.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
package base
55

66
import com.intellij.ide.GeneralSettings
7+
import com.intellij.openapi.application.ApplicationManager
78
import com.intellij.openapi.project.Project
89
import com.jetbrains.rider.projectView.solutionDirectory
910
import com.jetbrains.rider.test.base.BaseTestWithSolutionBase
1011
import com.jetbrains.rider.test.debugger.XDebuggerTestHelper
12+
import com.jetbrains.rider.test.protocol.testProtocolHost
1113
import com.jetbrains.rider.test.scriptingApi.getVirtualFileFromPath
1214
import com.jetbrains.rider.test.scriptingApi.useCachedTemplates
1315
import org.testng.annotations.AfterClass
@@ -47,6 +49,8 @@ abstract class AwsReuseSolutionTestBase : BaseTestWithSolutionBase() {
4749

4850
@BeforeClass(alwaysRun = true)
4951
fun setUpClassSolution() {
52+
val host = ApplicationManager.getApplication().testProtocolHost
53+
setUpCustomToolset(msBuild, host)
5054
openSolution(getSolutionDirectoryName())
5155
}
5256

jetbrains-rider/tst/base/RiderTestFrameworkUtils.kt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,51 @@ package base
55

66
import com.intellij.execution.configurations.GeneralCommandLine
77
import com.intellij.execution.util.ExecUtil
8+
import com.intellij.openapi.application.ApplicationInfo
89
import com.intellij.openapi.application.ApplicationManager
910
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
11+
import com.intellij.util.text.SemVer
1012
import com.jetbrains.rider.test.base.PrepareTestEnvironment
1113
import java.io.File
14+
import java.nio.file.Paths
1215

13-
val dotNetSdk by lazy {
14-
val output = ExecUtil.execAndGetOutput(GeneralCommandLine("dotnet", "--version"))
15-
if (output.exitCode == 0) {
16-
"C:\\Program Files\\dotnet\\sdk\\${output.stdout.trim()}".also {
17-
println("Using dotnet SDK at $it")
18-
}
19-
} else {
16+
val versions by lazy {
17+
// would be nice if this were json https://github.com/dotnet/runtime/issues/3049
18+
val output = ExecUtil.execAndGetOutput(GeneralCommandLine("dotnet", "--list-sdks"))
19+
if (output.exitCode != 0) {
2020
throw IllegalStateException("Failed to locate dotnet version: ${output.stderr}")
2121
}
22+
23+
output.stdout.trim().lines().map {
24+
val (version, path) = it.split(' ', limit = 2)
25+
val sdkSemVer = SemVer.parseFromText(version) ?: throw RuntimeException("Could not parse .NET SDK version as SemVar: $version")
26+
sdkSemVer to path.trim('[', ']')
27+
}.sortedByDescending { it.first }
28+
}
29+
30+
val dotNetSdk by lazy {
31+
val version = ApplicationInfo.getInstance().build.baselineVersion
32+
33+
val sdk = when {
34+
// FIX_WHEN_MIN_IS_212: Rider is not aware of .NET 6.0 until 212
35+
version < 212 ->
36+
versions.firstOrNull { it.first.major < 6 }
37+
?: throw RuntimeException("Current IDE profile '$version' requires .NET < 6, but only found: $versions")
38+
// otherwise use latest
39+
else -> versions.first()
40+
}
41+
42+
val (sdkVersion, sdkRoot) = sdk
43+
val sdkVersionFolder = sdkVersion.rawVersion
44+
val sdkPath = Paths.get(sdkRoot, sdkVersionFolder).toAbsolutePath().toString()
45+
46+
println("Using .NET SDK '$sdkVersionFolder' at path: '$sdkPath'")
47+
48+
return@lazy sdkPath
2249
}
2350

2451
val msBuild by lazy {
25-
"${dotNetSdk}\\MSBuild.dll"
52+
Paths.get(dotNetSdk, "MSBuild.dll").toAbsolutePath().toString()
2653
}
2754

2855
// TODO: Remove when https://youtrack.jetbrains.com/issue/RIDER-47995 is fixed FIX_WHEN_MIN_IS_212

0 commit comments

Comments
 (0)