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

chore: refactor build to use custom smithy build plugin #1020

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"
}

/**
Expand Down
8 changes: 7 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ 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.1")
branch = "smithy-build-plugin"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pluginManagement {
repositories {
mavenLocal()
mavenCentral()
maven("https://plugins.gradle.org/m2/")
google()
gradlePluginPortal()
}
}
Expand Down
19 changes: 7 additions & 12 deletions tests/benchmarks/serde-benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<SmithyBuild>("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) {
Expand All @@ -103,7 +98,7 @@ val benchmarkModels = listOf(

val stageGeneratedSources = tasks.register("stageGeneratedSources") {
group = "codegen"
dependsOn(generateSdk)
dependsOn(tasks.generateSmithyProjections)
doLast {
benchmarkModels.forEach {
copy {
Expand Down
1 change: 1 addition & 0 deletions tests/benchmarks/serde-benchmarks/smithy-build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"version": "1.0",
"sources": ["model"],
Copy link
Contributor

Choose a reason for hiding this comment

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

question: why doesn't this need to reference a .smithy file like the other smithy-build.json files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"projections": {
"twitter": {
"transforms": [
Expand Down
60 changes: 25 additions & 35 deletions tests/codegen/nullability-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<KotlinCompile> {
// 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<SmithyBuild>("generateSdk") {
group = "codegen"
classpath = codegen
inputs.file(projectDir.resolve("smithy-build.json"))
inputs.files(codegen)
}

tasks.named<SmithyValidate>("smithyValidate") {
classpath = codegen
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(generateSdk)
dependsOn(tasks.generateSmithyProjections)
// generated code has warnings unfortunately
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can link this issue as a FIXME: awslabs/aws-sdk-kotlin#1169 (just converted now from the internal issue)

kotlinOptions.allWarningsAsErrors = false
}

tasks.test {
Expand All @@ -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)
}
1 change: 1 addition & 0 deletions tests/codegen/nullability-tests/smithy-build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"version": "1.0",
"sources": ["model/nullability.smithy"],
"projections": {
"client-mode": {
"transforms": [
Expand Down
43 changes: 16 additions & 27 deletions tests/codegen/paginator-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SmithyBuild>("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>("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<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(generateSdk)
dependsOn(tasks.generateSmithyProjections)
}

tasks.test {
Expand All @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions tests/codegen/paginator-tests/smithy-build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"version": "1.0",
"sources": ["model/paginated-operations.smithy"],
"projections": {
"paginator-tests": {
"transforms": [
Expand Down
45 changes: 18 additions & 27 deletions tests/codegen/waiter-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SmithyBuild>("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>("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<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
dependsOn(generateSdk)
dependsOn(tasks.generateSmithyProjections)
kotlinOptions {
allWarningsAsErrors = false // FIXME Generated waiters code contains lots of warnings
// generated code has warnings unfortunately
allWarningsAsErrors = false
}
}

Expand All @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions tests/codegen/waiter-tests/smithy-build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"version": "1.0",
"sources": ["model"],
"projections": {
"waiter-tests": {
"transforms": [
Expand Down
Loading