Skip to content

Commit 1b8bb28

Browse files
authored
Merge #1139 'SAM debugconfig: fix placement of .vsdbg'
2 parents 43c651d + 50e4810 commit 1b8bb28

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

src/shared/sam/debugger/csharpSamDebug.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export async function makeCsharpConfig(config: SamLaunchRequestArgs): Promise<Sa
3333
throw Error('invalid state: config.baseBuildDir was not set')
3434
}
3535
config.codeRoot = getCodeRoot(config.workspaceFolder, config)!
36-
3736
config.samTemplatePath = await makeInputTemplate(config)
38-
// XXX: reassignment...
37+
// TODO: avoid the reassignment
3938
// TODO: walk the tree to find .sln, .csproj ?
39+
const originalCodeRoot = config.codeRoot
4040
config.codeRoot = getSamProjectDirPathForFile(config.samTemplatePath)
4141

4242
config = {
@@ -48,7 +48,7 @@ export async function makeCsharpConfig(config: SamLaunchRequestArgs): Promise<Sa
4848
}
4949

5050
if (!config.noDebug) {
51-
config = await makeCoreCLRDebugConfiguration(config, config.codeRoot)
51+
config = await makeCoreCLRDebugConfiguration(config, originalCodeRoot)
5252
}
5353

5454
return config
@@ -152,7 +152,7 @@ export async function makeCoreCLRDebugConfiguration(
152152
}
153153
config.debugPort = config.debugPort ?? (await getStartPort())
154154
const pipeArgs = ['-c', `docker exec -i $(docker ps -q -f publish=${config.debugPort}) \${debuggerCommand}`]
155-
config.debuggerPath = pathutil.normalize(getDebuggerPath(config.codeRoot))
155+
config.debuggerPath = pathutil.normalize(getDebuggerPath(codeUri))
156156
await ensureDebuggerPathExists(config.debuggerPath)
157157

