From 2de56c8461eee25385fccf717e789a2675941f6e Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 25 Jun 2024 17:05:48 -0500 Subject: [PATCH 01/28] Handle SPR-based dependencies --- .../swift/codegen/PackageManifestGenerator.kt | 30 ++++++++++------ .../smithy/swift/codegen/SwiftDependency.kt | 19 +++++++--- .../smithy/swift/codegen/SwiftWriter.kt | 3 +- .../RegistryConfigIntegration.kt | 36 +++++++++++++++++++ ...swift.codegen.integration.SwiftIntegration | 1 + 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt 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 3bcf40eb7..1cfed554c 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 @@ -6,6 +6,7 @@ package software.amazon.smithy.swift.codegen import software.amazon.smithy.codegen.core.SymbolDependency import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator +import kotlin.jvm.optionals.getOrNull class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { @@ -27,21 +28,26 @@ 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).get().isNotEmpty() } - val dependenciesByURL = externalDependencies.distinctBy { it.expectProperty("url", String::class.java) } + val externalDependencies = dependencies.filter { + it.getProperty("url", String::class.java).getOrNull() != null || + it.getProperty("id", String::class.java).getOrNull() != null + } + val dependenciesByURL = externalDependencies.distinctBy { + it.getProperty("url", String::class.java).getOrNull() ?: it.getProperty("id", String::class.java).getOrNull() ?: "" + } writer.openBlock("dependencies: [", "],") { dependenciesByURL.forEach { dependency -> writer.openBlock(".package(", "),") { - - val localPath = dependency.expectProperty("localPath", String::class.java) - if (localPath.isNotEmpty()) { - writer.write("path: \$S", localPath) - } else { - val dependencyURL = dependency.expectProperty("url", String::class.java) - writer.write("url: \$S,", dependencyURL) - writer.write("from: \$S", dependency.version) + val id = dependency.getProperty("id", String::class.java).getOrNull() + id?.let { + writer.write("id: \$S,", it) + } + val url = dependency.getProperty("url", String::class.java).getOrNull() + url?.let { + writer.write("url: \$S,", it) } + writer.write("from: \$S", dependency.version) } } } @@ -56,7 +62,9 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.openBlock(".product(", "),") { val target = dependency.expectProperty("target", String::class.java) writer.write("name: \$S,", target) - writer.write("package: \$S", dependency.packageName) + val id = dependency.getProperty("id", String::class.java).getOrNull() + val packageName = id ?: dependency.packageName + writer.write("package: \$S", packageName) } } } 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 57ad31a4a..4b062d66e 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 @@ -11,11 +11,15 @@ class SwiftDependency( override val target: String, private val branch: String? = null, private val version: String, - private val url: String, + private val location: String, private val localPath: String, override var packageName: String, + private val distributionMethod: DistributionMethod = DistributionMethod.GIT, ) : Dependency { + enum class DistributionMethod { + SPR, GIT + } companion object { val NONE = SwiftDependency("", "", "", "", "", "") val XCTest = SwiftDependency("XCTest", null, "", "", "", "") @@ -202,13 +206,20 @@ class SwiftDependency( } private fun toSymbolDependency(): SymbolDependency { - return SymbolDependency.builder() + val builder = SymbolDependency.builder() .putProperty("target", target) .putProperty("branch", branch) .putProperty("localPath", localPath) .packageName(packageName) .version(version) - .putProperty("url", url) - .build() + when (distributionMethod) { + DistributionMethod.GIT -> { + builder.putProperty("url", location) + } + DistributionMethod.SPR -> { + builder.putProperty("id", location) + } + } + return builder.build() } } 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 ec923b9b5..4765df1f3 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 @@ -149,7 +149,8 @@ class SwiftWriter(private val fullPackageName: String, swiftImportContainer: Swi // Package.swift requires a special comment at the top to specify Swift tools version, // and the package manifest generator manually writes its own dependency imports // (it only imports the PackageDescription module.) - return contents.takeIf { fullPackageName == "Package" } ?: (GENERATED_FILE_HEADER + imports + contents) + val noHeader = fullPackageName == "Package" || fullPackageName == ".swiftpm/configuration/registries.json" + return contents.takeIf { noHeader } ?: (GENERATED_FILE_HEADER + imports + contents) } private class SwiftSymbolFormatter( diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt new file mode 100644 index 000000000..2d8186f13 --- /dev/null +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt @@ -0,0 +1,36 @@ +package software.amazon.smithy.swift.codegen.swiftintegrations + +import software.amazon.smithy.model.Model +import software.amazon.smithy.swift.codegen.SwiftDelegator +import software.amazon.smithy.swift.codegen.SwiftSettings +import software.amazon.smithy.swift.codegen.core.SwiftCodegenContext +import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator +import software.amazon.smithy.swift.codegen.integration.SwiftIntegration + +class RegistryConfigIntegration: SwiftIntegration { + + override fun enabledForService(model: Model, settings: SwiftSettings): Boolean = true + + override fun writeAdditionalFiles( + ctx: SwiftCodegenContext, + protocolGenerationContext: ProtocolGenerator.GenerationContext, + delegator: SwiftDelegator + ) { + protocolGenerationContext.delegator.useFileWriter(".swiftpm/configuration/registries.json") { writer -> + writer.write(""" + { + "authentication" : { + + }, + "registries" : { + "aws-sdk-swift" : { + "supportsAvailability" : false, + "url" : "https://d1b0xmm48lrxf5.cloudfront.net/" + } + }, + "version" : 1 + } + """.trimIndent()) + } + } +} \ No newline at end of file diff --git a/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration b/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration index 0932ce113..9f943d76a 100644 --- a/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration +++ b/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration @@ -3,3 +3,4 @@ software.amazon.smithy.swift.codegen.waiters.WaiterIntegration software.amazon.smithy.swift.codegen.ServiceNamespaceIntegration software.amazon.smithy.swift.codegen.DefaultClientConfigurationIntegration software.amazon.smithy.swift.codegen.integration.ExtractTelemetryLoggerConfig +software.amazon.smithy.swift.codegen.swiftintegrations.RegistryConfigIntegration From cfeb008f1d9052f672d098ad98e84e0f57e7d3b4 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 26 Jun 2024 09:36:02 -0500 Subject: [PATCH 02/28] Require smithy-swift from SPR --- .../smithy/swift/codegen/SwiftDependency.kt | 142 ++++++++++-------- 1 file changed, 81 insertions(+), 61 deletions(-) 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 4b062d66e..c2622a6c7 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 @@ -34,171 +34,191 @@ class SwiftDependency( val CLIENT_RUNTIME = SwiftDependency( "ClientRuntime", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", + DistributionMethod.SPR, ) val SMITHY = SwiftDependency( "Smithy", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_IDENTITY_API = SwiftDependency( "SmithyIdentityAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_IDENTITY = SwiftDependency( "SmithyIdentity", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_RETRIES_API = SwiftDependency( "SmithyRetriesAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_RETRIES = SwiftDependency( "SmithyRetries", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_HTTP_API = SwiftDependency( "SmithyHTTPAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_HTTP_AUTH_API = SwiftDependency( "SmithyHTTPAuthAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", ) val SMITHY_CHECKSUMS_API = SwiftDependency( "SmithyChecksumsAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_CHECKSUMS = SwiftDependency( "SmithyChecksums", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_STREAMS = SwiftDependency( "SmithyStreams", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_EVENT_STREAMS_API = SwiftDependency( "SmithyEventStreamsAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_EVENT_STREAMS_AUTH_API = SwiftDependency( "SmithyEventStreamsAuthAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_EVENT_STREAMS = SwiftDependency( "SmithyEventStreams", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_TEST_UTIL = SwiftDependency( "SmithyTestUtil", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_READ_WRITE = SwiftDependency( "SmithyReadWrite", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_TIMESTAMPS = SwiftDependency( "SmithyTimestamps", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_XML = SwiftDependency( "SmithyXML", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_JSON = SwiftDependency( "SmithyJSON", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_FORM_URL = SwiftDependency( "SmithyFormURL", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) val SMITHY_WAITERS_API = SwiftDependency( "SmithyWaitersAPI", "main", - "0.1.0", - "https://github.com/smithy-lang/smithy-swift.git", + "0.0.1", + "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", - ) + DistributionMethod.SPR, + ) } override fun getDependencies(): List { From 83e01690d305bc5f5348f64121103dce650ac1d5 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 26 Jun 2024 10:44:04 -0500 Subject: [PATCH 03/28] Fix dependencies --- .../smithy/swift/codegen/SwiftDependency.kt | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) 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 c2622a6c7..1fca668f3 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 @@ -20,6 +20,7 @@ class SwiftDependency( enum class DistributionMethod { SPR, GIT } + companion object { val NONE = SwiftDependency("", "", "", "", "", "") val XCTest = SwiftDependency("XCTest", null, "", "", "", "") @@ -30,6 +31,7 @@ class SwiftDependency( "https://github.com/awslabs/aws-crt-swift", "", "aws-crt-swift", + DistributionMethod.GIT, ) val CLIENT_RUNTIME = SwiftDependency( "ClientRuntime", @@ -48,7 +50,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_IDENTITY_API = SwiftDependency( "SmithyIdentityAPI", "main", @@ -57,7 +59,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_IDENTITY = SwiftDependency( "SmithyIdentity", "main", @@ -66,7 +68,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_RETRIES_API = SwiftDependency( "SmithyRetriesAPI", "main", @@ -75,7 +77,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_RETRIES = SwiftDependency( "SmithyRetries", "main", @@ -84,7 +86,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_HTTP_API = SwiftDependency( "SmithyHTTPAPI", "main", @@ -93,7 +95,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_HTTP_AUTH_API = SwiftDependency( "SmithyHTTPAuthAPI", "main", @@ -101,6 +103,7 @@ class SwiftDependency( "aws-sdk-swift.ClientRuntime", "../../../smithy-swift", "smithy-swift", + DistributionMethod.SPR, ) val SMITHY_CHECKSUMS_API = SwiftDependency( "SmithyChecksumsAPI", @@ -110,7 +113,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_CHECKSUMS = SwiftDependency( "SmithyChecksums", "main", @@ -119,7 +122,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_STREAMS = SwiftDependency( "SmithyStreams", "main", @@ -128,7 +131,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_EVENT_STREAMS_API = SwiftDependency( "SmithyEventStreamsAPI", "main", @@ -137,7 +140,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_EVENT_STREAMS_AUTH_API = SwiftDependency( "SmithyEventStreamsAuthAPI", "main", @@ -146,7 +149,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_EVENT_STREAMS = SwiftDependency( "SmithyEventStreams", "main", @@ -155,7 +158,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_TEST_UTIL = SwiftDependency( "SmithyTestUtil", "main", @@ -164,7 +167,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_READ_WRITE = SwiftDependency( "SmithyReadWrite", "main", @@ -173,7 +176,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_TIMESTAMPS = SwiftDependency( "SmithyTimestamps", "main", @@ -182,7 +185,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_XML = SwiftDependency( "SmithyXML", "main", @@ -191,7 +194,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_JSON = SwiftDependency( "SmithyJSON", "main", @@ -200,7 +203,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_FORM_URL = SwiftDependency( "SmithyFormURL", "main", @@ -209,7 +212,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) val SMITHY_WAITERS_API = SwiftDependency( "SmithyWaitersAPI", "main", @@ -218,7 +221,7 @@ class SwiftDependency( "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, - ) + ) } override fun getDependencies(): List { From 29d0da49a23ed96af875cfa02439724e456401be Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 26 Jun 2024 15:58:12 -0500 Subject: [PATCH 04/28] Clean up SwiftDependency --- .../swift/codegen/PackageManifestGenerator.kt | 57 ++++++++-------- .../smithy/swift/codegen/SwiftDependency.kt | 66 ++++++++++++------- .../swift/codegen/swiftmodules/SwiftTypes.kt | 2 +- 3 files changed, 73 insertions(+), 52 deletions(-) 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 1cfed554c..3eb8b4910 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 @@ -12,7 +12,7 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { fun writePackageManifest(dependencies: List) { ctx.delegator.useFileWriter("Package.swift") { writer -> - writer.write("// swift-tools-version:\$L", ctx.settings.swiftVersion) + writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) writer.write("") writer.write("import PackageDescription") writer.write("") @@ -30,26 +30,15 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { val externalDependencies = dependencies.filter { it.getProperty("url", String::class.java).getOrNull() != null || - it.getProperty("id", String::class.java).getOrNull() != null + it.getProperty("scope", String::class.java).getOrNull() != null } val dependenciesByURL = externalDependencies.distinctBy { - it.getProperty("url", String::class.java).getOrNull() ?: it.getProperty("id", String::class.java).getOrNull() ?: "" + it.getProperty("url", String::class.java).getOrNull() ?: + "${it.getProperty("scope", String::class.java).get()}.${it.packageName}" } writer.openBlock("dependencies: [", "],") { - dependenciesByURL.forEach { dependency -> - writer.openBlock(".package(", "),") { - val id = dependency.getProperty("id", String::class.java).getOrNull() - id?.let { - writer.write("id: \$S,", it) - } - val url = dependency.getProperty("url", String::class.java).getOrNull() - url?.let { - writer.write("url: \$S,", it) - } - writer.write("from: \$S", dependency.version) - } - } + dependenciesByURL.forEach { writePackageDependency(writer, it) } } val dependenciesByTarget = externalDependencies.distinctBy { it.expectProperty("target", String::class.java) + it.packageName } @@ -58,26 +47,42 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.openBlock(".target(", "),") { writer.write("name: \$S,", ctx.settings.moduleName) writer.openBlock("dependencies: [", "]") { - for (dependency in dependenciesByTarget) { - writer.openBlock(".product(", "),") { - val target = dependency.expectProperty("target", String::class.java) - writer.write("name: \$S,", target) - val id = dependency.getProperty("id", String::class.java).getOrNull() - val packageName = id ?: dependency.packageName - writer.write("package: \$S", packageName) - } - } + dependenciesByTarget.forEach { writeTargetDependency(writer, it) } } } writer.openBlock(".testTarget(", ")") { writer.write("name: \$S,", ctx.settings.testModuleName) writer.openBlock("dependencies: [", "]") { writer.write("\$S,", ctx.settings.moduleName) - writer.write(".product(name: \"SmithyTestUtil\", package: \"smithy-swift\"),") + SwiftDependency.SMITHY_TEST_UTIL.dependencies.forEach { writeTargetDependency(writer, it) } } } } } } } + + private fun writePackageDependency(writer: SwiftWriter, dependency: SymbolDependency) { + writer.openBlock(".package(", "),") { + val scope = dependency.getProperty("scope", String::class.java).getOrNull() + scope?.let { + writer.write("id: \"\$L.\$L\",", it, dependency.packageName) + } + val url = dependency.getProperty("url", String::class.java).getOrNull() + url?.let { + writer.write("url: \$S,", it) + } + writer.write("from: \$S", dependency.version) + } + } + + private fun writeTargetDependency(writer: SwiftWriter, dependency: SymbolDependency) { + writer.openBlock(".product(", "),") { + val target = dependency.expectProperty("target", String::class.java) + writer.write("name: \$S,", target) + val scope = dependency.getProperty("scope", String::class.java).getOrNull() + val packageName = scope?.let { "$it.${dependency.packageName}" } ?: dependency.packageName + writer.write("package: \$S", packageName) + } + } } 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 1fca668f3..cf6b37f6e 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 @@ -14,7 +14,7 @@ class SwiftDependency( private val location: String, private val localPath: String, override var packageName: String, - private val distributionMethod: DistributionMethod = DistributionMethod.GIT, + private val distributionMethod: DistributionMethod, ) : Dependency { enum class DistributionMethod { @@ -22,8 +22,24 @@ class SwiftDependency( } companion object { - val NONE = SwiftDependency("", "", "", "", "", "") - val XCTest = SwiftDependency("XCTest", null, "", "", "", "") + val NONE = SwiftDependency( + "", + "", + "", + "", + "", + "", + DistributionMethod.GIT, + ) + val XCTest = SwiftDependency( + "XCTest", + null, + "", + "", + "", + "", + DistributionMethod.GIT, + ) val CRT = SwiftDependency( "AwsCommonRuntimeKit", null, @@ -37,7 +53,7 @@ class SwiftDependency( "ClientRuntime", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -46,7 +62,7 @@ class SwiftDependency( "Smithy", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -55,7 +71,7 @@ class SwiftDependency( "SmithyIdentityAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -64,7 +80,7 @@ class SwiftDependency( "SmithyIdentity", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -73,7 +89,7 @@ class SwiftDependency( "SmithyRetriesAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -82,7 +98,7 @@ class SwiftDependency( "SmithyRetries", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -91,7 +107,7 @@ class SwiftDependency( "SmithyHTTPAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -100,7 +116,7 @@ class SwiftDependency( "SmithyHTTPAuthAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -109,7 +125,7 @@ class SwiftDependency( "SmithyChecksumsAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -118,7 +134,7 @@ class SwiftDependency( "SmithyChecksums", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -127,7 +143,7 @@ class SwiftDependency( "SmithyStreams", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -136,7 +152,7 @@ class SwiftDependency( "SmithyEventStreamsAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -145,7 +161,7 @@ class SwiftDependency( "SmithyEventStreamsAuthAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -154,7 +170,7 @@ class SwiftDependency( "SmithyEventStreams", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -163,7 +179,7 @@ class SwiftDependency( "SmithyTestUtil", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -172,7 +188,7 @@ class SwiftDependency( "SmithyReadWrite", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -181,7 +197,7 @@ class SwiftDependency( "SmithyTimestamps", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -190,7 +206,7 @@ class SwiftDependency( "SmithyXML", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -199,7 +215,7 @@ class SwiftDependency( "SmithyJSON", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -208,7 +224,7 @@ class SwiftDependency( "SmithyFormURL", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -217,7 +233,7 @@ class SwiftDependency( "SmithyWaitersAPI", "main", "0.0.1", - "aws-sdk-swift.ClientRuntime", + "aws-sdk-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.SPR, @@ -240,7 +256,7 @@ class SwiftDependency( builder.putProperty("url", location) } DistributionMethod.SPR -> { - builder.putProperty("id", location) + builder.putProperty("scope", location) } } return builder.build() diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt index 4fa32b006..3e2fe8922 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt @@ -37,6 +37,6 @@ object SwiftTypes { private fun builtInSymbol(name: String, declaration: SwiftDeclaration? = null): Symbol = SwiftSymbol.make( name, declaration, - SwiftDependency("Swift", "", "", "", "", ""), + SwiftDependency("Swift", "", "", "", "", "", SwiftDependency.DistributionMethod.GIT), null, ) From 1bd24942f2b96e5d77f41881d2ff2fafafc6ae0b Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Thu, 27 Jun 2024 14:10:47 -0500 Subject: [PATCH 05/28] Simplify package dependency writer --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3eb8b4910..ff1dadded 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 @@ -66,7 +66,7 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.openBlock(".package(", "),") { val scope = dependency.getProperty("scope", String::class.java).getOrNull() scope?.let { - writer.write("id: \"\$L.\$L\",", it, dependency.packageName) + writer.write("id: \$S,", "$it.${dependency.packageName}") } val url = dependency.getProperty("url", String::class.java).getOrNull() url?.let { From b798caa4bca5a7d9f4473e66735e721d9e774d96 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 13:25:18 -0500 Subject: [PATCH 06/28] Code cleanup --- .../amazon/smithy/swift/codegen/SwiftDependency.kt | 9 +++++++++ .../software/amazon/smithy/swift/codegen/SwiftWriter.kt | 4 +++- .../smithy/swift/codegen/swiftmodules/SwiftTypes.kt | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) 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 cf6b37f6e..601f0acca 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 @@ -31,6 +31,15 @@ class SwiftDependency( "", DistributionMethod.GIT, ) + val SWIFT = SwiftDependency( + "Swift", + "", + "", + "", + "", + "", + SwiftDependency.DistributionMethod.GIT, + ) val XCTest = SwiftDependency( "XCTest", null, 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 4765df1f3..789303397 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 @@ -149,7 +149,9 @@ class SwiftWriter(private val fullPackageName: String, swiftImportContainer: Swi // Package.swift requires a special comment at the top to specify Swift tools version, // and the package manifest generator manually writes its own dependency imports // (it only imports the PackageDescription module.) - val noHeader = fullPackageName == "Package" || fullPackageName == ".swiftpm/configuration/registries.json" + // + // Also leave out the headers when JSON is being written, as indicated by the file extension. + val noHeader = fullPackageName == "Package" || fullPackageName.endsWith(".json") return contents.takeIf { noHeader } ?: (GENERATED_FILE_HEADER + imports + contents) } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt index 3e2fe8922..784d3776c 100644 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/SwiftTypes.kt @@ -37,6 +37,6 @@ object SwiftTypes { private fun builtInSymbol(name: String, declaration: SwiftDeclaration? = null): Symbol = SwiftSymbol.make( name, declaration, - SwiftDependency("Swift", "", "", "", "", "", SwiftDependency.DistributionMethod.GIT), + SwiftDependency.SWIFT, null, ) From 0df6f1a1229918dc0ce58bedab436b8ab8a924f3 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 14:34:49 -0500 Subject: [PATCH 07/28] Move registry config JSON gen to AWS --- .../RegistryConfigIntegration.kt | 36 ------------------- ...swift.codegen.integration.SwiftIntegration | 1 - 2 files changed, 37 deletions(-) delete mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt deleted file mode 100644 index 2d8186f13..000000000 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftintegrations/RegistryConfigIntegration.kt +++ /dev/null @@ -1,36 +0,0 @@ -package software.amazon.smithy.swift.codegen.swiftintegrations - -import software.amazon.smithy.model.Model -import software.amazon.smithy.swift.codegen.SwiftDelegator -import software.amazon.smithy.swift.codegen.SwiftSettings -import software.amazon.smithy.swift.codegen.core.SwiftCodegenContext -import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator -import software.amazon.smithy.swift.codegen.integration.SwiftIntegration - -class RegistryConfigIntegration: SwiftIntegration { - - override fun enabledForService(model: Model, settings: SwiftSettings): Boolean = true - - override fun writeAdditionalFiles( - ctx: SwiftCodegenContext, - protocolGenerationContext: ProtocolGenerator.GenerationContext, - delegator: SwiftDelegator - ) { - protocolGenerationContext.delegator.useFileWriter(".swiftpm/configuration/registries.json") { writer -> - writer.write(""" - { - "authentication" : { - - }, - "registries" : { - "aws-sdk-swift" : { - "supportsAvailability" : false, - "url" : "https://d1b0xmm48lrxf5.cloudfront.net/" - } - }, - "version" : 1 - } - """.trimIndent()) - } - } -} \ No newline at end of file diff --git a/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration b/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration index 9f943d76a..0932ce113 100644 --- a/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration +++ b/smithy-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration @@ -3,4 +3,3 @@ software.amazon.smithy.swift.codegen.waiters.WaiterIntegration software.amazon.smithy.swift.codegen.ServiceNamespaceIntegration software.amazon.smithy.swift.codegen.DefaultClientConfigurationIntegration software.amazon.smithy.swift.codegen.integration.ExtractTelemetryLoggerConfig -software.amazon.smithy.swift.codegen.swiftintegrations.RegistryConfigIntegration From c2a402f39b1f60df357ad170a3c687dcd28986ea Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 16:54:21 -0500 Subject: [PATCH 08/28] Accommodate resources in service client --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 5 ++++- .../software/amazon/smithy/swift/codegen/SwiftWriter.kt | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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 ff1dadded..239cdd6b4 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 @@ -46,9 +46,12 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.openBlock("targets: [", "]") { writer.openBlock(".target(", "),") { writer.write("name: \$S,", ctx.settings.moduleName) - writer.openBlock("dependencies: [", "]") { + writer.openBlock("dependencies: [", "],") { dependenciesByTarget.forEach { writeTargetDependency(writer, it) } } + writer.openBlock("resources: [", "]") { + writer.write(".process(\"Resources\")") + } } writer.openBlock(".testTarget(", ")") { writer.write("name: \$S,", ctx.settings.testModuleName) 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 789303397..0932a92ef 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 @@ -150,8 +150,9 @@ class SwiftWriter(private val fullPackageName: String, swiftImportContainer: Swi // and the package manifest generator manually writes its own dependency imports // (it only imports the PackageDescription module.) // - // Also leave out the headers when JSON is being written, as indicated by the file extension. - val noHeader = fullPackageName == "Package" || fullPackageName.endsWith(".json") + // Also leave out the headers when JSON or the version file is being written, + // as indicated by the file extension. + val noHeader = fullPackageName == "Package" || listOf(".json", ".version").any { fullPackageName.endsWith(it) } return contents.takeIf { noHeader } ?: (GENERATED_FILE_HEADER + imports + contents) } From 50bbef616b92e758a5d5fa5f820c27102f80c532 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 17:27:44 -0500 Subject: [PATCH 09/28] Configurable Package.swift name --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 4 +++- .../software/amazon/smithy/swift/codegen/SwiftWriter.kt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) 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 239cdd6b4..79bcdf093 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,10 +8,12 @@ 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.swift") { writer -> + ctx.delegator.useFileWriter(PACKAGE_MANIFEST_NAME) { writer -> writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) writer.write("") writer.write("import PackageDescription") 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 0932a92ef..6f3b81595 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 @@ -152,7 +152,9 @@ class SwiftWriter(private val fullPackageName: String, swiftImportContainer: Swi // // Also leave out the headers when JSON or the version file is being written, // as indicated by the file extension. - val noHeader = fullPackageName == "Package" || listOf(".json", ".version").any { fullPackageName.endsWith(it) } + val isPackageManifest = listOf(PACKAGE_MANIFEST_NAME, (PACKAGE_MANIFEST_NAME + ".swift")).contains(fullPackageName) + val isNonSwiftSourceFile = listOf(".json", ".version").any { fullPackageName.endsWith(it) } + val noHeader = isPackageManifest || isNonSwiftSourceFile return contents.takeIf { noHeader } ?: (GENERATED_FILE_HEADER + imports + contents) } From 7bc666a5eda0c5401181adbe93dc5ffbe968af16 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 19:32:36 -0500 Subject: [PATCH 10/28] Fix codegen tests --- .../test/kotlin/PackageManifestGeneratorTests.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt index f963572eb..3721ef4d3 100644 --- a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt @@ -14,7 +14,7 @@ class PackageManifestGeneratorTests { @Test fun `it renders package manifest file with macOS and iOS platforms block`() { - val packageManifest = testContext.manifest.getFileString("Package.swift").get() + val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get() assertNotNull(packageManifest) packageManifest.shouldContain( "platforms: [\n" + @@ -25,7 +25,7 @@ class PackageManifestGeneratorTests { @Test fun `it renders package manifest file with single library in product block`() { - val packageManifest = testContext.manifest.getFileString("Package.swift").get() + val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get() assertNotNull(packageManifest) packageManifest.shouldContain( "products: [\n" + @@ -37,20 +37,26 @@ class PackageManifestGeneratorTests { @Test fun `it renders package manifest file with target and test target`() { println(testContext.manifest.files) - val packageManifest = testContext.manifest.getFileString("Package.swift").get() + val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get() assertNotNull(packageManifest) val expected = """ targets: [ .target( name: "MockSDK", dependencies: [ + ], + resources: [ + .process("Resources") ] ), .testTarget( name: "MockSDKTests", dependencies: [ "MockSDK", - .product(name: "SmithyTestUtil", package: "smithy-swift"), + .product( + name: "SmithyTestUtil", + package: "aws-sdk-swift.smithy-swift" + ), ] ) ] From 9ccb6752bd9b58c2f3d54a560c7e75ee2ff90a13 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 19:39:27 -0500 Subject: [PATCH 11/28] Fix ktlint --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 79bcdf093..04307efc3 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 @@ -35,8 +35,8 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { it.getProperty("scope", String::class.java).getOrNull() != null } val dependenciesByURL = externalDependencies.distinctBy { - it.getProperty("url", String::class.java).getOrNull() ?: - "${it.getProperty("scope", String::class.java).get()}.${it.packageName}" + it.getProperty("url", String::class.java).getOrNull() + ?: "${it.getProperty("scope", String::class.java).get()}.${it.packageName}" } writer.openBlock("dependencies: [", "],") { From 9b57567ba6e6bb46064c811e57fb9698b93ae538 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 28 Jun 2024 23:41:22 -0500 Subject: [PATCH 12/28] Revert "Configurable Package.swift name" This reverts commit 50bbef616b92e758a5d5fa5f820c27102f80c532. --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 4 +--- .../software/amazon/smithy/swift/codegen/SwiftWriter.kt | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) 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 04307efc3..0a500e88a 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") { writer -> writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) writer.write("") writer.write("import PackageDescription") 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 6f3b81595..0932a92ef 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 @@ -152,9 +152,7 @@ class SwiftWriter(private val fullPackageName: String, swiftImportContainer: Swi // // 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 isNonSwiftSourceFile = listOf(".json", ".version").any { fullPackageName.endsWith(it) } - val noHeader = isPackageManifest || isNonSwiftSourceFile + val noHeader = fullPackageName == "Package" || listOf(".json", ".version").any { fullPackageName.endsWith(it) } return contents.takeIf { noHeader } ?: (GENERATED_FILE_HEADER + imports + contents) } From 003caeeea3d2edaabbcec1a238ccc67dd950dab0 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 2 Jul 2024 16:33:19 -0500 Subject: [PATCH 13/28] Set version static var in client --- .../swift/codegen/integration/HttpProtocolServiceClient.kt | 1 + 1 file changed, 1 insertion(+) 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) From af54db30bc8fb63ba510a5839bb080a167f7c8c4 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 3 Jul 2024 14:12:22 -0500 Subject: [PATCH 14/28] Fix package manifest generator --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 4 +++- .../src/test/kotlin/HttpProtocolClientGeneratorTests.kt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) 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 0a500e88a..04307efc3 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,10 +8,12 @@ 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.swift") { writer -> + ctx.delegator.useFileWriter(PACKAGE_MANIFEST_NAME) { writer -> writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) writer.write("") writer.write("import PackageDescription") diff --git a/smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt index 434b0750e..7c31f8b25 100644 --- a/smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/HttpProtocolClientGeneratorTests.kt @@ -17,6 +17,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" From fb1734e95ea53f6891f6b0aa10fdd24aab96e823 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 3 Jul 2024 17:30:30 -0500 Subject: [PATCH 15/28] Eliminate CRT from generated code, use smithy-swift from Git --- Package.swift | 5 +- Sources/SmithyTestUtil/TestInitializer.swift | 15 ++ .../swift/codegen/PackageManifestGenerator.kt | 2 +- .../smithy/swift/codegen/SwiftDependency.kt | 233 +++--------------- .../smithy/swift/codegen/SwiftWriter.kt | 2 +- .../swift/codegen/swiftmodules/AWSCRTTypes.kt | 16 -- .../swiftmodules/SmithyTestUtilTypes.kt | 1 + .../kotlin/PackageManifestGeneratorTests.kt | 21 +- 8 files changed, 71 insertions(+), 224 deletions(-) create mode 100644 Sources/SmithyTestUtil/TestInitializer.swift delete mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt diff --git a/Package.swift b/Package.swift index 70447daf1..021c07270 100644 --- a/Package.swift +++ b/Package.swift @@ -130,7 +130,10 @@ let package = Package( ), .target( name: "SmithyTestUtil", - dependencies: ["ClientRuntime"] + dependencies: [ + "ClientRuntime", + .product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"), + ] ), .target( name: "SmithyIdentity", diff --git a/Sources/SmithyTestUtil/TestInitializer.swift b/Sources/SmithyTestUtil/TestInitializer.swift new file mode 100644 index 000000000..2697772af --- /dev/null +++ b/Sources/SmithyTestUtil/TestInitializer.swift @@ -0,0 +1,15 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import struct AwsCommonRuntimeKit.CommonRuntimeKit + +public enum TestInitializer { + + public static func initialize() { + CommonRuntimeKit.initialize() + } +} 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 04307efc3..1b053ebfb 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,7 +8,7 @@ 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" +val PACKAGE_MANIFEST_NAME = "Package.swift" class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { 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 601f0acca..bb66359ae 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,204 +49,39 @@ class SwiftDependency( "", DistributionMethod.GIT, ) - val CRT = SwiftDependency( - "AwsCommonRuntimeKit", - null, - "0.30.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_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_API = smithySwiftTargetNamed("SmithyIdentityAPI") + 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_CHECKSUMS_API = smithySwiftTargetNamed("SmithyChecksumsAPI") + val SMITHY_CHECKSUMS = smithySwiftTargetNamed("SmithyChecksums") + val SMITHY_STREAMS = smithySwiftTargetNamed("SmithyStreams") + val SMITHY_EVENT_STREAMS_API = smithySwiftTargetNamed("SmithyEventStreamsAPI") + val SMITHY_EVENT_STREAMS_AUTH_API = smithySwiftTargetNamed("SmithyEventStreamsAuthAPI") + 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.0.1", + "https://github.com/smithy-lang/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/SwiftWriter.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/SwiftWriter.kt index 2bee94e35..a9cf462bb 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 @@ -157,7 +157,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_MANIFEST_NAME.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/swiftmodules/AWSCRTTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt deleted file mode 100644 index 651ef398c..000000000 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt +++ /dev/null @@ -1,16 +0,0 @@ -package software.amazon.smithy.swift.codegen.swiftmodules - -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.swift.codegen.SwiftDeclaration -import software.amazon.smithy.swift.codegen.SwiftDependency - -object CRT { - val CommonRuntimeKit = runtimeSymbol("CommonRuntimeKit", SwiftDeclaration.STRUCT) -} - -private fun runtimeSymbol(name: String, declaration: SwiftDeclaration? = null, spiName: String? = null): Symbol = SwiftSymbol.make( - name, - declaration, - SwiftDependency.CRT, - spiName, -) 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 751fb4952..6ba879a62 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,6 +5,7 @@ import software.amazon.smithy.swift.codegen.SwiftDependency import software.amazon.smithy.swift.codegen.model.buildSymbol object SmithyTestUtilTypes { + val TestInitializer = runtimeSymbol("TestInitializer") val TestBaseError = runtimeSymbol("TestBaseError") } diff --git a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt index 3721ef4d3..e72f179c6 100644 --- a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt @@ -4,6 +4,7 @@ */ import io.kotest.matchers.string.shouldContain +import io.kotest.matchers.string.shouldStartWith import mocks.MockHTTPAWSJson11ProtocolGenerator import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Test @@ -12,20 +13,28 @@ import software.amazon.smithy.swift.codegen.PackageManifestGenerator class PackageManifestGeneratorTests { private val testContext = setupTests("simple-service-with-operation-and-dependency.smithy", "smithy.example#Example") + val PACKAGE_MANIFEST_NAME = "Package.swift" + @Test + fun `it starts with a swift-tools-version statement`() { + val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).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.txt").get() + val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).get() assertNotNull(packageManifest) packageManifest.shouldContain( "platforms: [\n" + - " .macOS(.v10_15), .iOS(.v13)\n" + - " ]" + " .macOS(.v10_15), .iOS(.v13)\n" + + " ]" ) } @Test fun `it renders package manifest file with single library in product block`() { - val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get() + val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).get() assertNotNull(packageManifest) packageManifest.shouldContain( "products: [\n" + @@ -37,7 +46,7 @@ class PackageManifestGeneratorTests { @Test fun `it renders package manifest file with target and test target`() { println(testContext.manifest.files) - val packageManifest = testContext.manifest.getFileString("Package.swift.txt").get() + val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).get() assertNotNull(packageManifest) val expected = """ targets: [ @@ -55,7 +64,7 @@ class PackageManifestGeneratorTests { "MockSDK", .product( name: "SmithyTestUtil", - package: "aws-sdk-swift.smithy-swift" + package: "smithy-swift" ), ] ) From 135fa12241911abf273146e1e9fc9cce29f0569c Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 5 Jul 2024 17:00:52 -0500 Subject: [PATCH 16/28] Lock to exact version on jbelkins fork --- .../amazon/smithy/swift/codegen/PackageManifestGenerator.kt | 2 +- .../software/amazon/smithy/swift/codegen/SwiftDependency.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 1b053ebfb..3409c7518 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 @@ -77,7 +77,7 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { url?.let { writer.write("url: \$S,", it) } - writer.write("from: \$S", dependency.version) + writer.write("exact: \$S", dependency.version) } } 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 bb66359ae..81b910ccf 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 @@ -75,8 +75,8 @@ class SwiftDependency( return SwiftDependency( name, "main", - "0.0.1", - "https://github.com/smithy-lang/smithy-swift", + "0.60.0", + "https://github.com/jbelkins/smithy-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.GIT, From 9132d1740ccdc8fe76ebc6bc713880b3b8ba0b82 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 5 Jul 2024 19:37:18 -0500 Subject: [PATCH 17/28] Restore compatibility with current smithy-swift --- .../swift/codegen/PackageManifestGenerator.kt | 1 + .../smithy/swift/codegen/SwiftDependency.kt | 13 +++++++++++-- .../swift/codegen/swiftmodules/AWSCRTTypes.kt | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt 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 3409c7518..2467f8850 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 @@ -60,6 +60,7 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.openBlock("dependencies: [", "]") { writer.write("\$S,", ctx.settings.moduleName) SwiftDependency.SMITHY_TEST_UTIL.dependencies.forEach { writeTargetDependency(writer, it) } + SwiftDependency.CRT.dependencies.forEach { writeTargetDependency(writer, it) } } } } 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 81b910ccf..e98d1c635 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 @@ -49,6 +49,15 @@ class SwiftDependency( "", DistributionMethod.GIT, ) + val CRT = SwiftDependency( + "AwsCommonRuntimeKit", + null, + "0.32.0", + "https://github.com/awslabs/aws-crt-swift", + "", + "aws-crt-swift", + DistributionMethod.GIT, + ) val CLIENT_RUNTIME = smithySwiftTargetNamed("ClientRuntime") val SMITHY = smithySwiftTargetNamed("Smithy") val SMITHY_IDENTITY_API = smithySwiftTargetNamed("SmithyIdentityAPI") @@ -75,8 +84,8 @@ class SwiftDependency( return SwiftDependency( name, "main", - "0.60.0", - "https://github.com/jbelkins/smithy-swift", + "0.51.0", + "https://github.com/smithy-lang/smithy-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.GIT, diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt new file mode 100644 index 000000000..651ef398c --- /dev/null +++ b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt @@ -0,0 +1,16 @@ +package software.amazon.smithy.swift.codegen.swiftmodules + +import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.swift.codegen.SwiftDeclaration +import software.amazon.smithy.swift.codegen.SwiftDependency + +object CRT { + val CommonRuntimeKit = runtimeSymbol("CommonRuntimeKit", SwiftDeclaration.STRUCT) +} + +private fun runtimeSymbol(name: String, declaration: SwiftDeclaration? = null, spiName: String? = null): Symbol = SwiftSymbol.make( + name, + declaration, + SwiftDependency.CRT, + spiName, +) From eed4a9c4f22c1fd66bb69d711310560700759544 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Sat, 6 Jul 2024 00:48:22 -0500 Subject: [PATCH 18/28] Point smithy-swift to fork --- .../amazon/smithy/swift/codegen/SwiftDependency.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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 e98d1c635..52475e4d8 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 @@ -60,17 +60,13 @@ class SwiftDependency( ) val CLIENT_RUNTIME = smithySwiftTargetNamed("ClientRuntime") val SMITHY = smithySwiftTargetNamed("Smithy") - val SMITHY_IDENTITY_API = smithySwiftTargetNamed("SmithyIdentityAPI") 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_CHECKSUMS_API = smithySwiftTargetNamed("SmithyChecksumsAPI") - val SMITHY_CHECKSUMS = smithySwiftTargetNamed("SmithyChecksums") val SMITHY_STREAMS = smithySwiftTargetNamed("SmithyStreams") val SMITHY_EVENT_STREAMS_API = smithySwiftTargetNamed("SmithyEventStreamsAPI") - val SMITHY_EVENT_STREAMS_AUTH_API = smithySwiftTargetNamed("SmithyEventStreamsAuthAPI") val SMITHY_EVENT_STREAMS = smithySwiftTargetNamed("SmithyEventStreams") val SMITHY_TEST_UTIL = smithySwiftTargetNamed("SmithyTestUtil") val SMITHY_READ_WRITE = smithySwiftTargetNamed("SmithyReadWrite") @@ -84,8 +80,8 @@ class SwiftDependency( return SwiftDependency( name, "main", - "0.51.0", - "https://github.com/smithy-lang/smithy-swift", + "0.100.0", + "https://github.com/jbelkins/smithy-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.GIT, From 33e919d77770081541b8dfe539fefa8e6df7c450 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Wed, 10 Jul 2024 20:52:07 -0500 Subject: [PATCH 19/28] Use SmithyTestUtils to initialize CRT --- .../swift/codegen/PackageManifestGenerator.kt | 1 - .../swift/codegen/swiftmodules/AWSCRTTypes.kt | 16 ---------------- 2 files changed, 17 deletions(-) delete mode 100644 smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt 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 2467f8850..3409c7518 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 @@ -60,7 +60,6 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { writer.openBlock("dependencies: [", "]") { writer.write("\$S,", ctx.settings.moduleName) SwiftDependency.SMITHY_TEST_UTIL.dependencies.forEach { writeTargetDependency(writer, it) } - SwiftDependency.CRT.dependencies.forEach { writeTargetDependency(writer, it) } } } } diff --git a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt b/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt deleted file mode 100644 index 651ef398c..000000000 --- a/smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/swiftmodules/AWSCRTTypes.kt +++ /dev/null @@ -1,16 +0,0 @@ -package software.amazon.smithy.swift.codegen.swiftmodules - -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.swift.codegen.SwiftDeclaration -import software.amazon.smithy.swift.codegen.SwiftDependency - -object CRT { - val CommonRuntimeKit = runtimeSymbol("CommonRuntimeKit", SwiftDeclaration.STRUCT) -} - -private fun runtimeSymbol(name: String, declaration: SwiftDeclaration? = null, spiName: String? = null): Symbol = SwiftSymbol.make( - name, - declaration, - SwiftDependency.CRT, - spiName, -) From 6011f2f394a783217dbe7bc69c0222545fe2e2b4 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Thu, 11 Jul 2024 14:46:29 -0500 Subject: [PATCH 20/28] Add declaration type to TestInitializer, disable Package.swift in service clients --- .../swift/codegen/PackageManifestGenerator.kt | 2 +- .../codegen/swiftmodules/SmithyTestUtilTypes.kt | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) 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 3409c7518..b9a7257a8 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,7 +8,7 @@ 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" +val PACKAGE_MANIFEST_NAME = "Package.swift.txt" class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) { 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 3c74d225b..bd29b159b 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 @@ -1,17 +1,19 @@ package software.amazon.smithy.swift.codegen.swiftmodules import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.swift.codegen.SwiftDeclaration import software.amazon.smithy.swift.codegen.SwiftDependency import software.amazon.smithy.swift.codegen.model.buildSymbol object SmithyTestUtilTypes { - val TestInitializer = runtimeSymbol("TestInitializer") + val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM) val TestBaseError = runtimeSymbol("TestBaseError") val SelectNoAuthScheme = runtimeSymbol("SelectNoAuthScheme") } -private fun runtimeSymbol(name: String): Symbol = buildSymbol { - this.name = name - this.namespace = SwiftDependency.SMITHY_TEST_UTIL.target - dependency(SwiftDependency.SMITHY_TEST_UTIL) -} +private fun runtimeSymbol(name: String, declaration: SwiftDeclaration? = null): Symbol = SwiftSymbol.make( + name, + declaration, + SwiftDependency.SMITHY_TEST_UTIL, + null, +) From f84d6169714ec7a09e4060b06da8b948bd84fb85 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Thu, 11 Jul 2024 14:56:49 -0500 Subject: [PATCH 21/28] Fix codegen tests --- .../swift/codegen/swiftmodules/SmithyTestUtilTypes.kt | 1 - .../src/test/kotlin/PackageManifestGeneratorTests.kt | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) 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 bd29b159b..962243b16 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 @@ -3,7 +3,6 @@ package software.amazon.smithy.swift.codegen.swiftmodules import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.swift.codegen.SwiftDeclaration import software.amazon.smithy.swift.codegen.SwiftDependency -import software.amazon.smithy.swift.codegen.model.buildSymbol object SmithyTestUtilTypes { val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM) diff --git a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt index e72f179c6..b7fffc05c 100644 --- a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt @@ -13,7 +13,7 @@ import software.amazon.smithy.swift.codegen.PackageManifestGenerator class PackageManifestGeneratorTests { private val testContext = setupTests("simple-service-with-operation-and-dependency.smithy", "smithy.example#Example") - val PACKAGE_MANIFEST_NAME = "Package.swift" + val PACKAGE_MANIFEST_NAME = "Package.swift.txt" @Test fun `it starts with a swift-tools-version statement`() { @@ -27,8 +27,8 @@ class PackageManifestGeneratorTests { assertNotNull(packageManifest) packageManifest.shouldContain( "platforms: [\n" + - " .macOS(.v10_15), .iOS(.v13)\n" + - " ]" + " .macOS(.v10_15), .iOS(.v13)\n" + + " ]" ) } From c3934e1c6b7969bca7fa6b8944d0dd57c884c660 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Thu, 11 Jul 2024 15:30:08 -0500 Subject: [PATCH 22/28] Remove CRT SwiftDependency --- .../amazon/smithy/swift/codegen/SwiftDependency.kt | 9 --------- 1 file changed, 9 deletions(-) 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 52475e4d8..873e11c2a 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 @@ -49,15 +49,6 @@ class SwiftDependency( "", DistributionMethod.GIT, ) - val CRT = SwiftDependency( - "AwsCommonRuntimeKit", - null, - "0.32.0", - "https://github.com/awslabs/aws-crt-swift", - "", - "aws-crt-swift", - DistributionMethod.GIT, - ) val CLIENT_RUNTIME = smithySwiftTargetNamed("ClientRuntime") val SMITHY = smithySwiftTargetNamed("Smithy") val SMITHY_IDENTITY = smithySwiftTargetNamed("SmithyIdentity") From 4113fd7d2ae498ea72da29c75d6db6de07821d4c Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 12 Jul 2024 12:42:26 -0500 Subject: [PATCH 23/28] Don't link service client to SmithyTestUtil --- .../smithy/swift/codegen/PackageManifestGenerator.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 b9a7257a8..4dff3805d 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 @@ -30,10 +30,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() ?: "${it.getProperty("scope", String::class.java).get()}.${it.packageName}" From 46123785a05e32b75be651296fee3ab6f8f52068 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 12 Jul 2024 14:14:54 -0500 Subject: [PATCH 24/28] Remove parameterized package manifest name --- .../smithy/swift/codegen/PackageManifestGenerator.kt | 4 +--- .../amazon/smithy/swift/codegen/SwiftWriter.kt | 2 +- .../src/test/kotlin/PackageManifestGeneratorTests.kt | 10 ++++------ 3 files changed, 6 insertions(+), 10 deletions(-) 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 4dff3805d..46c976178 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") { writer -> writer.write("// swift-tools-version: \$L", ctx.settings.swiftVersion) writer.write("") writer.write("import PackageDescription") 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 a9cf462bb..9f9294d13 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 @@ -157,7 +157,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 = PACKAGE_MANIFEST_NAME.contains(fullPackageName) + val isPackageManifest = "Package.swift".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/test/kotlin/PackageManifestGeneratorTests.kt b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt index b7fffc05c..dcd510e82 100644 --- a/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt +++ b/smithy-swift-codegen/src/test/kotlin/PackageManifestGeneratorTests.kt @@ -13,17 +13,15 @@ import software.amazon.smithy.swift.codegen.PackageManifestGenerator class PackageManifestGeneratorTests { private val testContext = setupTests("simple-service-with-operation-and-dependency.smithy", "smithy.example#Example") - val PACKAGE_MANIFEST_NAME = "Package.swift.txt" - @Test fun `it starts with a swift-tools-version statement`() { - val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).get() + val packageManifest = testContext.manifest.getFileString("Package.swift").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_MANIFEST_NAME).get() + val packageManifest = testContext.manifest.getFileString("Package.swift").get() assertNotNull(packageManifest) packageManifest.shouldContain( "platforms: [\n" + @@ -34,7 +32,7 @@ class PackageManifestGeneratorTests { @Test fun `it renders package manifest file with single library in product block`() { - val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).get() + val packageManifest = testContext.manifest.getFileString("Package.swift").get() assertNotNull(packageManifest) packageManifest.shouldContain( "products: [\n" + @@ -46,7 +44,7 @@ class PackageManifestGeneratorTests { @Test fun `it renders package manifest file with target and test target`() { println(testContext.manifest.files) - val packageManifest = testContext.manifest.getFileString(PACKAGE_MANIFEST_NAME).get() + val packageManifest = testContext.manifest.getFileString("Package.swift").get() assertNotNull(packageManifest) val expected = """ targets: [ From 72e679bd9d35fa66b7c900b7f9d0c14c69c3ef62 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Fri, 12 Jul 2024 17:36:11 -0500 Subject: [PATCH 25/28] SwiftSettings cleanup --- .../amazon/smithy/swift/codegen/SwiftSettings.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 4a8979d4e..21a9e0539 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 @@ -42,7 +42,7 @@ class SwiftSettings( val swiftVersion: String, var useInterceptors: Boolean, val mergeModels: Boolean, - val copyrightNotice: String + val copyrightNotice: String, ) { companion object { @@ -71,7 +71,7 @@ class SwiftSettings( SWIFT_VERSION, USE_INTERCEPTORS, MERGE_MODELS, - COPYRIGHT_NOTICE + COPYRIGHT_NOTICE, ) ) @@ -80,7 +80,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 @@ -97,7 +97,7 @@ class SwiftSettings( return SwiftSettings( serviceId, moduleName, - version, + moduleVersion, desc, author, homepage, @@ -106,7 +106,7 @@ class SwiftSettings( swiftVersion, useInterceptors, mergeModels, - copyrightNotice + copyrightNotice, ) } From 68ff8f10eb731832e840f7e6e783c05b3d013e9e Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 30 Jul 2024 13:03:55 -0500 Subject: [PATCH 26/28] Re-add SmithyHTTPAuth SwiftSymbol --- .../software/amazon/smithy/swift/codegen/SwiftDependency.kt | 1 + 1 file changed, 1 insertion(+) 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 873e11c2a..e6fb1d562 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 @@ -56,6 +56,7 @@ class SwiftDependency( 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") From 51ac2eb366a577f747109d071edebbfb5d60e05a Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Mon, 5 Aug 2024 09:04:40 -0400 Subject: [PATCH 27/28] Revert to stable smithy-swift --- .../software/amazon/smithy/swift/codegen/SwiftDependency.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e6fb1d562..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 @@ -72,8 +72,8 @@ class SwiftDependency( return SwiftDependency( name, "main", - "0.100.0", - "https://github.com/jbelkins/smithy-swift", + "0.54.0", + "https://github.com/awslabs/smithy-swift", "../../../smithy-swift", "smithy-swift", DistributionMethod.GIT, From 422483d222a9f4897d9bbc9e51a4c83995bcbe42 Mon Sep 17 00:00:00 2001 From: Josh Elkins Date: Tue, 3 Sep 2024 18:52:30 -0500 Subject: [PATCH 28/28] Fix SmithyTestUtilTypes --- .../swift/codegen/swiftmodules/SmithyTestUtilTypes.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 962243b16..d32912461 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 @@ -6,13 +6,13 @@ import software.amazon.smithy.swift.codegen.SwiftDependency object SmithyTestUtilTypes { val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM) - val TestBaseError = runtimeSymbol("TestBaseError") - val SelectNoAuthScheme = runtimeSymbol("SelectNoAuthScheme") + val TestBaseError = runtimeSymbol("TestBaseError", SwiftDeclaration.STRUCT) } private fun runtimeSymbol(name: String, declaration: SwiftDeclaration? = null): Symbol = SwiftSymbol.make( name, declaration, SwiftDependency.SMITHY_TEST_UTIL, - null, + emptyList(), + emptyList(), )