diff --git a/Package.swift b/Package.swift index 3551b6967..a7ca78cfc 100644 --- a/Package.swift +++ b/Package.swift @@ -140,7 +140,12 @@ let package = Package( ), .target( name: "SmithyTestUtil", - dependencies: ["ClientRuntime", "SmithyHTTPAPI", "SmithyIdentity"] + dependencies: [ + "ClientRuntime", + "SmithyHTTPAPI", + "SmithyIdentity", + .product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"), + ] ), .target( name: "SmithyIdentity", diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt index b022ea84d..558608a32 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/PackageManifestGenerator.kt @@ -8,12 +8,10 @@ import software.amazon.smithy.codegen.core.SymbolDependency import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import kotlin.jvm.optionals.getOrNull -val PACKAGE_MANIFEST_NAME = "Package.swift.txt" - class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { fun writePackageManifest(dependencies: List) { - ctx.delegator.useFileWriter(PACKAGE_MANIFEST_NAME) { writer -> + ctx.delegator.useFileWriter("Package.swift.txt") { writer -> writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) writer.write("") writer.write("import PackageDescription") @@ -30,10 +28,12 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.write(".library(name: \$S, targets: [\$S])", ctx.settings.moduleName, ctx.settings.moduleName) } - val externalDependencies = dependencies.filter { - it.getProperty("url", String::class.java).getOrNull() != null || - it.getProperty("scope", String::class.java).getOrNull() != null - } + val externalDependencies = dependencies + .filter { it.expectProperty("target", String::class.java) != "SmithyTestUtil" } // SmithyTestUtil links to test target only + .filter { + it.getProperty("url", String::class.java).getOrNull() != null || + it.getProperty("scope", String::class.java).getOrNull() != null + } val dependenciesByURL = externalDependencies .distinctBy { it.getProperty("url", String::class.java).getOrNull() diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt index 1c8a619cf..1e63737f3 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftDependency.kt @@ -38,7 +38,7 @@ class SwiftDependency( "", "", "", - SwiftDependency.DistributionMethod.GIT, + DistributionMethod.GIT, ) val XCTest = SwiftDependency( "XCTest", @@ -49,213 +49,36 @@ class SwiftDependency( "", DistributionMethod.GIT, ) - val CRT = SwiftDependency( - "AwsCommonRuntimeKit", - null, - "0.31.0", - "https://github.com/awslabs/aws-crt-swift", - "", - "aws-crt-swift", - DistributionMethod.GIT, - ) - val CLIENT_RUNTIME = SwiftDependency( - "ClientRuntime", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY = SwiftDependency( - "Smithy", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_IDENTITY_API = SwiftDependency( - "SmithyIdentityAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_IDENTITY = SwiftDependency( - "SmithyIdentity", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_RETRIES_API = SwiftDependency( - "SmithyRetriesAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_RETRIES = SwiftDependency( - "SmithyRetries", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_HTTP_API = SwiftDependency( - "SmithyHTTPAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_HTTP_AUTH_API = SwiftDependency( - "SmithyHTTPAuthAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_HTTP_AUTH = SwiftDependency( - "SmithyHTTPAuth", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_CHECKSUMS_API = SwiftDependency( - "SmithyChecksumsAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_CHECKSUMS = SwiftDependency( - "SmithyChecksums", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_STREAMS = SwiftDependency( - "SmithyStreams", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_EVENT_STREAMS_API = SwiftDependency( - "SmithyEventStreamsAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_EVENT_STREAMS_AUTH_API = SwiftDependency( - "SmithyEventStreamsAuthAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_EVENT_STREAMS = SwiftDependency( - "SmithyEventStreams", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_TEST_UTIL = SwiftDependency( - "SmithyTestUtil", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_READ_WRITE = SwiftDependency( - "SmithyReadWrite", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_TIMESTAMPS = SwiftDependency( - "SmithyTimestamps", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_XML = SwiftDependency( - "SmithyXML", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_JSON = SwiftDependency( - "SmithyJSON", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_FORM_URL = SwiftDependency( - "SmithyFormURL", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) - val SMITHY_WAITERS_API = SwiftDependency( - "SmithyWaitersAPI", - "main", - "0.0.1", - "aws-sdk-swift", - "../../../smithy-swift", - "smithy-swift", - DistributionMethod.SPR, - ) + val CLIENT_RUNTIME = smithySwiftTargetNamed("ClientRuntime") + val SMITHY = smithySwiftTargetNamed("Smithy") + val SMITHY_IDENTITY = smithySwiftTargetNamed("SmithyIdentity") + val SMITHY_RETRIES_API = smithySwiftTargetNamed("SmithyRetriesAPI") + val SMITHY_RETRIES = smithySwiftTargetNamed("SmithyRetries") + val SMITHY_HTTP_API = smithySwiftTargetNamed("SmithyHTTPAPI") + val SMITHY_HTTP_AUTH_API = smithySwiftTargetNamed("SmithyHTTPAuthAPI") + val SMITHY_HTTP_AUTH = smithySwiftTargetNamed("SmithyHTTPAuth") + val SMITHY_STREAMS = smithySwiftTargetNamed("SmithyStreams") + val SMITHY_EVENT_STREAMS_API = smithySwiftTargetNamed("SmithyEventStreamsAPI") + val SMITHY_EVENT_STREAMS = smithySwiftTargetNamed("SmithyEventStreams") + val SMITHY_TEST_UTIL = smithySwiftTargetNamed("SmithyTestUtil") + val SMITHY_READ_WRITE = smithySwiftTargetNamed("SmithyReadWrite") + val SMITHY_TIMESTAMPS = smithySwiftTargetNamed("SmithyTimestamps") + val SMITHY_XML = smithySwiftTargetNamed("SmithyXML") + val SMITHY_JSON = smithySwiftTargetNamed("SmithyJSON") + val SMITHY_FORM_URL = smithySwiftTargetNamed("SmithyFormURL") + val SMITHY_WAITERS_API = smithySwiftTargetNamed("SmithyWaitersAPI") + + private fun smithySwiftTargetNamed(name: String): SwiftDependency { + return SwiftDependency( + name, + "main", + "0.54.0", + "https://github.com/awslabs/smithy-swift", + "../../../smithy-swift", + "smithy-swift", + DistributionMethod.GIT, + ) + } } override fun getDependencies(): List { diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt index 0f6d7df65..f52228740 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftSettings.kt @@ -40,7 +40,7 @@ class SwiftSettings( val gitRepo: String, val swiftVersion: String, val mergeModels: Boolean, - val copyrightNotice: String + val copyrightNotice: String, ) { companion object { @@ -68,7 +68,7 @@ class SwiftSettings( GIT_REPO, SWIFT_VERSION, MERGE_MODELS, - COPYRIGHT_NOTICE + COPYRIGHT_NOTICE, ) ) @@ -77,7 +77,7 @@ class SwiftSettings( .orElseGet { inferService(model) } val moduleName = config.expectStringMember(MODULE_NAME).value - val version = config.expectStringMember(MODULE_VERSION).value + val moduleVersion = config.expectStringMember(MODULE_VERSION).value val desc = config.getStringMemberOrDefault(MODULE_DESCRIPTION, "$moduleName client") val homepage = config.expectStringMember(HOMEPAGE).value val author = config.expectStringMember(AUTHOR).value @@ -93,7 +93,7 @@ class SwiftSettings( return SwiftSettings( serviceId, moduleName, - version, + moduleVersion, desc, author, homepage, @@ -101,7 +101,7 @@ class SwiftSettings( gitRepo, swiftVersion, mergeModels, - copyrightNotice + copyrightNotice, ) } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt index ed8bc8e06..1d4716bfc 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt @@ -162,7 +162,7 @@ class SwiftWriter( // // Also leave out the headers when JSON or the version file is being written, // as indicated by the file extension. - val isPackageManifest = listOf(PACKAGE_MANIFEST_NAME, (PACKAGE_MANIFEST_NAME + ".swift")).contains(fullPackageName) + val isPackageManifest = "Package.swift.txt".contains(fullPackageName) val isNonSwiftSourceFile = listOf(".json", ".version").any { fullPackageName.endsWith(it) } val noHeader = isPackageManifest || isNonSwiftSourceFile return contents.takeIf { noHeader } ?: (copyrightNotice + imports + contents) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt index 3141bc2a5..d369620ec 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/integration/HttpProtocolServiceClient.kt @@ -30,6 +30,7 @@ open class HttpProtocolServiceClient( ClientRuntimeTypes.Core.Client, ) { writer.write("public static let clientName = \$S", serviceSymbol.name) + writer.write("public static let version = \$S", ctx.settings.moduleVersion) writer.write("let client: \$N", ClientRuntimeTypes.Http.SdkHttpClient) writer.write("let config: \$L", serviceConfig.typeName) writer.write("let serviceName = \$S", serviceName) diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyTestUtilTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyTestUtilTypes.kt index dda1b7e9f..1f30bcbdf 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyTestUtilTypes.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SmithyTestUtilTypes.kt @@ -5,8 +5,8 @@ import software.amazon.smithy.swift.codegen.SwiftDeclaration import software.amazon.smithy.swift.codegen.SwiftDependency object SmithyTestUtilTypes { - val TestInitializer = runtimeSymbol("TestInitializer") - val TestBaseError = runtimeSymbol("TestBaseError") + val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM) + val TestBaseError = runtimeSymbol("TestBaseError", SwiftDeclaration.STRUCT) val dummyIdentityResolver = runtimeSymbol("dummyIdentityResolver", SwiftDeclaration.FUNC) } diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt index 5a2972a58..fbfbbb498 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/HttpProtocolClientGeneratorTests.kt @@ -19,6 +19,7 @@ class HttpProtocolClientGeneratorTests { val expected = """ public class RestJsonProtocolClient: ClientRuntime.Client { public static let clientName = "RestJsonProtocolClient" + public static let version = "2019-12-16" let client: ClientRuntime.SdkHttpClient let config: RestJsonProtocolClient.RestJsonProtocolClientConfiguration let serviceName = "Rest Json Protocol" diff --git a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/manifestanddocs/PackageManifestGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/manifestanddocs/PackageManifestGeneratorTests.kt index 935484b57..a51bae834 100644 --- a/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/manifestanddocs/PackageManifestGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/manifestanddocs/PackageManifestGeneratorTests.kt @@ -6,6 +6,7 @@ package software.amazon.smithy.swift.codegen.manifestanddocs */ import io.kotest.matchers.string.shouldContain +import io.kotest.matchers.string.shouldStartWith import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test import software.amazon.smithy.swift.codegen.PackageManifestGenerator @@ -17,9 +18,15 @@ class PackageManifestGeneratorTests { private val testContext = setupTests("simple-service-with-operation-and-dependency.smithy", "smithy.example#Example") @Test - fun `it renders package manifest file with macOS and iOS platforms block`() { + fun `it starts with a swift-tools-version statement`() { val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get() assertNotNull(packageManifest) + packageManifest.shouldStartWith("// swift-tools-version: 5.5.0") + } + + fun `it renders package manifest file with macOS and iOS platforms block`() { + val packageManifest = testContext.manifest.getFileString("Package.swift").get() + assertNotNull(packageManifest) packageManifest.shouldContain( "platforms: [\n" + " .macOS(.v10_15), .iOS(.v13)\n" + @@ -59,7 +66,7 @@ class PackageManifestGeneratorTests { "MockSDK", .product( name: "SmithyTestUtil", - package: "aws-sdk-swift.smithy-swift" + package: "smithy-swift" ), ] )