Skip to content

Commit

Permalink
chore: Simplify & fix Swift 6 issues in protocol test manifest (#1855)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jan 7, 2025
1 parent b1057fe commit 9221899
Showing 1 changed file with 39 additions and 77 deletions.
116 changes: 39 additions & 77 deletions codegen/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@
// 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") }
static var awsSDKHTTPAuth: Self { .product(name: "AWSSDKHTTPAuth", package: "aws-sdk-swift") }
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") }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 9221899

Please sign in to comment.