158158
if (os.platform() === 'win32') {

src/test/lambda/local/debugConfiguration.test.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55

66
import * as assert from 'assert'
77
import * as os from 'os'
8-
import * as path from 'path'
98
import * as vscode from 'vscode'
10-
119
import { RuntimeFamily } from '../../../lambda/models/samLambdaRuntime'
12-
import { FakeExtensionContext } from '../../fakeExtensionContext'
10+
import { rmrf } from '../../../shared/filesystem'
11+
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
1312
import { DefaultSamLocalInvokeCommand } from '../../../shared/sam/cli/samCliLocalInvoke'
13+
import { makeCoreCLRDebugConfiguration } from '../../../shared/sam/debugger/csharpSamDebug'
1414
import { SamLaunchRequestArgs } from '../../../shared/sam/debugger/samDebugSession'
15-
import { makeTemporaryToolkitFolder } from '../../../shared/filesystemUtilities'
16-
import { rmrf } from '../../../shared/filesystem'
15+
import { FakeExtensionContext } from '../../fakeExtensionContext'
1716
import * as testutil from '../../testUtil'
18-
import { makeCoreCLRDebugConfiguration } from '../../../shared/sam/debugger/csharpSamDebug'
1917

2018
describe('makeCoreCLRDebugConfiguration', async () => {
2119
let tempFolder: string
@@ -66,35 +64,34 @@ describe('makeCoreCLRDebugConfiguration', async () => {
6664
return config
6765
}
6866

69-
async function makeConfig({ codeUri = path.join('foo', 'bar') }: { codeUri?: string; port?: number }) {
67+
async function makeConfig({ codeUri = tempFolder }: { codeUri?: string; port?: number }) {
7068
const fakeLaunchConfig = await makeFakeSamLaunchConfig()
7169
return makeCoreCLRDebugConfiguration(fakeLaunchConfig, codeUri)
7270
}
7371

7472
it('uses the specified codeUri', async () => {
7573
const config = await makeConfig({})
76-
77-
testutil.assertEqualPaths(config.sourceFileMap['/var/task'], path.join('foo', 'bar'))
74+
testutil.assertEqualPaths(config.sourceFileMap['/var/task'], tempFolder)
7875
})
7976

8077
describe('windows', async () => {
8178
if (os.platform() === 'win32') {
8279
it('massages drive letters to uppercase', async () => {
83-
const config = await makeConfig({ codeUri: 'c:\\foo\\bar' })
84-
85-
testutil.assertEqualPaths(config.windows.pipeTransport.pipeCwd, 'C:/foo/bar')
80+
const config = await makeConfig({})
81+
assert.strictEqual(
82+
config.windows.pipeTransport.pipeCwd.substring(0, 1),
83+
tempFolder.substring(0, 1).toUpperCase()
84+
)
8685
})
8786
}
8887

8988
it('uses powershell', async () => {
9089
const config = await makeConfig({})
91-
9290
assert.strictEqual(config.windows.pipeTransport.pipeProgram, 'powershell')
9391
})
9492

9593
it('uses the specified port', async () => {
9694
const config = await makeConfig({})
97-
9895
assert.strictEqual(
9996
config.windows.pipeTransport.pipeArgs.some(arg => arg.includes(config.debugPort!!.toString())),
10097
true

src/test/shared/sam/cli/samCliBuild.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,25 @@ describe('SamCliBuildInvocation', async () => {
5959
await del([tempFolder], { force: true })
6060
})
6161

62-
it('Passes build command to sam cli', async () => {
62+
it('invokes `sam build` with args', async () => {
6363
const processInvoker: SamCliProcessInvoker = new ExtendedTestSamCliProcessInvoker((args: any[]) => {
64-
assert.ok(args.length > 0, 'Expected args to be present')
65-
assert.strictEqual(args[0], 'build', 'Expected first arg to be the build command')
64+
assert.ok(args.length >= 2, 'Expected args to be present')
65+
assert.strictEqual(args[0], 'build')
66+
assert.strictEqual(args[3], '--template')
67+
assert.strictEqual(args[5], '--base-dir')
68+
69+
// `extraArgs` are appended to the end.
70+
assert.strictEqual(args[7], '--debug')
71+
assert.strictEqual(args[8], '--build-dir')
72+
assert.strictEqual(args[9], 'my/build/dir/')
6673
})
6774

6875
await new SamCliBuildInvocation({
6976
buildDir: nonRelevantArg,
7077
baseDir: nonRelevantArg,
7178
templatePath: placeholderTemplateFile,
7279
invoker: processInvoker,
80+
extraArgs: ['--debug', '--build-dir', 'my/build/dir/'],
7381
}).execute()
7482
})
7583

src/test/shared/sam/cli/samCliLocalInvoke.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@ describe('SamCliLocalInvokeInvocation', async () => {
4141
await del([tempFolder], { force: true })
4242
})
4343

44-
it('Passes local invoke command to sam cli', async () => {
44+
it('invokes `sam local` with args', async () => {
4545
const taskInvoker: SamLocalInvokeCommand = new TestSamLocalInvokeCommand(
4646
(invokeArgs: SamLocalInvokeCommandArgs) => {
4747
assert.ok(invokeArgs.args.length >= 2, 'Expected args to be present')
48-
assert.strictEqual(invokeArgs.args[0], 'local', 'Expected first arg to be local')
49-
assert.strictEqual(invokeArgs.args[1], 'invoke', 'Expected second arg to be invoke')
48+
assert.strictEqual(invokeArgs.args[0], 'local')
49+
assert.strictEqual(invokeArgs.args[1], 'invoke')
50+
assert.strictEqual(invokeArgs.args[3], '--template')
51+
assert.strictEqual(invokeArgs.args[5], '--event')
52+
assert.strictEqual(invokeArgs.args[7], '--env-vars')
53+
54+
// `extraArgs` are appended to the end.
55+
assert.strictEqual(invokeArgs.args[9], '--debug')
56+
assert.strictEqual(invokeArgs.args[10], '--build-dir')
57+
assert.strictEqual(invokeArgs.args[11], 'my/build/dir/')
5058
}
5159
)
5260

@@ -56,6 +64,7 @@ describe('SamCliLocalInvokeInvocation', async () => {
5664
eventPath: placeholderEventFile,
5765
environmentVariablePath: nonRelevantArg,
5866
invoker: taskInvoker,
67+
extraArgs: ['--debug', '--build-dir', 'my/build/dir/'],
5968
}).execute()
6069
})
6170

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ describe('AwsSamDebugConfigurationProvider', async () => {
572572
folder,
573573
input
574574
))! as DotNetCoreDebugConfiguration
575+
const codeRoot = `${appDir}${input.invokeTarget.projectRoot}`
575576
const expectedCodeRoot = (actual.baseBuildDir ?? 'fail') + '/input'
576577
const expected: SamLaunchRequestArgs = {
577578
request: 'attach', // Input "direct-invoke", output "attach".
@@ -603,24 +604,24 @@ describe('AwsSamDebugConfigurationProvider', async () => {
603604
//
604605
// Csharp-related fields
605606
//
606-
debuggerPath: expectedCodeRoot + '/.vsdbg', // Normalized to absolute path.
607+
debuggerPath: codeRoot + '/.vsdbg', // Normalized to absolute path.
607608
processId: '1',
608609
pipeTransport: {
609610
debuggerPath: '/tmp/lambci_debug_files/vsdbg',
610611
// tslint:disable-next-line: no-invalid-template-strings
611612
pipeArgs: ['-c', 'docker exec -i $(docker ps -q -f publish=5858) ${debuggerCommand}'],
612-
pipeCwd: expectedCodeRoot,
613+
pipeCwd: codeRoot,
613614
pipeProgram: 'sh',
614615
},
615616
sourceFileMap: {
616-
'/var/task': expectedCodeRoot,
617+
'/var/task': codeRoot,
617618
},
618619
windows: {
619620
pipeTransport: {
620621
debuggerPath: '/tmp/lambci_debug_files/vsdbg',
621622
// tslint:disable-next-line: no-invalid-template-strings
622623
pipeArgs: ['-c', 'docker exec -i $(docker ps -q -f publish=5858) ${debuggerCommand}'],
623-
pipeCwd: expectedCodeRoot,
624+
pipeCwd: codeRoot,
624625
pipeProgram: 'powershell',
625626
},
626627
},
@@ -710,6 +711,7 @@ describe('AwsSamDebugConfigurationProvider', async () => {
710711
folder,
711712
input
712713
))! as DotNetCoreDebugConfiguration
714+
const codeRoot = `${appDir}/src/HelloWorld`
713715
const expectedCodeRoot = (actual.baseBuildDir ?? 'fail') + '/input'
714716
const expected: SamLaunchRequestArgs = {
715717
request: 'attach', // Input "direct-invoke", output "attach".
@@ -738,24 +740,24 @@ describe('AwsSamDebugConfigurationProvider', async () => {
738740
//
739741
// Csharp-related fields
740742
//
741-
debuggerPath: expectedCodeRoot + '/.vsdbg', // Normalized to absolute path.
743+
debuggerPath: codeRoot + '/.vsdbg', // Normalized to absolute path.
742744
processId: '1',
743745
pipeTransport: {
744746
debuggerPath: '/tmp/lambci_debug_files/vsdbg',
745747
// tslint:disable-next-line: no-invalid-template-strings
746748
pipeArgs: ['-c', 'docker exec -i $(docker ps -q -f publish=5858) ${debuggerCommand}'],
747-
pipeCwd: expectedCodeRoot,
749+
pipeCwd: codeRoot,
748750
pipeProgram: 'sh',
749751
},
750752
sourceFileMap: {
751-
'/var/task': expectedCodeRoot,
753+
'/var/task': codeRoot,
752754
},
753755
windows: {
754756
pipeTransport: {
755757
debuggerPath: '/tmp/lambci_debug_files/vsdbg',
756758
// tslint:disable-next-line: no-invalid-template-strings
757759
pipeArgs: ['-c', 'docker exec -i $(docker ps -q -f publish=5858) ${debuggerCommand}'],
758-
pipeCwd: expectedCodeRoot,
760+
pipeCwd: codeRoot,
759761
pipeProgram: 'powershell',
760762
},
761763
},

0 commit comments

Comments
 (0)