Skip to content

Commit cb4ab12

Browse files
committed
Clean up build scripts
1 parent 136c9db commit cb4ab12

File tree

6 files changed

+114
-131
lines changed

6 files changed

+114
-131
lines changed

tests/codegen/event-stream/build.gradle.kts

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,57 @@
66
import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin
77
import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir
88

9-
description = "Event stream codegen integration test suite"
9+
description = "AWS SDK for Kotlin codegen event stream integration test suite"
1010

11-
data class Test(
12-
val projectionName: String,
13-
val protocolName: String,
14-
val modelTemplate: File,
11+
apply(from = rootProject.file("buildSrc/shared.gradle.kts"))
12+
13+
data class CodegenTest(
14+
val name: String,
15+
val model: Model,
16+
val serviceShapeId: String,
17+
val protocolName: String? = null,
18+
)
19+
20+
data class Model(
21+
val fileName: String,
22+
val path: String = "src/commonTest/resources/",
1523
) {
16-
val model: File
17-
get() = layout.buildDirectory.file("$projectionName/model.smithy").get().asFile
24+
val file: File
25+
get() = layout.projectDirectory.file(path + fileName).asFile
1826
}
1927

2028
val tests = listOf(
21-
Test("restJson1", "restJson1", file("event-stream-model-template.smithy")),
22-
Test("awsJson11", "awsJson1_1", file("event-stream-initial-request-response.smithy")),
29+
CodegenTest(
30+
"restJson1",
31+
Model("event-stream-model-template.smithy"),
32+
"aws.sdk.kotlin.test#TestService",
33+
"restJson1"
34+
),
35+
CodegenTest(
36+
"awsJson11",
37+
Model("event-stream-initial-request-response.smithy"),
38+
"aws.sdk.kotlin.test#TestService",
39+
"awsJson1_1"
40+
),
2341
)
2442

25-
fun fillInModel(output: File, protocolName: String, template: File) {
26-
val input = template.readText()
27-
val opTraits = when (protocolName) {
28-
"restJson1", "restXml" -> """@http(method: "POST", uri: "/test-eventstream", code: 200)"""
29-
else -> ""
30-
}
31-
val replaced = input
32-
.replace("{protocol-name}", protocolName)
33-
.replace("{op-traits}", opTraits)
34-
35-
output.parentFile.mkdirs()
36-
output.writeText(replaced)
37-
}
38-
39-
val testServiceShapeId = "aws.sdk.kotlin.test#TestService"
4043
smithyBuild {
4144
tests.forEach { test ->
42-
43-
projections.register(test.projectionName) {
44-
imports = listOf(test.model.absolutePath)
45+
projections.register(test.name) {
46+
imports = listOf(test.model.file.absolutePath)
4547
transforms = listOf(
4648
"""
4749
{
4850
"name": "includeServices",
4951
"args": {
50-
"services": ["$testServiceShapeId"]
52+
"services": ["${test.serviceShapeId}"]
5153
}
5254
}
5355
""",
5456
)
55-
5657
smithyKotlinPlugin {
57-
serviceShapeId = testServiceShapeId
58-
packageName = "aws.sdk.kotlin.test.${test.projectionName.lowercase()}"
58+
serviceShapeId = test.serviceShapeId
59+
packageName = "aws.sdk.kotlin.test.${test.name.lowercase()}"
5960
packageVersion = "1.0"
6061
buildSettings {
6162
generateFullProject = false
@@ -70,18 +71,36 @@ smithyBuild {
7071
}
7172
}
7273

73-
tasks.generateSmithyBuild {
74-
doFirst {
75-
tests.forEach { test -> fillInModel(test.model, test.protocolName, test.modelTemplate) }
76-
}
77-
}
78-
7974
kotlin {
8075
sourceSets {
81-
commonTest {
76+
commonTest { // TODO: CHANGE TO JUST TEST WHEN NON-KMPing the project
8277
smithyBuild.projections.forEach {
8378
kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir(it.name))
8479
}
8580
}
8681
}
8782
}
83+
84+
tasks.generateSmithyBuild {
85+
doFirst {
86+
tests.forEach { test -> fillInModel(test) }
87+
}
88+
}
89+
90+
fun fillInModel(test: CodegenTest) {
91+
val modelFile = test.model.file
92+
val model = modelFile.readText()
93+
94+
val opTraits =
95+
when (test.protocolName) {
96+
"restJson1", "restXml" -> """@http(method: "POST", uri: "/test-eventstream", code: 200)"""
97+
else -> ""
98+
}
99+
100+
val replaced = model
101+
.replace("{protocol-name}", test.protocolName!!)
102+
.replace("{op-traits}", opTraits)
103+
104+
modelFile.parentFile.mkdirs()
105+
modelFile.writeText(replaced)
106+
}

tests/codegen/event-stream/event-stream-model-template.smithy renamed to tests/codegen/event-stream/src/commonTest/resources/event-stream-model-template.smithy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
namespace aws.sdk.kotlin.test
22

3-
use aws.protocols#{protocol-name}
3+
use aws.protocols#restJson1
44
use aws.api#service
55
use aws.auth#sigv4
66

7-
@{protocol-name}
7+
@restJson1
88
@sigv4(name: "event-stream-test")
99
@service(sdkId: "EventStreamTest")
1010
service TestService { version: "123", operations: [TestStreamOp] }
1111

12-
{op-traits}
12+
@http(method: "POST", uri: "/test-eventstream", code: 200)
1313
operation TestStreamOp {
1414
input: TestStreamInputOutput,
1515
output: TestStreamInputOutput,

tests/codegen/rules-engine/build.gradle.kts

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,35 @@
44
*/
55

66
import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin
7-
import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir
87

8+
description = "AWS SDK for Kotlin codegen rules engine integration test suite"
99

10-
description = "AWS SDK for Kotlin codegen integration test suite" // TODO: Don't commonize
10+
data class CodegenTest(
11+
val name: String,
12+
val model: Model,
13+
val serviceShapeId: String,
14+
val protocolName: String? = null,
15+
)
1116

12-
data class Test(
13-
val projectionName: String,
14-
val protocolName: String,
15-
val modelTemplate: File,
17+
data class Model(
18+
val fileName: String,
19+
val path: String = "src/commonTest/resources/",
1620
) {
17-
val model: File
18-
get() = layout.buildDirectory.file("$projectionName/model.smithy").get().asFile
21+
val file: File
22+
get() = layout.projectDirectory.file(path + fileName).asFile
1923
}
2024

21-
val tests = listOf( // TODO: Don't commonize
22-
Test("operationContextParams", "operationContextParams", file("operation-context-params.smithy")),
25+
val tests = listOf(
26+
CodegenTest("operationContextParams", Model("operation-context-params.smithy"), "aws.sdk.kotlin.test#TestService")
2327
)
2428

25-
fun fillInModel(output: File, protocolName: String, template: File) {
26-
val input = template.readText()
27-
val opTraits = when (protocolName) {
28-
"restJson1", "restXml" -> """@http(method: "POST", uri: "/test-eventstream", code: 200)"""
29-
else -> ""
30-
}
31-
val replaced = input
32-
.replace("{protocol-name}", protocolName)
33-
.replace("{op-traits}", opTraits)
34-
35-
output.parentFile.mkdirs()
36-
output.writeText(replaced)
37-
}
38-
39-
val testServiceShapeId = "aws.sdk.kotlin.test#TestService"
4029
smithyBuild {
4130
tests.forEach { test ->
42-
43-
projections.register(test.projectionName) {
44-
imports = listOf(test.model.absolutePath)
45-
transforms = listOf(
46-
"""
47-
{
48-
"name": "includeServices",
49-
"args": {
50-
"services": ["$testServiceShapeId"]
51-
}
52-
}
53-
""",
54-
)
55-
31+
projections.register(test.name) {
32+
imports = listOf(test.model.file.absolutePath)
5633
smithyKotlinPlugin {
57-
serviceShapeId = testServiceShapeId
58-
packageName = "aws.sdk.kotlin.test.${test.projectionName.lowercase()}"
34+
serviceShapeId = test.serviceShapeId
35+
packageName = "aws.sdk.kotlin.test.${test.name.lowercase()}"
5936
packageVersion = "1.0"
6037
buildSettings {
6138
generateFullProject = false
@@ -69,15 +46,3 @@ smithyBuild {
6946
}
7047
}
7148
}
72-
73-
tasks.generateSmithyBuild {
74-
doFirst {
75-
tests.forEach { test -> fillInModel(test.model, test.protocolName, test.modelTemplate) }
76-
}
77-
}
78-
79-
kotlin.sourceSets.getByName("jvmTest") {
80-
smithyBuild.projections.forEach {
81-
kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir(it.name))
82-
}
83-
}

tests/codegen/smoke-tests/build.gradle.kts

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import aws.sdk.kotlin.gradle.codegen.dsl.generateSmithyProjections
77
import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin
88
import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionPath
99

10-
description = "Tests for smoke tests runners"
10+
description = "AWS SDK for Kotlin codegen smoke tests integration test suite"
1111

1212
kotlin {
1313
sourceSets {
@@ -19,25 +19,38 @@ kotlin {
1919
}
2020
}
2121

22-
val projections = listOf(
23-
Projection("successService", "smoke-tests-success.smithy", "smithy.kotlin.traits#SuccessService"),
24-
Projection("failureService", "smoke-tests-failure.smithy", "smithy.kotlin.traits#FailureService"),
25-
Projection("exceptionService", "smoke-tests-exception.smithy", "smithy.kotlin.traits#ExceptionService"),
22+
data class CodegenTest(
23+
val name: String,
24+
val model: Model,
25+
val serviceShapeId: String,
26+
val protocolName: String? = null,
27+
)
28+
29+
data class Model(
30+
val fileName: String,
31+
val path: String = "src/jvmTest/resources/",
32+
) {
33+
val file: File
34+
get() = layout.projectDirectory.file(path + fileName).asFile
35+
}
36+
37+
val tests = listOf(
38+
CodegenTest("successService", Model("smoke-tests-success.smithy"), "smithy.kotlin.traits#SuccessService"),
39+
CodegenTest("failureService", Model("smoke-tests-failure.smithy"), "smithy.kotlin.traits#FailureService"),
40+
CodegenTest("exceptionService", Model("smoke-tests-exception.smithy"), "smithy.kotlin.traits#ExceptionService"),
2641
)
2742

2843
configureProjections()
2944
configureTasks()
3045

3146
fun configureProjections() {
3247
smithyBuild {
33-
val pathToSmithyModels = "src/jvmTest/resources/"
34-
35-
this@Build_gradle.projections.forEach { projection ->
36-
projections.register(projection.name) {
37-
imports = listOf(layout.projectDirectory.file(pathToSmithyModels + projection.modelFile).asFile.absolutePath)
48+
this@Build_gradle.tests.forEach { test ->
49+
projections.register(test.name) {
50+
imports = listOf(test.model.file.absolutePath)
3851
smithyKotlinPlugin {
39-
serviceShapeId = projection.serviceShapeId
40-
packageName = "aws.sdk.kotlin.test"
52+
serviceShapeId = test.serviceShapeId
53+
packageName = "aws.sdk.kotlin.test.${test.name.lowercase()}"
4154
packageVersion = "1.0"
4255
buildSettings {
4356
generateFullProject = false
@@ -51,26 +64,21 @@ fun configureProjections() {
5164
}
5265
}
5366
}
54-
55-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
56-
dependsOn(tasks.generateSmithyProjections)
57-
kotlinOptions.allWarningsAsErrors = false
58-
}
5967
}
6068

6169
fun configureTasks() {
6270
tasks.register("stageServices") {
6371
dependsOn(tasks.generateSmithyProjections)
64-
6572
doLast {
66-
this@Build_gradle.projections.forEach { projection ->
67-
val projectionPath = smithyBuild.smithyKotlinProjectionPath(projection.name).get()
68-
val destinationPath = layout.projectDirectory.asFile.absolutePath + "/services/${projection.name}"
73+
this@Build_gradle.tests.forEach { test ->
74+
val projectionPath = smithyBuild.smithyKotlinProjectionPath(test.name).get()
75+
val destinationPath = layout.projectDirectory.asFile.absolutePath + "/services/${test.name}"
6976

7077
copy {
7178
from("$projectionPath/src")
7279
into("$destinationPath/generated-src")
7380
}
81+
7482
copy {
7583
from("$projectionPath/build.gradle.kts")
7684
into(destinationPath)
@@ -79,28 +87,19 @@ fun configureTasks() {
7987
}
8088
}
8189

90+
tasks.withType<Test> {
91+
dependsOn(tasks.getByName("stageServices"))
92+
mustRunAfter(tasks.getByName("stageServices"))
93+
}
94+
8295
tasks.build {
8396
dependsOn(tasks.getByName("stageServices"))
8497
mustRunAfter(tasks.getByName("stageServices"))
8598
}
8699

87100
tasks.clean {
88-
this@Build_gradle.projections.forEach { projection ->
89-
delete("services/${projection.name}")
101+
this@Build_gradle.tests.forEach { test ->
102+
delete("services/${test.name}")
90103
}
91104
}
92-
93-
tasks.withType<Test> {
94-
dependsOn(tasks.getByName("stageServices"))
95-
mustRunAfter(tasks.getByName("stageServices"))
96-
}
97105
}
98-
99-
/**
100-
* Holds metadata about a smithy projection
101-
*/
102-
data class Projection(
103-
val name: String,
104-
val modelFile: String,
105-
val serviceShapeId: String,
106-
)

0 commit comments

Comments
 (0)