Skip to content

Commit 04037e1

Browse files
authored
Merge #3864 csharp/.NET SAM lambda debugging
2 parents c3baa6b + 000c32c commit 04037e1

File tree

7 files changed

+52
-10
lines changed

7 files changed

+52
-10
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "SAM: local debugging of a .NET lambda may fail if `containerbuild=true`"
4+
}

src/shared/extensions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const VSCODE_EXTENSION_ID = {
2121
go: 'golang.go',
2222
java: 'redhat.java',
2323
javadebug: 'vscjava.vscode-java-debug',
24+
dotnet: 'ms-dotnettools.csdevkit',
2425
git: 'vscode.git',
2526
remotessh: 'ms-vscode-remote.remote-ssh',
2627
}

src/shared/sam/cli/samCliBuild.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface SamCliBuildInvocationArguments {
4040
* - false: Lambda will be built on local machine instead of in a Docker image.
4141
*/
4242
useContainer?: boolean
43+
/** sam cli "--mount-with" option. */
44+
mountWith?: 'read' | 'write'
4345
/**
4446
* Specifies the name or id of an existing Docker network to Lambda Docker containers should connect to,
4547
* along with the default bridge network.
@@ -106,6 +108,7 @@ export class SamCliBuildInvocation {
106108
pushIf(invokeArgs, !!this.args.baseDir, '--base-dir', this.args.baseDir!)
107109
pushIf(invokeArgs, !!this.args.dockerNetwork, '--docker-network', this.args.dockerNetwork!)
108110
pushIf(invokeArgs, !!this.args.useContainer, '--use-container')
111+
pushIf(invokeArgs, !!this.args.mountWith, '--mount-with', this.args.mountWith?.toUpperCase())
109112
pushIf(invokeArgs, !!this.args.skipPullImage, '--skip-pull-image')
110113
pushIf(invokeArgs, !!this.args.manifestPath, '--manifest', this.args.manifestPath!)
111114
pushIf(

src/shared/sam/debugger/awsSamDebugger.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export interface SamLaunchRequestArgs extends AwsSamDebuggerConfiguration {
144144
/** Path to (generated) directory used as a working/staging area for SAM. */
145145
baseBuildDir?: string
146146

147+
/** sam cli "--mount-with" option. */
148+
mountWith?: 'read' | 'write'
149+
147150
/**
148151
* URI of the current editor document.
149152
* Used as a last resort for deciding `codeRoot` (when there is no `launch.json` nor `template.yaml`)

src/shared/sam/debugger/csharpSamDebug.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export async function makeCsharpConfig(config: SamLaunchRequestArgs): Promise<Sa
5555
runtimeFamily: RuntimeFamily.DotNet,
5656
}
5757

58+
if (config.sam?.containerBuild) {
59+
config.mountWith = 'write'
60+
}
61+
5862
if (!config.noDebug) {
5963
config = await makeDotnetDebugConfiguration(config, originalCodeRoot)
6064
}

src/test/shared/sam/debugger/samDebugConfigProvider.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,9 @@ describe('SamDebugConfigurationProvider', async function () {
17611761
templatePath: 'template.yaml',
17621762
logicalId: 'HelloWorldFunction',
17631763
},
1764+
sam: {
1765+
containerBuild: true, // #3864
1766+
},
17641767
lambda: {
17651768
environmentVariables: {
17661769
'test-envvar-1': 'test value 1',
@@ -1800,12 +1803,14 @@ describe('SamDebugConfigurationProvider', async function () {
18001803
documentUri: vscode.Uri.file(''), // TODO: remove or test.
18011804
handlerName: 'HelloWorld::HelloWorld.Function::FunctionHandler',
18021805
invokeTarget: { ...input.invokeTarget },
1806+
sam: { ...input.sam },
18031807
lambda: {
18041808
...input.lambda,
18051809
},
18061810
name: input.name,
18071811
architecture: 'x86_64',
18081812
templatePath: pathutil.normalize(path.join(path.dirname(templatePath.fsPath), 'template.yaml')),
1813+
mountWith: 'write',
18091814

18101815
//
18111816
// Csharp-related fields

src/testInteg/sam.test.ts

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ const scenarios: TestScenario[] = [
111111
dependencyManager: 'gradle',
112112
vscodeMinimum: '1.50.0',
113113
},
114+
{
115+
runtime: 'dotnet6',
116+
displayName: 'dotnet6 (ZIP)',
117+
path: 'src/HelloWorld/Function.cs',
118+
debugSessionType: 'coreclr',
119+
language: 'csharp',
120+
dependencyManager: 'cli-package',
121+
vscodeMinimum: '1.50.0',
122+
},
114123
{
115124
runtime: 'java8.al2',
116125
displayName: 'java8.al2 (Maven ZIP)',
@@ -144,7 +153,7 @@ const scenarios: TestScenario[] = [
144153
{
145154
runtime: 'nodejs14.x',
146155
displayName: 'nodejs14.x (Image)',
147-
baseImage: `amazon/nodejs14.x-base`,
156+
baseImage: 'amazon/nodejs14.x-base',
148157
path: 'hello-world/app.js',
149158
debugSessionType: 'pwa-node',
150159
language: 'javascript',
@@ -154,7 +163,7 @@ const scenarios: TestScenario[] = [
154163
{
155164
runtime: 'nodejs16.x',
156165
displayName: 'nodejs16.x (Image)',
157-
baseImage: `amazon/nodejs16.x-base`,
166+
baseImage: 'amazon/nodejs16.x-base',
158167
path: 'hello-world/app.js',
159168
debugSessionType: 'pwa-node',
160169
language: 'javascript',
@@ -164,7 +173,7 @@ const scenarios: TestScenario[] = [
164173
{
165174
runtime: 'nodejs18.x',
166175
displayName: 'nodejs18.x (Image)',
167-
baseImage: `amazon/nodejs18.x-base`,
176+
baseImage: 'amazon/nodejs18.x-base',
168177
path: 'hello-world/app.mjs',
169178
debugSessionType: 'pwa-node',
170179
language: 'javascript',
@@ -208,7 +217,7 @@ const scenarios: TestScenario[] = [
208217
runtime: 'java8',
209218
displayName: 'java8 (Maven Image)',
210219
path: 'HelloWorldFunction/src/main/java/helloworld/App.java',
211-
baseImage: `amazon/java8-base`,
220+
baseImage: 'amazon/java8-base',
212221
debugSessionType: 'java',
213222
language: 'java',
214223
dependencyManager: 'maven',
@@ -218,7 +227,7 @@ const scenarios: TestScenario[] = [
218227
runtime: 'java8.al2',
219228
displayName: 'java8.al2 (Gradle Image)',
220229
path: 'HelloWorldFunction/src/main/java/helloworld/App.java',
221-
baseImage: `amazon/java8.al2-base`,
230+
baseImage: 'amazon/java8.al2-base',
222231
debugSessionType: 'java',
223232
language: 'java',
224233
dependencyManager: 'gradle',
@@ -228,12 +237,22 @@ const scenarios: TestScenario[] = [
228237
runtime: 'java11',
229238
displayName: 'java11 (Maven Image)',
230239
path: 'HelloWorldFunction/src/main/java/helloworld/App.java',
231-
baseImage: `amazon/java11-base`,
240+
baseImage: 'amazon/java11-base',
232241
debugSessionType: 'java',
233242
language: 'java',
234243
dependencyManager: 'maven',
235244
vscodeMinimum: '1.50.0',
236245
},
246+
{
247+
runtime: 'dotnet6',
248+
displayName: 'dotnet6 (Image)',
249+
path: 'src/HelloWorld/Function.cs',
250+
baseImage: 'amazon/dotnet6-base',
251+
debugSessionType: 'coreclr',
252+
language: 'csharp',
253+
dependencyManager: 'cli-package',
254+
vscodeMinimum: '1.50.0',
255+
},
237256
]
238257

239258
async function openSamAppFile(applicationPath: string): Promise<vscode.Uri> {
@@ -469,7 +488,10 @@ describe('SAM Integration Tests', async function () {
469488
})
470489

471490
it('produces an Add Debug Configuration codelens', async function () {
472-
if (semver.lt(vscode.version, scenario.vscodeMinimum)) {
491+
if (
492+
scenario.language === 'csharp' || // TODO
493+
semver.lt(vscode.version, scenario.vscodeMinimum)
494+
) {
473495
this.skip()
474496
}
475497

@@ -488,9 +510,9 @@ describe('SAM Integration Tests', async function () {
488510
case 'python':
489511
manifestFile = /^requirements\.txt$/
490512
break
491-
case 'csharp':
492-
manifestFile = /^.*\.csproj$/
493-
break
513+
// case 'csharp':
514+
// manifestFile = /^.*\.csproj$/
515+
// break
494516
case 'go':
495517
manifestFile = /^go\.mod$/
496518
break

0 commit comments

Comments
 (0)