Skip to content

Commit baf7553

Browse files
authored
Enable DotNet 3.1 local lambda debug support (#2119)
1 parent 6ef9e83 commit baf7553

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "feature",
3+
"description" : "Add support for debugging dotnet 3.1 local lambdas (requires minimum SAM CLI version of 1.4.0)"
4+
}

jetbrains-rider/src/software/aws/toolkits/jetbrains/services/lambda/LambdaDaemonHost.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.intellij.psi.SmartPointerManager
1919
import com.jetbrains.rdclient.util.idea.LifetimedProjectComponent
2020
import com.jetbrains.rider.model.lambdaDaemonModel
2121
import com.jetbrains.rider.projectView.solution
22-
import software.amazon.awssdk.services.lambda.model.Runtime
2322
import software.aws.toolkits.jetbrains.services.lambda.dotnet.DotNetLambdaHandlerResolver
2423
import software.aws.toolkits.jetbrains.services.lambda.dotnet.element.RiderLambdaHandlerFakePsiElement
2524
import software.aws.toolkits.jetbrains.services.lambda.execution.LambdaRunConfigurationType
@@ -96,12 +95,8 @@ class LambdaDaemonHost(project: Project) : LifetimedProjectComponent(project) {
9695
val configurationType = ConfigurationTypeUtil.findConfigurationType(LambdaRunConfigurationType::class.java)
9796
val runConfigurations = runManager.getConfigurationsList(configurationType)
9897

99-
val isDebug = executor is DefaultDebugExecutor
100-
10198
var settings = runConfigurations.filterIsInstance<LocalLambdaRunConfiguration>().firstOrNull { configuration ->
102-
configuration.handler() == handler &&
103-
// TODO: Get rid of the check when SAM CLI provide support for dotnet 3.1 lambda debug
104-
(if (isDebug) configuration.runtime() != Runtime.DOTNETCORE3_1 else true)
99+
configuration.handler() == handler
105100
}?.let { configuration ->
106101
runManager.findSettings(configuration)
107102
}
@@ -112,12 +107,7 @@ class LambdaDaemonHost(project: Project) : LifetimedProjectComponent(project) {
112107
val template = runManager.getConfigurationTemplate(factory)
113108

114109
val configuration = template.configuration as LocalLambdaRunConfiguration
115-
val activeRuntime = DotNetRuntimeUtils.getCurrentDotNetCoreRuntime()
116-
117-
// TODO: Get rid of the check when SAM CLI provide support for dotnet 3.1 lambda debug
118-
val runtime =
119-
if (isDebug && activeRuntime == Runtime.DOTNETCORE3_1) DotNetRuntimeUtils.defaultDotNetCoreRuntime
120-
else activeRuntime
110+
val runtime = DotNetRuntimeUtils.getCurrentDotNetCoreRuntime()
121111

122112
LocalLambdaRunConfigurationProducer.setAccountOptions(configuration)
123113
configuration.useHandler(runtime, handler)

jetbrains-rider/src/software/aws/toolkits/jetbrains/services/lambda/dotnet/DotNetSamDebugSupport.kt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import kotlinx.coroutines.launch
4141
import kotlinx.coroutines.withContext
4242
import org.jetbrains.concurrency.AsyncPromise
4343
import org.jetbrains.concurrency.Promise
44-
import software.amazon.awssdk.services.lambda.model.Runtime
4544
import software.aws.toolkits.jetbrains.services.lambda.execution.local.SamDebugSupport
4645
import software.aws.toolkits.jetbrains.services.lambda.execution.local.SamRunningState
4746
import software.aws.toolkits.jetbrains.utils.ApplicationThreadPoolScope
@@ -73,22 +72,20 @@ class DotNetSamDebugSupport : SamDebugSupport {
7372
private const val REMOTE_DEBUGGER_DIR = "/tmp/lambci_debug_files"
7473
private const val REMOTE_NETCORE_CLI_PATH = "/var/lang/bin/dotnet"
7574
private const val NUMBER_OF_DEBUG_PORTS = 2
75+
76+
private const val FIND_PID_SCRIPT =
77+
"""
78+
for i in `ls /proc/*/exe` ; do
79+
symlink=`readlink ${'$'}i 2>/dev/null`;
80+
if [[ "${'$'}symlink" == *"/dotnet" ]]; then
81+
echo ${'$'}i | sed -n 's/.*\/proc\/\(.*\)\/exe.*/\1/p'
82+
fi;
83+
done;
84+
"""
7685
}
7786

7887
override fun getDebugPorts(): List<Int> = NetUtils.findAvailableSocketPorts(NUMBER_OF_DEBUG_PORTS).toList()
7988

80-
/**
81-
* Check whether the JatBrains.Rider.Worker.Launcher app (that is required to run Debugger) is downloaded into Rider SDK.
82-
*/
83-
override fun isSupported(runtime: Runtime): Boolean {
84-
// TODO: Remove when SAM adds debug support
85-
if (runtime == Runtime.DOTNETCORE3_1) {
86-
return false
87-
}
88-
89-
return true
90-
}
91-
9289
override fun patchCommandLine(debugPorts: List<Int>, commandLine: GeneralCommandLine) {
9390
commandLine.withParameters("--debugger-path")
9491
.withParameters(DotNetDebuggerUtils.debuggerBinDir.path)
@@ -259,7 +256,7 @@ class DotNetSamDebugSupport : SamDebugSupport {
259256
dockerContainer,
260257
"/bin/sh",
261258
"-c",
262-
"""find /proc -mindepth 2 -maxdepth 2 -name exe -exec ls -l {} \; 2>/dev/null | grep -e '/dotnet$' | sed -n 's/.*\/proc\/\(.*\)\/exe.*/\1/p'"""
259+
FIND_PID_SCRIPT
263260
)
264261
).stdout.trim().nullize()
265262
}.toInt()

0 commit comments

Comments
 (0)