diff --git a/codegen/Package.swift b/codegen/Package.swift index 0ba7930d874..8ecff3b4dfc 100644 --- a/codegen/Package.swift +++ b/codegen/Package.swift @@ -7,13 +7,12 @@ // SPDX-License-Identifier: Apache-2.0 // -import Foundation import PackageDescription // MARK: - Target dependencies extension Target.Dependency { - // AWS modules + // aws-sdk-swift modules static var awsClientRuntime: Self { .product(name: "AWSClientRuntime", package: "aws-sdk-swift") } static var awsSDKCommon: Self { .product(name: "AWSSDKCommon", package: "aws-sdk-swift") } static var awsSDKEventStreamsAuth: Self { .product(name: "AWSSDKEventStreamsAuth", package: "aws-sdk-swift") } @@ -21,10 +20,7 @@ extension Target.Dependency { static var awsSDKIdentity: Self { .product(name: "AWSSDKIdentity", package: "aws-sdk-swift") } static var awsSDKChecksums: Self { .product(name: "AWSSDKChecksums", package: "aws-sdk-swift") } - // CRT module - static var crt: Self { .product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift") } - - // Smithy modules + // smithy-swift modules static var clientRuntime: Self { .product(name: "ClientRuntime", package: "smithy-swift") } static var smithy: Self { .product(name: "Smithy", package: "smithy-swift") } static var smithyChecksumsAPI: Self { .product(name: "SmithyChecksumsAPI", package: "smithy-swift") } @@ -52,73 +48,16 @@ let package = Package( .iOS(.v13), .tvOS(.v13), .watchOS(.v6) - ] + ], + dependencies: [ + .package(path: "../../smithy-swift"), + .package(path: "../../aws-sdk-swift"), + ], + targets: protocolTestTargets ) -// MARK: - CRT, Smithy ClientRuntime, AWS ClientRuntime Dependencies - -func addDependencies() { - addClientRuntimeDependency() - addAWSClientRuntimeDependency() - addCRTDependency() -} - -func addClientRuntimeDependency() { - let smithySwiftURL = "https://github.com/smithy-lang/smithy-swift" - let useLocalDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_LOCAL_DEPS"] != nil - let useMainDeps = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_USE_MAIN_DEPS"] != nil - switch (useLocalDeps, useMainDeps) { - case (true, true): - fatalError("Unable to determine which dependencies to use. Please only specify one of AWS_SWIFT_SDK_USE_LOCAL_DEPS or AWS_SWIFT_SDK_USE_MAIN_DEPS.") - case (true, false): - package.dependencies += [ - .package(path: "../../smithy-swift") - ] - case (false, true): - package.dependencies += [ - .package(url: smithySwiftURL, branch: "main") - ] - case (false, false): - package.dependencies += [ - .package(url: smithySwiftURL, .upToNextMajor(from: "0.0.0")) - ] - } -} +private var protocolTestTargets: [Target] { -func addAWSClientRuntimeDependency() { - package.dependencies += [ - .package(path: "../../aws-sdk-swift") - ] -} - -func addCRTDependency() { - package.dependencies += [ - .package(url: "https://github.com/awslabs/aws-crt-swift", .upToNextMajor(from: "0.0.0")) - ] -} - -let serviceTargetDependencies: [Target.Dependency] = [ - .clientRuntime, - .awsClientRuntime, - .smithyRetriesAPI, - .smithyRetries, - .smithy, - .smithyIdentity, - .smithyIdentityAPI, - .smithyEventStreamsAPI, - .smithyEventStreamsAuthAPI, - .smithyEventStreams, - .smithyChecksumsAPI, - .smithyChecksums, - .smithyWaitersAPI, - .awsSDKCommon, - .awsSDKIdentity, - .awsSDKHTTPAuth, - .awsSDKEventStreamsAuth, - .awsSDKChecksums, -] - -func addProtocolTests() { struct ProtocolTest { let name: String let sourcePath: String @@ -156,20 +95,43 @@ func addProtocolTests() { .init(name: "Waiters", sourcePath: "\(baseDirLocal)/Waiters", testPath: "../codegen/protocol-test-codegen-local/Tests"), .init(name: "StringArrayEndpointParam", sourcePath: "\(baseDirLocal)/StringArrayEndpointParam") ] - for protocolTest in protocolTests { + return protocolTests.flatMap { protocolTest in let target = Target.target( name: protocolTest.name, - dependencies: serviceTargetDependencies, + dependencies: [ + .clientRuntime, + .awsClientRuntime, + .smithyRetriesAPI, + .smithyRetries, + .smithy, + .smithyIdentity, + .smithyIdentityAPI, + .smithyHTTPAPI, + .smithyHTTPAuth, + .smithyEventStreamsAPI, + .smithyEventStreamsAuthAPI, + .smithyEventStreams, + .smithyChecksumsAPI, + .smithyChecksums, + .smithyWaitersAPI, + .awsSDKCommon, + .awsSDKIdentity, + .awsSDKHTTPAuth, + .awsSDKEventStreamsAuth, + .awsSDKChecksums, + ], path: "\(protocolTest.sourcePath)/swift-codegen/Sources/\(protocolTest.name)" ) let testTarget = protocolTest.buildOnly ? nil : Target.testTarget( name: "\(protocolTest.name)Tests", - dependencies: [.smithyTestUtils, .smithyStreams, .smithyWaitersAPI, .byNameItem(name: protocolTest.name, condition: nil)], + dependencies: [ + .smithyTestUtils, + .smithyStreams, + .smithyWaitersAPI, + .byNameItem(name: protocolTest.name, condition: nil) + ], path: "\(protocolTest.testPath ?? protocolTest.sourcePath)/swift-codegen/Tests/\(protocolTest.name)Tests" ) - package.targets += [target, testTarget].compactMap { $0 } + return [target, testTarget].compactMap { $0 } } } - -addDependencies() -addProtocolTests()