Skip to content

Commit d621c0d

Browse files
committed
localLambdaRunner.ts: eliminate executeSamBuild()
"execute sam build" is already abstracted via `SamCliBuildInvocationArguments`, so `executeSamBuild()` is unnecessary.
1 parent d943ba8 commit d621c0d

File tree

4 files changed

+22
-55
lines changed

4 files changed

+22
-55
lines changed

src/shared/sam/cli/samCliBuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface SamCliBuildInvocationArguments {
2323
*/
2424
templatePath: string
2525
/**
26-
* Environment variables to set on the child process.
26+
* Environment variables set when invoking the SAM process (NOT passed to the Lambda).
2727
*/
2828
environmentVariables?: NodeJS.ProcessEnv
2929
/**

src/shared/sam/debugger/csharpSamDebug.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export async function makeCsharpConfig(config: SamLaunchRequestArgs): Promise<Sa
5656

5757
/**
5858
* Launches and attaches debugger to a SAM dotnet (csharp) project.
59+
*
60+
* We spin up a C# Lambda Docker container, download and build the debugger for
61+
* Linux, then mount it with the SAM app on run. User's C# workspace dir will
62+
* have a `.vsdbg` dir after the first run.
5963
*/
6064
export async function invokeCsharpLambda(ctx: ExtContext, config: SamLaunchRequestArgs): Promise<void> {
6165
config.samLocalInvokeCommand = new DefaultSamLocalInvokeCommand(getChannelLogger(ctx.outputChannel), [

src/shared/sam/debugger/samDebugSession.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export interface SamLaunchRequestArgs extends DebugProtocol.AttachRequestArgumen
5959
/**
6060
* SAM/CFN template absolute path used for SAM CLI invoke.
6161
* - For `target=code` this is the _generated_ template path.
62-
* - For `target=template` this is the template found in the workspace.
62+
* - For `target=template` this is the _generated_ template path (TODO: in
63+
* the future we may change this to be the template found in the workspace.
6364
*/
6465
samTemplatePath: string
6566

src/shared/sam/localLambdaRunner.ts

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { ChannelLogger } from '../utilities/vsCodeUtils'
2424
import { tryGetAbsolutePath } from '../utilities/workspaceUtils'
2525
import { DefaultValidatingSamCliProcessInvoker } from './cli/defaultValidatingSamCliProcessInvoker'
2626
import { SamCliBuildInvocation, SamCliBuildInvocationArguments } from './cli/samCliBuild'
27-
import { SamCliProcessInvoker } from './cli/samCliInvokerUtils'
2827
import { SamCliLocalInvokeInvocation, SamCliLocalInvokeInvocationArguments } from './cli/samCliLocalInvoke'
2928
import { SamLaunchRequestArgs } from './debugger/samDebugSession'
3029

@@ -117,53 +116,12 @@ export async function makeInputTemplate(config: SamLaunchRequestArgs): Promise<s
117116
return pathutil.normalize(inputTemplatePath)
118117
}
119118

120-
export interface ExecuteSamBuildArguments {
121-
baseBuildDir: string
122-
channelLogger: Pick<ChannelLogger, 'info'>
123-
codeDir: string
124-
inputTemplatePath: string
125-
manifestPath?: string
126-
environmentVariables?: NodeJS.ProcessEnv
127-
samProcessInvoker: SamCliProcessInvoker
128-
useContainer?: boolean
129-
}
130-
131-
export async function executeSamBuild({
132-
baseBuildDir,
133-
channelLogger,
134-
codeDir,
135-
inputTemplatePath,
136-
manifestPath,
137-
environmentVariables,
138-
samProcessInvoker,
139-
useContainer,
140-
}: ExecuteSamBuildArguments): Promise<string> {
141-
channelLogger.info('AWS.output.building.sam.application', 'Building SAM Application...')
142-
143-
const samBuildOutputFolder = path.join(baseBuildDir, 'output')
144-
145-
const samCliArgs: SamCliBuildInvocationArguments = {
146-
buildDir: samBuildOutputFolder,
147-
baseDir: codeDir,
148-
templatePath: inputTemplatePath,
149-
invoker: samProcessInvoker,
150-
manifestPath,
151-
environmentVariables,
152-
useContainer,
153-
}
154-
await new SamCliBuildInvocation(samCliArgs).execute()
155-
156-
channelLogger.info('AWS.output.building.sam.application.complete', 'Build complete.')
157-
158-
return path.join(samBuildOutputFolder, 'template.yaml')
159-
}
160-
161119
/**
162120
* Prepares and invokes a lambda function via `sam local invoke`.
163121
*
164122
* @param ctx
165123
* @param config
166-
* @param onAfterBuild Called after `executeSamBuild()`
124+
* @param onAfterBuild Called after `SamCliBuildInvocation.execute()`
167125
*/
168126
export async function invokeLambdaFunction(
169127
ctx: ExtContext,
@@ -175,25 +133,29 @@ export async function invokeLambdaFunction(
175133
ctx.chanLogger.info('AWS.output.sam.local.start', 'Preparing to run {0} locally...', config.handlerName)
176134

177135
const processInvoker = new DefaultValidatingSamCliProcessInvoker({})
178-
const buildArgs: ExecuteSamBuildArguments = {
179-
baseBuildDir: config.baseBuildDir!,
180-
channelLogger: ctx.chanLogger,
181-
codeDir: config.codeRoot,
182-
inputTemplatePath: config.samTemplatePath!,
136+
137+
ctx.chanLogger.info('AWS.output.building.sam.application', 'Building SAM Application...')
138+
const samBuildOutputFolder = path.join(config.baseBuildDir!, 'output')
139+
const samCliArgs: SamCliBuildInvocationArguments = {
140+
buildDir: samBuildOutputFolder,
141+
baseDir: config.codeRoot,
142+
templatePath: config.samTemplatePath!,
143+
invoker: processInvoker,
183144
manifestPath: config.manifestPath,
184-
samProcessInvoker: processInvoker,
145+
environmentVariables: {},
185146
useContainer: config.sam?.containerBuild || false,
186-
environmentVariables: config.lambda?.environmentVariables,
187147
}
188-
189148
if (!config.noDebug) {
190-
buildArgs.environmentVariables = {
149+
// Needed at least for dotnet case; harmless for others.
150+
samCliArgs.environmentVariables = {
191151
SAM_BUILD_MODE: 'debug',
192152
}
193153
}
154+
await new SamCliBuildInvocation(samCliArgs).execute()
155+
ctx.chanLogger.info('AWS.output.building.sam.application.complete', 'Build complete.')
194156

195157
// XXX: reassignment
196-
config.samTemplatePath = await executeSamBuild(buildArgs)
158+
config.samTemplatePath = path.join(samBuildOutputFolder, 'template.yaml')
197159
delete config.invokeTarget // Must not be used beyond this point.
198160

199161
await onAfterBuild()

0 commit comments

Comments
 (0)