From ac5aaf2f2c0d7587b7757b1e7274891e5c8b0f75 Mon Sep 17 00:00:00 2001 From: Aaron Todd Date: Tue, 2 Jan 2024 09:52:20 -0500 Subject: [PATCH] chore: refactor build to use custom smithy build plugin (#1020) --- bom/build.gradle.kts | 2 +- build.gradle.kts | 7 ++- gradle/libs.versions.toml | 4 +- settings.gradle.kts | 2 - .../serde-benchmarks/build.gradle.kts | 19 +++--- .../serde-benchmarks/smithy-build.json | 1 + .../nullability-tests/build.gradle.kts | 60 ++++++++----------- .../nullability-tests/smithy-build.json | 1 + .../codegen/paginator-tests/build.gradle.kts | 43 +++++-------- .../codegen/paginator-tests/smithy-build.json | 1 + tests/codegen/waiter-tests/build.gradle.kts | 45 ++++++-------- tests/codegen/waiter-tests/smithy-build.json | 1 + 12 files changed, 79 insertions(+), 107 deletions(-) diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index 9fdc408f0..c0e23752f 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -53,7 +53,7 @@ fun createBomConstraintsAndVersionCatalog() { fun Project.artifactId(target: KotlinTarget): String = when (target) { is KotlinMetadataTarget -> name is KotlinJsTarget -> "$name-js" - else -> "$name-${target.targetName.toLowerCase(Locale.ROOT)}" + else -> "$name-${target.targetName.lowercase()}" } /** diff --git a/build.gradle.kts b/build.gradle.kts index 918fbdc35..87edd398f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,9 +13,14 @@ buildscript { classpath(libs.kotlinx.atomicfu.plugin) // Add our custom gradle plugin(s) to buildscript classpath (comes from github source) + // NOTE: Anything included in our build plugin is added to the classpath for all projects, + // this includes bundled plugins and their versions. As an example the smithy gradle base + // plugin is used by the smithybuild plugin which means you can't apply it with a different + // version directly because it's already on the classpath. + // FIXME - if we publish this plugin it would fix a lot of things classpath("aws.sdk.kotlin:build-plugins") { version { - require("0.3.1") + require("0.3.2") } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index cc0edd931..8f83e7397 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ crt-kotlin-version = "0.8.2" # codegen smithy-version = "1.42.0" -smithy-gradle-version = "0.7.0" +smithy-gradle-version = "0.9.0" # testing junit-version = "5.10.1" @@ -58,6 +58,7 @@ crt-kotlin = { module = "aws.sdk.kotlin.crt:aws-crt-kotlin", version.ref = "crt- smithy-codegen-core = { module = "software.amazon.smithy:smithy-codegen-core", version.ref = "smithy-version" } smithy-cli = { module = "software.amazon.smithy:smithy-cli", version.ref = "smithy-version" } +smithy-model = { module = "software.amazon.smithy:smithy-model", version.ref = "smithy-version" } smithy-waiters = { module = "software.amazon.smithy:smithy-waiters", version.ref = "smithy-version" } smithy-rules-engine = { module = "software.amazon.smithy:smithy-rules-engine", version.ref = "smithy-version" } smithy-aws-traits = { module = "software.amazon.smithy:smithy-aws-traits", version.ref = "smithy-version" } @@ -92,4 +93,3 @@ kotlin-multiplatform = {id = "org.jetbrains.kotlin.multiplatform", version.ref = kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark-version" } kotlinx-binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" } kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-version"} -smithy-gradle = { id = "software.amazon.smithy", version.ref = "smithy-gradle-version" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 7924e2c8d..1b97b3a8b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,8 +7,6 @@ pluginManagement { repositories { mavenLocal() mavenCentral() - maven("https://plugins.gradle.org/m2/") - google() gradlePluginPortal() } } diff --git a/tests/benchmarks/serde-benchmarks/build.gradle.kts b/tests/benchmarks/serde-benchmarks/build.gradle.kts index f5c5b9b14..0b48c20ba 100644 --- a/tests/benchmarks/serde-benchmarks/build.gradle.kts +++ b/tests/benchmarks/serde-benchmarks/build.gradle.kts @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ import aws.sdk.kotlin.gradle.dsl.skipPublishing -import software.amazon.smithy.gradle.tasks.SmithyBuild plugins { kotlin("multiplatform") - alias(libs.plugins.smithy.gradle) alias(libs.plugins.kotlinx.benchmark) + id("aws.sdk.kotlin.gradle.smithybuild") } skipPublishing() @@ -73,19 +72,15 @@ afterEvaluate { } } -tasks["smithyBuildJar"].enabled = false - -val codegen by configurations.creating - +val codegen by configurations.getting dependencies { codegen(project(":tests:benchmarks:serde-benchmarks-codegen")) + codegen(libs.smithy.cli) + codegen(libs.smithy.model) } -val generateSdk = tasks.create("generateSdk") { - group = "codegen" - classpath = configurations.getByName("codegen") - inputs.file(projectDir.resolve("smithy-build.json")) - inputs.files(configurations.getByName("codegen")) +tasks.generateSmithyProjections { + smithyBuildConfigs.set(files("smithy-build.json")) } data class BenchmarkModel(val name: String) { @@ -103,7 +98,7 @@ val benchmarkModels = listOf( val stageGeneratedSources = tasks.register("stageGeneratedSources") { group = "codegen" - dependsOn(generateSdk) + dependsOn(tasks.generateSmithyProjections) doLast { benchmarkModels.forEach { copy { diff --git a/tests/benchmarks/serde-benchmarks/smithy-build.json b/tests/benchmarks/serde-benchmarks/smithy-build.json index 1cd86db66..a6fbe58d7 100644 --- a/tests/benchmarks/serde-benchmarks/smithy-build.json +++ b/tests/benchmarks/serde-benchmarks/smithy-build.json @@ -1,5 +1,6 @@ { "version": "1.0", + "sources": ["model"], "projections": { "twitter": { "transforms": [ diff --git a/tests/codegen/nullability-tests/build.gradle.kts b/tests/codegen/nullability-tests/build.gradle.kts index c169b6cce..2680c48bb 100644 --- a/tests/codegen/nullability-tests/build.gradle.kts +++ b/tests/codegen/nullability-tests/build.gradle.kts @@ -2,59 +2,47 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ +import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir import aws.sdk.kotlin.gradle.dsl.skipPublishing -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import software.amazon.smithy.gradle.tasks.SmithyBuild -import software.amazon.smithy.gradle.tasks.Validate as SmithyValidate plugins { - kotlin("jvm") - alias(libs.plugins.smithy.gradle) + alias(libs.plugins.kotlin.jvm) + id("aws.sdk.kotlin.gradle.smithybuild") } skipPublishing() +val codegen by configurations.getting +dependencies { + codegen(project(":codegen:smithy-kotlin-codegen")) + codegen(libs.smithy.cli) + codegen(libs.smithy.model) +} + +tasks.generateSmithyProjections { + smithyBuildConfigs.set(files("smithy-build.json")) +} + val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi") kotlin.sourceSets.all { optinAnnotations.forEach { languageSettings.optIn(it) } } -val projectionDirs = listOf( - "smithyprojections/nullability-tests/client-mode/kotlin-codegen", - "smithyprojections/nullability-tests/client-careful-mode/kotlin-codegen", +val projections = listOf( + "client-mode", + "client-careful-mode", ) kotlin.sourceSets.getByName("main") { - projectionDirs.forEach { - kotlin.srcDir(layout.buildDirectory.dir(it)) + projections.forEach { projectionName -> + kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir(projectionName)) } } -tasks.withType { - // generated code has warnings unfortunately - kotlinOptions.allWarningsAsErrors = false -} - -tasks["smithyBuildJar"].enabled = false - -val codegen by configurations.creating -dependencies { - codegen(project(":codegen:smithy-kotlin-codegen")) - codegen(libs.smithy.cli) -} - -val generateSdk = tasks.register("generateSdk") { - group = "codegen" - classpath = codegen - inputs.file(projectDir.resolve("smithy-build.json")) - inputs.files(codegen) -} - -tasks.named("smithyValidate") { - classpath = codegen -} tasks.withType { - dependsOn(generateSdk) + dependsOn(tasks.generateSmithyProjections) + // FIXME - generated code has warnings unfortunately, see https://github.com/awslabs/aws-sdk-kotlin/issues/1169 + kotlinOptions.allWarningsAsErrors = false } tasks.test { @@ -66,12 +54,14 @@ tasks.test { } dependencies { - implementation(libs.kotlinx.coroutines.core) compileOnly(project(":codegen:smithy-kotlin-codegen")) + + implementation(libs.kotlinx.coroutines.core) implementation(project(":runtime:runtime-core")) implementation(project(":runtime:smithy-client")) implementation(project(":runtime:protocol:http-client")) implementation(project(":runtime:observability:telemetry-api")) implementation(project(":runtime:observability:telemetry-defaults")) + testImplementation(libs.kotlin.test.junit5) } diff --git a/tests/codegen/nullability-tests/smithy-build.json b/tests/codegen/nullability-tests/smithy-build.json index e3fbf90d1..13d01f890 100644 --- a/tests/codegen/nullability-tests/smithy-build.json +++ b/tests/codegen/nullability-tests/smithy-build.json @@ -1,5 +1,6 @@ { "version": "1.0", + "sources": ["model/nullability.smithy"], "projections": { "client-mode": { "transforms": [ diff --git a/tests/codegen/paginator-tests/build.gradle.kts b/tests/codegen/paginator-tests/build.gradle.kts index 7890dbc15..0ef6e1d99 100644 --- a/tests/codegen/paginator-tests/build.gradle.kts +++ b/tests/codegen/paginator-tests/build.gradle.kts @@ -2,48 +2,38 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ +import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir import aws.sdk.kotlin.gradle.dsl.skipPublishing -import software.amazon.smithy.gradle.tasks.SmithyBuild -import software.amazon.smithy.gradle.tasks.Validate as SmithyValidate plugins { - kotlin("jvm") - alias(libs.plugins.smithy.gradle) + alias(libs.plugins.kotlin.jvm) + id("aws.sdk.kotlin.gradle.smithybuild") } skipPublishing() -val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi") -kotlin.sourceSets.all { - optinAnnotations.forEach { languageSettings.optIn(it) } -} - -kotlin.sourceSets.getByName("main") { - kotlin.srcDir(layout.buildDirectory.dir("generated-src/src")) - kotlin.srcDir(layout.buildDirectory.dir("smithyprojections/paginator-tests/paginator-tests/kotlin-codegen")) -} - -tasks["smithyBuildJar"].enabled = false - -val codegen by configurations.creating +val codegen by configurations.getting dependencies { codegen(project(":codegen:smithy-kotlin-codegen")) codegen(libs.smithy.cli) + codegen(libs.smithy.model) } -val generateSdk = tasks.register("generateSdk") { - group = "codegen" - classpath = codegen - inputs.file(projectDir.resolve("smithy-build.json")) - inputs.files(codegen) +tasks.generateSmithyProjections { + smithyBuildConfigs.set(files("smithy-build.json")) } -tasks.named("smithyValidate") { - classpath = codegen +val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi") +kotlin.sourceSets.all { + optinAnnotations.forEach { languageSettings.optIn(it) } +} + +kotlin.sourceSets.getByName("main") { + kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir("paginator-tests")) } tasks.withType { - dependsOn(generateSdk) + dependsOn(tasks.generateSmithyProjections) } tasks.test { @@ -55,10 +45,9 @@ tasks.test { } dependencies { + compileOnly(project(":codegen:smithy-kotlin-codegen")) implementation(libs.kotlinx.coroutines.core) - - compileOnly(project(":codegen:smithy-kotlin-codegen")) implementation(project(":runtime:runtime-core")) implementation(project(":runtime:smithy-client")) implementation(project(":runtime:protocol:http-client")) diff --git a/tests/codegen/paginator-tests/smithy-build.json b/tests/codegen/paginator-tests/smithy-build.json index 50865d002..2cedcd719 100644 --- a/tests/codegen/paginator-tests/smithy-build.json +++ b/tests/codegen/paginator-tests/smithy-build.json @@ -1,5 +1,6 @@ { "version": "1.0", + "sources": ["model/paginated-operations.smithy"], "projections": { "paginator-tests": { "transforms": [ diff --git a/tests/codegen/waiter-tests/build.gradle.kts b/tests/codegen/waiter-tests/build.gradle.kts index b2b35b362..88dde6eb2 100644 --- a/tests/codegen/waiter-tests/build.gradle.kts +++ b/tests/codegen/waiter-tests/build.gradle.kts @@ -2,49 +2,41 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ +import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir import aws.sdk.kotlin.gradle.dsl.skipPublishing -import software.amazon.smithy.gradle.tasks.SmithyBuild -import software.amazon.smithy.gradle.tasks.Validate as SmithyValidate plugins { - kotlin("jvm") - alias(libs.plugins.smithy.gradle) + alias(libs.plugins.kotlin.jvm) + id("aws.sdk.kotlin.gradle.smithybuild") } skipPublishing() -val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi") -kotlin.sourceSets.all { - optinAnnotations.forEach { languageSettings.optIn(it) } -} - -kotlin.sourceSets.getByName("main") { - kotlin.srcDir(layout.buildDirectory.dir("smithyprojections/waiter-tests/waiter-tests/kotlin-codegen/src/main/kotlin")) -} - -tasks["smithyBuildJar"].enabled = false - -val codegen by configurations.creating +val codegen by configurations.getting dependencies { codegen(project(":codegen:smithy-kotlin-codegen")) codegen(libs.smithy.cli) + codegen(libs.smithy.model) } -val generateSdk = tasks.register("generateSdk") { - group = "codegen" - classpath = codegen - inputs.file(projectDir.resolve("smithy-build.json")) - inputs.files(codegen) +tasks.generateSmithyProjections { + smithyBuildConfigs.set(files("smithy-build.json")) } -tasks.named("smithyValidate") { - classpath = codegen +val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi") +kotlin.sourceSets.all { + optinAnnotations.forEach { languageSettings.optIn(it) } +} + +kotlin.sourceSets.getByName("main") { + kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir("waiter-tests")) } tasks.withType { - dependsOn(generateSdk) + dependsOn(tasks.generateSmithyProjections) kotlinOptions { - allWarningsAsErrors = false // FIXME Generated waiters code contains lots of warnings + // generated code has warnings unfortunately + allWarningsAsErrors = false } } @@ -57,10 +49,9 @@ tasks.test { } dependencies { + compileOnly(project(":codegen:smithy-kotlin-codegen")) implementation(libs.kotlinx.coroutines.core) - - compileOnly(project(":codegen:smithy-kotlin-codegen")) implementation(project(":runtime:runtime-core")) implementation(project(":runtime:smithy-client")) implementation(project(":runtime:protocol:http-client")) diff --git a/tests/codegen/waiter-tests/smithy-build.json b/tests/codegen/waiter-tests/smithy-build.json index b21592868..73b9d3978 100644 --- a/tests/codegen/waiter-tests/smithy-build.json +++ b/tests/codegen/waiter-tests/smithy-build.json @@ -1,5 +1,6 @@ { "version": "1.0", + "sources": ["model"], "projections": { "waiter-tests": { "transforms": [