Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Publish releases on Swift Package Registry #778

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
2de56c8
Handle SPR-based dependencies
jbelkins Jun 25, 2024
cfeb008
Require smithy-swift from SPR
jbelkins Jun 26, 2024
83e0169
Fix dependencies
jbelkins Jun 26, 2024
29d0da4
Clean up SwiftDependency
jbelkins Jun 26, 2024
54aa1a1
Merge remote-tracking branch 'origin/main' into jbe/spr
jbelkins Jun 26, 2024
1bd2494
Simplify package dependency writer
jbelkins Jun 27, 2024
b798caa
Code cleanup
jbelkins Jun 28, 2024
0df6f1a
Move registry config JSON gen to AWS
jbelkins Jun 28, 2024
c2a402f
Accommodate resources in service client
jbelkins Jun 28, 2024
b808822
Merge remote-tracking branch 'origin/main' into jbe/spr
jbelkins Jun 28, 2024
50bbef6
Configurable Package.swift name
jbelkins Jun 28, 2024
7bc666a
Fix codegen tests
jbelkins Jun 29, 2024
9ccb675
Fix ktlint
jbelkins Jun 29, 2024
9b57567
Revert "Configurable Package.swift name"
jbelkins Jun 29, 2024
ac77566
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Jul 2, 2024
003caee
Set version static var in client
jbelkins Jul 2, 2024
d964f35
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Jul 3, 2024
624cfab
Merge remote-tracking branch 'origin/main' into jbe/spr
jbelkins Jul 3, 2024
9c7bdef
Merge branch 'jbe/spr' into jbe/spr2
jbelkins Jul 3, 2024
af54db3
Fix package manifest generator
jbelkins Jul 3, 2024
fb1734e
Eliminate CRT from generated code, use smithy-swift from Git
jbelkins Jul 3, 2024
071dcad
Merge branch 'main' into jbe/spr
jbelkins Jul 5, 2024
cc6a74a
Merge branch 'jbe/spr' into jbe/spr2
jbelkins Jul 5, 2024
5779dc2
Merge branch 'main' into jbe/spr
jbelkins Jul 5, 2024
19c1607
Merge branch 'jbe/spr' into jbe/spr2
jbelkins Jul 5, 2024
135fa12
Lock to exact version on jbelkins fork
jbelkins Jul 5, 2024
9132d17
Restore compatibility with current smithy-swift
jbelkins Jul 6, 2024
eed4a9c
Point smithy-swift to fork
jbelkins Jul 6, 2024
95d863f
Merge branch 'main' into jbe/spr
jbelkins Jul 8, 2024
d38d652
Merge branch 'jbe/spr' into jbe/spr2
jbelkins Jul 8, 2024
3dd321d
Merge branch 'main' into jbe/spr
jbelkins Jul 9, 2024
ddf9f87
Merge branch 'jbe/spr' into jbe/spr2
jbelkins Jul 9, 2024
ca25799
Merge remote-tracking branch 'origin/main' into jbe/spr
jbelkins Jul 9, 2024
153b3ae
Merge branch 'jbe/spr' into jbe/spr2
jbelkins Jul 9, 2024
0ce8c1e
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Jul 9, 2024
e64b466
Merge branch 'main' into jbe/spr2
jbelkins Jul 10, 2024
33e919d
Use SmithyTestUtils to initialize CRT
jbelkins Jul 11, 2024
12a23fc
Merge branch 'main' into jbe/spr2
jbelkins Jul 11, 2024
6011f2f
Add declaration type to TestInitializer, disable Package.swift in ser…
jbelkins Jul 11, 2024
f84d616
Fix codegen tests
jbelkins Jul 11, 2024
c3934e1
Remove CRT SwiftDependency
jbelkins Jul 11, 2024
4113fd7
Don't link service client to SmithyTestUtil
jbelkins Jul 12, 2024
4612378
Remove parameterized package manifest name
jbelkins Jul 12, 2024
09232ff
Merge branch 'main' into jbe/spr2
jbelkins Jul 12, 2024
72e679b
SwiftSettings cleanup
jbelkins Jul 12, 2024
50be2cb
Merge branch 'main' into jbe/spr2
jbelkins Jul 17, 2024
4dc6ad6
Merge branch 'main' into jbe/spr2
jbelkins Jul 27, 2024
68ff8f1
Re-add SmithyHTTPAuth SwiftSymbol
jbelkins Jul 30, 2024
dab764e
Merge branch 'main' into jbe/spr2
jbelkins Jul 30, 2024
5566971
Merge branch 'main' into jbe/spr2
jbelkins Jul 31, 2024
742be97
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Aug 1, 2024
51ac2eb
Revert to stable smithy-swift
jbelkins Aug 5, 2024
9445ef1
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Aug 7, 2024
842e81f
Merge branch 'main' into jbe/spr2
jbelkins Aug 13, 2024
a99ea64
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Aug 14, 2024
dcba3db
Merge branch 'main' into jbe/spr2
jbelkins Aug 16, 2024
92bf38d
Merge branch 'main' into jbe/spr2
jbelkins Aug 22, 2024
368dd01
Merge branch 'main' into jbe/spr2
jbelkins Sep 3, 2024
422483d
Fix SmithyTestUtilTypes
jbelkins Sep 3, 2024
bc2fce8
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Sep 5, 2024
286fcd4
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Sep 5, 2024
9836a02
Merge remote-tracking branch 'origin/main' into jbe/spr2
jbelkins Sep 9, 2024
3adabb3
Merge branch 'main' into jbe/spr2
jbelkins Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ let package = Package(
),
.target(
name: "SmithyTestUtil",
dependencies: ["ClientRuntime", "SmithyHTTPAPI"]
dependencies: [
"ClientRuntime",
"SmithyHTTPAPI",
.product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SmithyTestUtil now needs this dependency on CRT (this was an oversight in the earlier TestInitializer PR.)

]
),
.target(
name: "SmithyIdentity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymbolDependency>) {
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")
Expand All @@ -30,10 +28,12 @@ class PackageManifestGenerator(val ctx: ProtocolGenerator.GenerationContext) {
writer.write(".library(name: \$S, targets: [\$S])", ctx.settings.moduleName, ctx.settings.moduleName)
}

val externalDependencies = dependencies.filter {
it.getProperty("url", String::class.java).getOrNull() != null ||
it.getProperty("scope", String::class.java).getOrNull() != null
}
val externalDependencies = dependencies
.filter { it.expectProperty("target", String::class.java) != "SmithyTestUtil" } // SmithyTestUtil links to test target only
.filter {
it.getProperty("url", String::class.java).getOrNull() != null ||
it.getProperty("scope", String::class.java).getOrNull() != null
}
val dependenciesByURL = externalDependencies.distinctBy {
it.getProperty("url", String::class.java).getOrNull()
?: "${it.getProperty("scope", String::class.java).get()}.${it.packageName}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SwiftDependency(
"",
"",
"",
SwiftDependency.DistributionMethod.GIT,
DistributionMethod.GIT,
)
val XCTest = SwiftDependency(
"XCTest",
Expand All @@ -49,213 +49,36 @@ class SwiftDependency(
"",
DistributionMethod.GIT,
)
val CRT = SwiftDependency(
"AwsCommonRuntimeKit",
null,
"0.31.0",
"https://github.com/awslabs/aws-crt-swift",
"",
"aws-crt-swift",
DistributionMethod.GIT,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CRT SwiftDependency above is no longer used, and is deleted.

val CLIENT_RUNTIME = SwiftDependency(
"ClientRuntime",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY = SwiftDependency(
"Smithy",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_IDENTITY_API = SwiftDependency(
"SmithyIdentityAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_IDENTITY = SwiftDependency(
"SmithyIdentity",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_RETRIES_API = SwiftDependency(
"SmithyRetriesAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_RETRIES = SwiftDependency(
"SmithyRetries",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_HTTP_API = SwiftDependency(
"SmithyHTTPAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_HTTP_AUTH_API = SwiftDependency(
"SmithyHTTPAuthAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_HTTP_AUTH = SwiftDependency(
"SmithyHTTPAuth",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_CHECKSUMS_API = SwiftDependency(
"SmithyChecksumsAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_CHECKSUMS = SwiftDependency(
"SmithyChecksums",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_STREAMS = SwiftDependency(
"SmithyStreams",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_EVENT_STREAMS_API = SwiftDependency(
"SmithyEventStreamsAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_EVENT_STREAMS_AUTH_API = SwiftDependency(
"SmithyEventStreamsAuthAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_EVENT_STREAMS = SwiftDependency(
"SmithyEventStreams",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_TEST_UTIL = SwiftDependency(
"SmithyTestUtil",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_READ_WRITE = SwiftDependency(
"SmithyReadWrite",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_TIMESTAMPS = SwiftDependency(
"SmithyTimestamps",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_XML = SwiftDependency(
"SmithyXML",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_JSON = SwiftDependency(
"SmithyJSON",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_FORM_URL = SwiftDependency(
"SmithyFormURL",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val SMITHY_WAITERS_API = SwiftDependency(
"SmithyWaitersAPI",
"main",
"0.0.1",
"aws-sdk-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.SPR,
)
val CLIENT_RUNTIME = smithySwiftTargetNamed("ClientRuntime")
val SMITHY = smithySwiftTargetNamed("Smithy")
val SMITHY_IDENTITY = smithySwiftTargetNamed("SmithyIdentity")
val SMITHY_RETRIES_API = smithySwiftTargetNamed("SmithyRetriesAPI")
val SMITHY_RETRIES = smithySwiftTargetNamed("SmithyRetries")
val SMITHY_HTTP_API = smithySwiftTargetNamed("SmithyHTTPAPI")
val SMITHY_HTTP_AUTH_API = smithySwiftTargetNamed("SmithyHTTPAuthAPI")
val SMITHY_HTTP_AUTH = smithySwiftTargetNamed("SmithyHTTPAuth")
val SMITHY_STREAMS = smithySwiftTargetNamed("SmithyStreams")
val SMITHY_EVENT_STREAMS_API = smithySwiftTargetNamed("SmithyEventStreamsAPI")
val SMITHY_EVENT_STREAMS = smithySwiftTargetNamed("SmithyEventStreams")
val SMITHY_TEST_UTIL = smithySwiftTargetNamed("SmithyTestUtil")
val SMITHY_READ_WRITE = smithySwiftTargetNamed("SmithyReadWrite")
val SMITHY_TIMESTAMPS = smithySwiftTargetNamed("SmithyTimestamps")
val SMITHY_XML = smithySwiftTargetNamed("SmithyXML")
val SMITHY_JSON = smithySwiftTargetNamed("SmithyJSON")
val SMITHY_FORM_URL = smithySwiftTargetNamed("SmithyFormURL")
val SMITHY_WAITERS_API = smithySwiftTargetNamed("SmithyWaitersAPI")

private fun smithySwiftTargetNamed(name: String): SwiftDependency {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper function makes the SwiftDependency declarations above a lot less repetitive.

Also, ignore the version numbers on Swift dependencies for now. A future PR will automatically set them from a configuration file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these smithy-swift SwiftDependencies were also changed so that smithy-swift is a Git dependency, not installed from registry.

return SwiftDependency(
name,
"main",
"0.54.0",
"https://github.com/awslabs/smithy-swift",
"../../../smithy-swift",
"smithy-swift",
DistributionMethod.GIT,
)
}
}

override fun getDependencies(): List<SymbolDependency> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SwiftSettings(
val gitRepo: String,
val swiftVersion: String,
val mergeModels: Boolean,
val copyrightNotice: String
val copyrightNotice: String,
) {

companion object {
Expand Down Expand Up @@ -68,7 +68,7 @@ class SwiftSettings(
GIT_REPO,
SWIFT_VERSION,
MERGE_MODELS,
COPYRIGHT_NOTICE
COPYRIGHT_NOTICE,
)
)

Expand All @@ -77,7 +77,7 @@ class SwiftSettings(
.orElseGet { inferService(model) }

val moduleName = config.expectStringMember(MODULE_NAME).value
val version = config.expectStringMember(MODULE_VERSION).value
val moduleVersion = config.expectStringMember(MODULE_VERSION).value
val desc = config.getStringMemberOrDefault(MODULE_DESCRIPTION, "$moduleName client")
val homepage = config.expectStringMember(HOMEPAGE).value
val author = config.expectStringMember(AUTHOR).value
Expand All @@ -93,15 +93,15 @@ class SwiftSettings(
return SwiftSettings(
serviceId,
moduleName,
version,
moduleVersion,
desc,
author,
homepage,
sdkId,
gitRepo,
swiftVersion,
mergeModels,
copyrightNotice
copyrightNotice,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class SwiftWriter(
//
// Also leave out the headers when JSON or the version file is being written,
// as indicated by the file extension.
val isPackageManifest = listOf(PACKAGE_MANIFEST_NAME, (PACKAGE_MANIFEST_NAME + ".swift")).contains(fullPackageName)
val isPackageManifest = "Package.swift".contains(fullPackageName)
val isNonSwiftSourceFile = listOf(".json", ".version").any { fullPackageName.endsWith(it) }
val noHeader = isPackageManifest || isNonSwiftSourceFile
return contents.takeIf { noHeader } ?: (copyrightNotice + imports + contents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client gains this version property, which is used over in the accompanying AWS SDK PR to set the client version in the user agent.

writer.write("let client: \$N", ClientRuntimeTypes.Http.SdkHttpClient)
writer.write("let config: \$L", serviceConfig.typeName)
writer.write("let serviceName = \$S", serviceName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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 TestBaseError = runtimeSymbol("TestBaseError")
val SelectNoAuthScheme = runtimeSymbol("SelectNoAuthScheme")
val TestInitializer = runtimeSymbol("TestInitializer", SwiftDeclaration.ENUM)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to include a declaration type on this symbol in my previous PR

val TestBaseError = runtimeSymbol("TestBaseError", SwiftDeclaration.STRUCT)
}

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,
emptyList(),
emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading
Loading