From 1ecdcfbab661cf2539f9138e7c038b2c88990c0b Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Mon, 29 Jun 2026 13:04:39 +0200 Subject: [PATCH 1/2] fix warning --- .../CollectEverythingLogHandler.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Tests/AWSLambdaRuntimeTests/CollectEverythingLogHandler.swift b/Tests/AWSLambdaRuntimeTests/CollectEverythingLogHandler.swift index b02406f01..fca43ba03 100644 --- a/Tests/AWSLambdaRuntimeTests/CollectEverythingLogHandler.swift +++ b/Tests/AWSLambdaRuntimeTests/CollectEverythingLogHandler.swift @@ -117,16 +117,12 @@ struct CollectEverythingLogHandler: LogHandler { self.logStore = logStore } - func log( - level: Logger.Level, - message: Logger.Message, - metadata: Logger.Metadata?, - source: String, - file: String, - function: String, - line: UInt - ) { - self.logStore.append(level: level, message: message, metadata: self.metadata.merging(metadata ?? [:]) { $1 }) + func log(event: LogEvent) { + self.logStore.append( + level: event.level, + message: event.message, + metadata: self.metadata.merging(event.metadata ?? [:]) { $1 } + ) } subscript(metadataKey key: String) -> Logger.Metadata.Value? { From 8eca94f2d1b0f6eb21a14d433bbb53674dde82a7 Mon Sep 17 00:00:00 2001 From: Sebastien Stormacq Date: Mon, 29 Jun 2026 13:04:54 +0200 Subject: [PATCH 2/2] fix config make backend --- .../lambda-build/Builder.swift | 28 +++++++++++++++-- .../lambda-build/CrossCompileMethod.swift | 30 +++---------------- .../BuildBackendTests.swift | 22 +++++--------- 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/Sources/AWSLambdaPluginHelper/lambda-build/Builder.swift b/Sources/AWSLambdaPluginHelper/lambda-build/Builder.swift index ce5a334f2..b7c1d4fbb 100644 --- a/Sources/AWSLambdaPluginHelper/lambda-build/Builder.swift +++ b/Sources/AWSLambdaPluginHelper/lambda-build/Builder.swift @@ -36,11 +36,11 @@ struct Builder { // Select the build backend: build natively when already on an Amazon Linux host, // otherwise cross-compile using the backend chosen by --cross-compile. - let backend: BuildBackend + let backend: any BuildBackend if self.isAmazonLinux(.al2) || self.isAmazonLinux(.al2023) { backend = NativeBuildBackend() } else { - backend = try configuration.crossCompileMethod.makeBackend(configuration: configuration) + backend = try configuration.makeCrossCompileBackend() } let builtProducts = try backend.build( @@ -379,6 +379,30 @@ struct BuilderConfiguration: CustomStringConvertible { } } + /// Creates the ``BuildBackend`` that performs a cross-compiled build for the configured method. + /// + /// Used when the host is not already an Amazon Linux machine. The configuration already holds + /// everything a backend needs (the resolved tool path, base image, and image-update + /// preference), so the factory lives here rather than on ``CrossCompileMethod``. + func makeCrossCompileBackend() throws -> any BuildBackend { + let cli: any ContainerCLI + switch self.crossCompileMethod { + case .docker: + cli = DockerCLI() + case .container: + cli = AppleContainerCLI() + case .swiftStaticSdk, .customSdk: + throw BuilderErrors.unsupportedCrossCompileMethod(self.crossCompileMethod) + } + return ContainerBuildBackend( + cli: cli, + toolPath: self.crossCompileToolPath, + baseImage: self.baseDockerImage, + disableImageUpdate: self.disableDockerImageUpdate, + method: self.crossCompileMethod + ) + } + var description: String { """ { diff --git a/Sources/AWSLambdaPluginHelper/lambda-build/CrossCompileMethod.swift b/Sources/AWSLambdaPluginHelper/lambda-build/CrossCompileMethod.swift index d32240597..20a7e146c 100644 --- a/Sources/AWSLambdaPluginHelper/lambda-build/CrossCompileMethod.swift +++ b/Sources/AWSLambdaPluginHelper/lambda-build/CrossCompileMethod.swift @@ -21,9 +21,10 @@ import Foundation /// The cross-compilation method requested via `--cross-compile`. /// -/// This enum is the parsed user choice and a factory for the matching ``BuildBackend``. It holds -/// no execution logic itself: container argument spelling lives in the ``ContainerCLI`` types and -/// the build flow lives in the ``BuildBackend`` types. +/// This enum is purely the parsed user choice. It holds no execution logic: container argument +/// spelling lives in the ``ContainerCLI`` types, the build flow lives in the ``BuildBackend`` +/// types, and backend construction lives on ``BuilderConfiguration`` (which holds everything a +/// backend needs). @available(LambdaSwift 2.0, *) enum CrossCompileMethod: String, CustomStringConvertible { case docker @@ -56,29 +57,6 @@ enum CrossCompileMethod: String, CustomStringConvertible { return method } - /// Creates the ``BuildBackend`` that performs a cross-compiled build for this method. - /// - /// Used when the host is not already an Amazon Linux machine. The configuration supplies the - /// resolved tool path, base image, and image-update preference. - func makeBackend(configuration: BuilderConfiguration) throws -> BuildBackend { - let cli: ContainerCLI - switch self { - case .docker: - cli = DockerCLI() - case .container: - cli = AppleContainerCLI() - case .swiftStaticSdk, .customSdk: - throw BuilderErrors.unsupportedCrossCompileMethod(self) - } - return ContainerBuildBackend( - cli: cli, - toolPath: configuration.crossCompileToolPath, - baseImage: configuration.baseDockerImage, - disableImageUpdate: configuration.disableDockerImageUpdate, - method: self - ) - } - var description: String { self.rawValue } diff --git a/Tests/AWSLambdaPluginHelperTests/BuildBackendTests.swift b/Tests/AWSLambdaPluginHelperTests/BuildBackendTests.swift index d8ed3cd03..f10d5e20e 100644 --- a/Tests/AWSLambdaPluginHelperTests/BuildBackendTests.swift +++ b/Tests/AWSLambdaPluginHelperTests/BuildBackendTests.swift @@ -150,13 +150,13 @@ struct AppleContainerCLIArgumentTests { } } -// MARK: - CrossCompileMethod.makeBackend +// MARK: - BuilderConfiguration.makeCrossCompileBackend -@Suite("CrossCompileMethod backend selection") -struct CrossCompileMethodBackendTests { +@Suite("Cross-compile backend selection") +struct CrossCompileBackendSelectionTests { @available(LambdaSwift 2.0, *) - static func makeConfiguration() throws -> BuilderConfiguration { + static func makeConfiguration(method: String) throws -> BuilderConfiguration { try BuilderConfiguration(arguments: [ "--package-id", "test", "--package-display-name", "Test", @@ -166,13 +166,14 @@ struct CrossCompileMethodBackendTests { "--output-path", "/tmp", "--products", "MyLambda", "--configuration", "release", + "--cross-compile", method, ]) } @available(LambdaSwift 2.0, *) @Test("docker selects a container backend running the docker CLI") func dockerBackend() throws { - let backend = try CrossCompileMethod.docker.makeBackend(configuration: Self.makeConfiguration()) + let backend = try Self.makeConfiguration(method: "docker").makeCrossCompileBackend() let container = try #require(backend as? ContainerBuildBackend) #expect(container.name == "docker") #expect(container.cli is DockerCLI) @@ -181,18 +182,9 @@ struct CrossCompileMethodBackendTests { @available(LambdaSwift 2.0, *) @Test("container selects a container backend running the apple container CLI") func containerBackend() throws { - let backend = try CrossCompileMethod.container.makeBackend(configuration: Self.makeConfiguration()) + let backend = try Self.makeConfiguration(method: "container").makeCrossCompileBackend() let container = try #require(backend as? ContainerBuildBackend) #expect(container.name == "container") #expect(container.cli is AppleContainerCLI) } - - @available(LambdaSwift 2.0, *) - @Test("unsupported methods throw", arguments: [CrossCompileMethod.swiftStaticSdk, .customSdk]) - func unsupportedThrows(method: CrossCompileMethod) throws { - let config = try Self.makeConfiguration() - #expect(throws: BuilderErrors.self) { - _ = try method.makeBackend(configuration: config) - } - } }