Skip to content

Commit 77992a7

Browse files
authored
chore: generate smithy-build.json for protocol test codegen (#285)
1 parent a11acc8 commit 77992a7

File tree

3 files changed

+79
-144
lines changed

3 files changed

+79
-144
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ AWSClientRuntime/AWSClientRuntime.xcodeproj
2121
AWSClientRuntime/AWSClientRuntime.xcodeproj/
2222
AWSClientRuntime/.swiftpm/xcode/xcuserdata/*
2323
AWSClientRuntime/.swiftpm/xcode/package.xcworkspace/xcuserdata/*
24-
codegen/protocol-test-codegen-local/smithy-build.json
24+
codegen/protocol-test-codegen-local/smithy-build.json
25+
codegen/protocol-test-codegen/smithy-build.json

codegen/protocol-test-codegen/build.gradle.kts

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,45 @@ dependencies {
2525
implementation(project(":smithy-aws-swift-codegen"))
2626
}
2727

28+
val enabledProtocols = listOf(
29+
ProtocolTest("ec2-query", "aws.protocoltests.ec2#AwsEc2", "Ec2QueryTestSDK"),
30+
ProtocolTest("aws-json-10", "aws.protocoltests.json10#JsonRpc10", "AWSJson1_0TestSDK"),
31+
ProtocolTest("aws-json-11", "aws.protocoltests.json#JsonProtocol", "AWSJson1_1TestSDK"),
32+
ProtocolTest("aws-restjson", "aws.protocoltests.restjson#RestJson", "AWSRestJsonTestSDK"),
33+
ProtocolTest("rest-xml", "aws.protocoltests.restxml#RestXml", "RestXmlTestSDK"),
34+
//ProtocolTest("rest-xml-xmlns", "aws.protocoltests.restxml.xmlns#RestXmlWithNamespace", "RestXmlWithNamespaceTestSDK"),
35+
ProtocolTest("aws-query", "aws.protocoltests.query#AwsQuery", "AWSQueryTestSDK")
36+
37+
// service specific tests
38+
//ProtocolTest("apigateway", "com.amazonaws.apigateway#BackplaneControlService"),
39+
//ProtocolTest("glacier", "com.amazonaws.glacier#Glacier")
40+
)
41+
2842
// This project doesn't produce a JAR.
2943
tasks["jar"].enabled = false
3044

3145
// Run the SmithyBuild task manually since this project needs the built JAR
3246
// from smithy-aws-swift-codegen.
3347
tasks["smithyBuildJar"].enabled = false
3448

49+
task("generateSmithyBuild") {
50+
group = "codegen"
51+
description = "generate smithy-build.json"
52+
val buildFile = projectDir.resolve("smithy-build.json")
53+
doFirst {
54+
buildFile.writeText(generateSmithyBuild(enabledProtocols))
55+
}
56+
outputs.file(buildFile)
57+
}
58+
59+
tasks["clean"].doFirst {
60+
delete("smithy-build.json")
61+
}
62+
3563
tasks.create<SmithyBuild>("buildSdk") {
3664
addRuntimeClasspath = true
65+
dependsOn(tasks["generateSmithyBuild"])
66+
inputs.file(projectDir.resolve("smithy-build.json"))
3767
}
3868

3969
// Run the `buildSdk` automatically.
@@ -42,19 +72,60 @@ tasks["build"].finalizedBy(tasks["buildSdk"])
4272
// force rebuild every time while developing
4373
tasks["buildSdk"].outputs.upToDateWhen { false }
4474

45-
// The following section exposes Smithy protocol test suites as gradle test targets
46-
// for the configured protocols in [enabledProtocols].
47-
val enabledProtocols = listOf("aws-json-10", "aws-json-11", "aws-restjson", "rest-xml", "aws-query", "ec2-query")
48-
4975
enabledProtocols.forEach {
50-
tasks.register<ProtocolTestTask>("testProtocol-${it}") {
76+
tasks.register<ProtocolTestTask>("testProtocol-${it.projectionName}") {
5177
dependsOn(tasks.build)
5278
group = "Verification"
53-
protocol = it
79+
protocol = it.projectionName
5480
plugin = "swift-codegen"
5581
}
5682
}
5783

84+
85+
data class ProtocolTest(val projectionName: String,
86+
val serviceShapeId: String,
87+
val moduleName: String) {
88+
val packageName: String
89+
get() = projectionName.toLowerCase().filter { it.isLetterOrDigit() }
90+
}
91+
fun generateSmithyBuild(tests: List<ProtocolTest>): String {
92+
val projections = tests.joinToString(",") { test ->
93+
"""
94+
"${test.projectionName}": {
95+
"transforms": [
96+
{
97+
"name": "includeServices",
98+
"args": {
99+
"services": [
100+
"${test.serviceShapeId}"
101+
]
102+
}
103+
}
104+
],
105+
"plugins": {
106+
"swift-codegen": {
107+
"service": "${test.serviceShapeId}",
108+
"module": "${test.moduleName}",
109+
"moduleVersion": "1.0",
110+
"gitRepo": "https://github.com/aws-amplify/smithy-swift.git",
111+
"author": "Amazon Web Services",
112+
"homepage": "https://docs.amplify.aws/",
113+
"swiftVersion": "5.4.0",
114+
"shouldGenerateUnitTestTarget": true
115+
}
116+
}
117+
}"""
118+
}
119+
return """
120+
{
121+
"version": "1.0",
122+
"projections": {
123+
$projections
124+
}
125+
}
126+
""".trimIndent()
127+
}
128+
58129
tasks.register("testAllProtocols") {
59130
group = "Verification"
60131
val allTests = tasks.withType<ProtocolTestTask>()

codegen/protocol-test-codegen/smithy-build.json

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)