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(codegen): migrate to updated smithy gradle plugins #5912

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 4 additions & 17 deletions codegen/generic-client-test-codegen/build.gradle.kts
Expand Up @@ -13,10 +13,6 @@
* permissions and limitations under the License.
*/

import software.amazon.smithy.gradle.tasks.SmithyBuild

val smithyVersion: String by project

buildscript {
val smithyVersion: String by project

Expand All @@ -30,26 +26,17 @@ buildscript {
}

plugins {
val smithyGradleVersion: String by project
id("software.amazon.smithy").version(smithyGradleVersion)
`java-library`
id("software.amazon.smithy.gradle.smithy-base")
}

dependencies {
val smithyVersion: String by project

implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
implementation(project(":smithy-aws-typescript-codegen"))
}

// This project doesn't produce a JAR.
tasks["jar"].enabled = false

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

tasks.create<SmithyBuild>("buildSdk") {
addRuntimeClasspath = true
}

// Run the `buildSdk` automatically.
tasks["build"].finalizedBy(tasks["buildSdk"])
35 changes: 21 additions & 14 deletions codegen/generic-client-test-codegen/model/echo.smithy
Expand Up @@ -6,46 +6,53 @@ use aws.protocols#restJson1

@restJson1
service EchoService {
version: "2018-05-10",
operations: [Echo, Length],
version: "2018-05-10"
operations: [
Echo
Length
]
}

@http(code: 200, method: "POST", uri: "/echo",)
@http(code: 200, method: "POST", uri: "/echo")
operation Echo {
input: EchoInput,
output: EchoOutput,
errors: [PalindromeException],
input: EchoInput
output: EchoOutput
errors: [
PalindromeException
]
}

@readonly
@http(code: 200, method: "GET", uri: "/length/{string}")
operation Length {
input: LengthInput,
output: LengthOutput,
errors: [PalindromeException],
input: LengthInput
output: LengthOutput
errors: [
PalindromeException
]
}

structure EchoInput {
string: String,
string: String
}

structure EchoOutput {
string: String,
string: String
}

structure LengthInput {
@required
@httpLabel
string: String,
string: String
}

structure LengthOutput {
length: Integer,
length: Integer
}

/// For some reason, this service does not like palindromes!
@httpError(400)
@error("client")
structure PalindromeException {
message: String,
message: String
}
6 changes: 3 additions & 3 deletions codegen/generic-client-test-codegen/model/weather.smithy
Expand Up @@ -93,7 +93,7 @@ operation OnlyCustomAuthOptional {}
@readonly
@http(method: "GET", uri: "/SameAsService")
operation SameAsService {
output := {
service: String
}
output := {
service: String
}
}
2 changes: 1 addition & 1 deletion codegen/gradle.properties
@@ -1,2 +1,2 @@
smithyVersion=1.45.0
smithyGradleVersion=0.6.0
smithyGradleVersion=0.10.1
23 changes: 5 additions & 18 deletions codegen/protocol-test-codegen/build.gradle.kts
Expand Up @@ -13,10 +13,6 @@
* permissions and limitations under the License.
*/

import software.amazon.smithy.gradle.tasks.SmithyBuild

val smithyVersion: String by project

buildscript {
val smithyVersion: String by project

Expand All @@ -30,25 +26,16 @@ buildscript {
}

plugins {
val smithyGradleVersion: String by project
id("software.amazon.smithy").version(smithyGradleVersion)
`java-library`
id("software.amazon.smithy.gradle.smithy-base")
}

dependencies {
val smithyVersion: String by project

smithyBuild(project(":smithy-aws-typescript-codegen"))
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
implementation(project(":smithy-aws-typescript-codegen"))
}

// This project doesn't produce a JAR.
tasks["jar"].enabled = false

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

tasks.create<SmithyBuild>("buildSdk") {
addRuntimeClasspath = true
}

// Run the `buildSdk` automatically.
tasks["build"].finalizedBy(tasks["buildSdk"])
32 changes: 10 additions & 22 deletions codegen/sdk-codegen/build.gradle.kts
Expand Up @@ -15,12 +15,9 @@

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.gradle.tasks.SmithyBuild
import software.amazon.smithy.aws.traits.ServiceTrait
import java.util.stream.Stream
import kotlin.streams.toList

val smithyVersion: String by project

Expand All @@ -38,8 +35,8 @@ buildscript {
}

plugins {
val smithyGradleVersion: String by project
id("software.amazon.smithy").version(smithyGradleVersion)
`java-library`
id("software.amazon.smithy.gradle.smithy-base")
}

dependencies {
Expand All @@ -48,25 +45,18 @@ dependencies {
implementation("software.amazon.smithy:smithy-smoke-test-traits:$smithyVersion")
}

// This project doesn't produce a JAR.
tasks["jar"].enabled = false

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

tasks.create<SmithyBuild>("buildSdk") {
addRuntimeClasspath = true
}

configure<software.amazon.smithy.gradle.SmithyExtension> {
smithy {
format.set(false)
val clientNameProp: String? by project
if (!(clientNameProp?.isEmpty() ?: true)) {
smithyBuildConfigs = files("smithy-build-" + clientNameProp + ".json")
outputDirectory = file("build-single/" + clientNameProp)
}
}

// This project doesn't produce a JAR.
tasks["jar"].enabled = false

// Generates a smithy-build.json file by creating a new projection for every
// JSON file found in aws-models/. The generated smithy-build.json file is
// not committed to git since it's rebuilt each time codegen is performed.
Expand Down Expand Up @@ -101,7 +91,7 @@ tasks.register("generate-smithy-build") {
val clientName = sdkId.split("-").toTypedArray()
.map { it.capitalize() }
.joinToString(separator = " ")
var manifestOverwrites = Node.parse(
val manifestOverwrites = Node.parse(
File("smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/package.json.template")
.readText()
).expectObjectNode()
Expand Down Expand Up @@ -150,7 +140,5 @@ tasks.register("generate-default-configs-provider", JavaExec::class) {
args(listOf(project.properties["defaultsModeConfigOutput"]))
}

// Run the `buildSdk` automatically.
tasks["build"]
.dependsOn(tasks["generate-smithy-build"])
.finalizedBy(tasks["buildSdk"])
// Ensure the smithy-build.json file is generated before smithy build is executed
tasks["smithyBuild"].dependsOn(tasks["generate-smithy-build"])
15 changes: 15 additions & 0 deletions codegen/settings.gradle.kts
Expand Up @@ -35,3 +35,18 @@ file(
.filter { it.isDirectory }
.forEach { includeBuild(it.absolutePath) }
}

pluginManagement {
val smithyGradleVersion: String by settings

plugins {
id("software.amazon.smithy.gradle.smithy-jar").version(smithyGradleVersion)
id("software.amazon.smithy.gradle.smithy-base").version(smithyGradleVersion)
}

repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}
}
18 changes: 9 additions & 9 deletions codegen/smithy-aws-typescript-codegen/build.gradle.kts
Expand Up @@ -20,8 +20,6 @@ description = "Generates TypeScript code for AWS protocols from Smithy models"
extra["displayName"] = "Smithy :: AWS :: Typescript :: Codegen"
extra["moduleName"] = "software.amazon.smithy.aws.typescript.codegen"

val smithyVersion: String by project

buildscript {
val smithyVersion: String by project

Expand All @@ -35,6 +33,8 @@ buildscript {
}

dependencies {
val smithyVersion: String by project

api("software.amazon.smithy:smithy-aws-cloudformation-traits:$smithyVersion")
api("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
api("software.amazon.smithy:smithy-aws-endpoints:$smithyVersion")
Expand All @@ -49,16 +49,16 @@ dependencies {
tasks.register("set-aws-sdk-versions") {
doLast {
mkdir("$buildDir/generated/resources/software/amazon/smithy/aws/typescript/codegen")
var versionsFile =
val versionsFile =
file("$buildDir/generated/resources/software/amazon/smithy/aws/typescript/codegen/sdkVersions.properties")
var roots = project.file("../../packages").listFiles().toMutableList() + project.file("../../clients").listFiles().toList()
val roots = project.file("../../packages").listFiles().toMutableList() + project.file("../../clients").listFiles().toList()
roots.forEach { packageDir ->
var packageJsonFile = File(packageDir, "package.json")
val packageJsonFile = File(packageDir, "package.json")
if (packageJsonFile.isFile()) {
var packageJson = Node.parse(packageJsonFile.readText()).expectObjectNode()
var packageName = packageJson.expectStringMember("name").getValue()
var packageVersion = packageJson.expectStringMember("version").getValue()
var isPrivate = packageJson.getBooleanMemberOrDefault("private", false)
val packageJson = Node.parse(packageJsonFile.readText()).expectObjectNode()
val packageName = packageJson.expectStringMember("name").getValue()
val packageVersion = packageJson.expectStringMember("version").getValue()
val isPrivate = packageJson.getBooleanMemberOrDefault("private", false)
if (!isPrivate) {
versionsFile.appendText("$packageName=$packageVersion\n")
}
Expand Down