Skip to content

Commit 294d06b

Browse files
authored
Use LAMBDA_USE_LOCAL_DEPS env var in local builds with docker (#325)
1 parent 17a993e commit 294d06b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Plugins/AWSLambdaPackager/Plugin.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,24 @@ struct AWSLambdaPackager: CommandPlugin {
115115
for product in products {
116116
print("building \"\(product.name)\"")
117117
let buildCommand = "swift build -c \(buildConfiguration.rawValue) --product \(product.name) --static-swift-stdlib"
118-
try self.execute(
119-
executable: dockerToolPath,
120-
arguments: ["run", "--rm", "-v", "\(packageDirectory.string):/workspace", "-w", "/workspace", baseImage, "bash", "-cl", buildCommand],
121-
logLevel: verboseLogging ? .debug : .output
122-
)
118+
if ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"] != nil {
119+
// when developing locally, we must have the full swift-aws-lambda-runtime project in the container
120+
// because Examples' Package.swift have a dependency on ../..
121+
// just like Package.swift's examples assume ../.., we assume we are two levels below the root project
122+
let lastComponent = packageDirectory.lastComponent
123+
let beforeLastComponent = packageDirectory.removingLastComponent().lastComponent
124+
try self.execute(
125+
executable: dockerToolPath,
126+
arguments: ["run", "--rm", "--env", "LAMBDA_USE_LOCAL_DEPS=true", "-v", "\(packageDirectory.string)/../..:/workspace", "-w", "/workspace/\(beforeLastComponent)/\(lastComponent)", baseImage, "bash", "-cl", buildCommand],
127+
logLevel: verboseLogging ? .debug : .output
128+
)
129+
} else {
130+
try self.execute(
131+
executable: dockerToolPath,
132+
arguments: ["run", "--rm", "-v", "\(packageDirectory.string):/workspace", "-w", "/workspace", baseImage, "bash", "-cl", buildCommand],
133+
logLevel: verboseLogging ? .debug : .output
134+
)
135+
}
123136
let productPath = buildOutputPath.appending(product.name)
124137
guard FileManager.default.fileExists(atPath: productPath.string) else {
125138
Diagnostics.error("expected '\(product.name)' binary at \"\(productPath.string)\"")

0 commit comments

Comments
 (0)