2020-10-28 23:00:49 +08:00
|
|
|
/*
|
|
|
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2022-05-09 22:50:46 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2020-10-28 23:00:49 +08:00
|
|
|
*/
|
2022-03-29 02:05:08 +08:00
|
|
|
|
|
|
|
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
2022-08-12 18:35:55 +08:00
|
|
|
import java.io.ByteArrayOutputStream
|
2022-03-29 02:05:08 +08:00
|
|
|
|
2020-10-28 23:00:49 +08:00
|
|
|
plugins {
|
|
|
|
kotlin("jvm")
|
|
|
|
`maven-publish`
|
|
|
|
}
|
|
|
|
|
2022-09-08 00:31:46 +08:00
|
|
|
description = "Common code generation logic for generating Rust code from Smithy models"
|
|
|
|
extra["displayName"] = "Smithy :: Rust :: CodegenCore"
|
|
|
|
extra["moduleName"] = "software.amazon.smithy.rust.codegen.core"
|
2020-10-28 23:00:49 +08:00
|
|
|
|
2022-09-08 00:31:46 +08:00
|
|
|
group = "software.amazon.smithy.rust.codegen"
|
2020-10-28 23:00:49 +08:00
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
val smithyVersion: String by project
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
implementation(kotlin("stdlib-jdk8"))
|
2023-12-08 06:52:51 +08:00
|
|
|
implementation("org.jsoup:jsoup:1.16.2")
|
2020-10-28 23:00:49 +08:00
|
|
|
api("software.amazon.smithy:smithy-codegen-core:$smithyVersion")
|
2022-09-27 20:33:50 +08:00
|
|
|
api("com.moandjiezana.toml:toml4j:0.7.2")
|
2020-10-28 23:00:49 +08:00
|
|
|
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
|
|
|
|
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
|
2020-12-31 05:37:40 +08:00
|
|
|
implementation("software.amazon.smithy:smithy-waiters:$smithyVersion")
|
2020-10-28 23:00:49 +08:00
|
|
|
}
|
|
|
|
|
2022-08-17 18:24:19 +08:00
|
|
|
fun gitCommitHash(): String {
|
|
|
|
// Use commit hash from env if provided, it is helpful to override commit hash in some contexts.
|
|
|
|
// For example: while generating diff for generated SDKs we don't want to see version diff,
|
|
|
|
// so we are overriding commit hash to something fixed
|
|
|
|
val commitHashFromEnv = System.getenv("SMITHY_RS_VERSION_COMMIT_HASH_OVERRIDE")
|
|
|
|
if (commitHashFromEnv != null) {
|
|
|
|
return commitHashFromEnv
|
|
|
|
}
|
|
|
|
|
|
|
|
return try {
|
2022-08-12 18:35:55 +08:00
|
|
|
val output = ByteArrayOutputStream()
|
|
|
|
exec {
|
|
|
|
commandLine = listOf("git", "rev-parse", "HEAD")
|
|
|
|
standardOutput = output
|
|
|
|
}
|
|
|
|
output.toString().trim()
|
|
|
|
} catch (ex: Exception) {
|
|
|
|
"unknown"
|
|
|
|
}
|
2022-08-17 18:24:19 +08:00
|
|
|
}
|
2022-08-12 18:35:55 +08:00
|
|
|
|
2021-10-28 01:58:09 +08:00
|
|
|
val generateSmithyRuntimeCrateVersion by tasks.registering {
|
2024-01-12 06:39:00 +08:00
|
|
|
// Generate the version of the runtime to use as a resource.
|
|
|
|
// This keeps us from having to manually change version numbers in multiple places.
|
2023-12-07 06:05:21 +08:00
|
|
|
val resourcesDir = layout.buildDirectory.dir("resources/main/software/amazon/smithy/rust/codegen/core")
|
2024-01-12 06:39:00 +08:00
|
|
|
val versionsFile = resourcesDir.get().file("runtime-crate-versions.json")
|
|
|
|
outputs.file(versionsFile)
|
|
|
|
|
Fix runtime crate versions (#3260)
## Motivation and Context
When the stable/unstable crate versions were split, this caused a
regression in determining the crate version during codegen. This
enhances our crate-version forwarding code to publish all the crate
versions. For impact, see codegen-client-test.
## Description
- Change the build artifact to be a JSON blob will all required
versions.
## Testing
- [ ] Audit diff
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
2023-11-29 23:01:51 +08:00
|
|
|
val stableCrateVersion = project.properties["smithy.rs.runtime.crate.stable.version"].toString()
|
|
|
|
val unstableCrateVersion = project.properties["smithy.rs.runtime.crate.unstable.version"].toString()
|
2024-01-12 06:39:00 +08:00
|
|
|
inputs.property("stableCrateVersion", stableCrateVersion)
|
|
|
|
inputs.property("unstableCrateVersion", stableCrateVersion)
|
Fix runtime crate versions (#3260)
## Motivation and Context
When the stable/unstable crate versions were split, this caused a
regression in determining the crate version during codegen. This
enhances our crate-version forwarding code to publish all the crate
versions. For impact, see codegen-client-test.
## Description
- Change the build artifact to be a JSON blob will all required
versions.
## Testing
- [ ] Audit diff
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
2023-11-29 23:01:51 +08:00
|
|
|
|
2024-01-12 06:39:00 +08:00
|
|
|
val cargoTomls = mutableListOf<File>()
|
|
|
|
for (runtimePath in arrayOf("../rust-runtime", "../aws/rust-runtime")) {
|
|
|
|
for (path in project.projectDir.resolve(runtimePath).listFiles()!!) {
|
|
|
|
val manifestPath = path.resolve("Cargo.toml")
|
|
|
|
if (manifestPath.exists()) {
|
|
|
|
cargoTomls.add(manifestPath)
|
|
|
|
inputs.file(manifestPath)
|
|
|
|
}
|
Fix runtime crate versions (#3260)
## Motivation and Context
When the stable/unstable crate versions were split, this caused a
regression in determining the crate version during codegen. This
enhances our crate-version forwarding code to publish all the crate
versions. For impact, see codegen-client-test.
## Description
- Change the build artifact to be a JSON blob will all required
versions.
## Testing
- [ ] Audit diff
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
2023-11-29 23:01:51 +08:00
|
|
|
}
|
2024-01-12 06:39:00 +08:00
|
|
|
}
|
Fix runtime crate versions (#3260)
## Motivation and Context
When the stable/unstable crate versions were split, this caused a
regression in determining the crate version during codegen. This
enhances our crate-version forwarding code to publish all the crate
versions. For impact, see codegen-client-test.
## Description
- Change the build artifact to be a JSON blob will all required
versions.
## Testing
- [ ] Audit diff
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
2023-11-29 23:01:51 +08:00
|
|
|
|
2021-10-28 01:58:09 +08:00
|
|
|
sourceSets.main.get().output.dir(resourcesDir)
|
|
|
|
doLast {
|
2024-01-12 06:39:00 +08:00
|
|
|
// Version format must be kept in sync with `software.amazon.smithy.rust.codegen.core.Version`
|
|
|
|
versionsFile.asFile.writeText(
|
|
|
|
StringBuilder().append("{\n").also { json ->
|
|
|
|
fun StringBuilder.keyVal(key: String, value: String) = append("\"$key\": \"$value\"")
|
|
|
|
|
|
|
|
json.append(" ").keyVal("gitHash", gitCommitHash()).append(",\n")
|
|
|
|
json.append(" \"runtimeCrates\": {\n")
|
|
|
|
json.append(
|
|
|
|
cargoTomls.map { path ->
|
|
|
|
path.parentFile.name to path.readLines()
|
|
|
|
}
|
|
|
|
.filter { (name, manifestLines) ->
|
|
|
|
val publish = manifestLines.none { line -> line == "publish = false" }
|
|
|
|
// HACK: The experimental/unpublished typescript runtime crate needs
|
|
|
|
// to be included since it is referenced by the code generator and tested in CI.
|
|
|
|
publish || name == "aws-smithy-http-server-typescript"
|
|
|
|
}
|
|
|
|
.map { (name, manifestLines) ->
|
|
|
|
val stable = manifestLines.any { line -> line == "stable = true" }
|
|
|
|
val versionLine = manifestLines.first { line -> line.startsWith("version = \"") }
|
|
|
|
val maybeVersion = versionLine.slice(("version = \"".length)..(versionLine.length - 2))
|
|
|
|
val version = if (maybeVersion == "0.0.0-smithy-rs-head") {
|
|
|
|
when (stable) {
|
|
|
|
true -> stableCrateVersion
|
|
|
|
else -> unstableCrateVersion
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
maybeVersion
|
|
|
|
}
|
|
|
|
" \"$name\": \"$version\""
|
|
|
|
}
|
|
|
|
.joinToString(",\n"),
|
|
|
|
)
|
|
|
|
json.append(" }\n")
|
|
|
|
}.append("}").toString(),
|
|
|
|
)
|
2021-10-28 01:58:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-16 00:18:36 +08:00
|
|
|
java {
|
|
|
|
sourceCompatibility = JavaVersion.VERSION_11
|
|
|
|
targetCompatibility = JavaVersion.VERSION_11
|
|
|
|
}
|
|
|
|
|
2021-10-28 01:58:09 +08:00
|
|
|
tasks.compileKotlin {
|
2023-12-15 04:35:18 +08:00
|
|
|
kotlinOptions.jvmTarget = "11"
|
2021-10-28 01:58:09 +08:00
|
|
|
dependsOn(generateSmithyRuntimeCrateVersion)
|
2020-10-28 23:00:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reusable license copySpec
|
|
|
|
val licenseSpec = copySpec {
|
|
|
|
from("${project.rootDir}/LICENSE")
|
|
|
|
from("${project.rootDir}/NOTICE")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure jars to include license related info
|
|
|
|
tasks.jar {
|
|
|
|
metaInf.with(licenseSpec)
|
|
|
|
inputs.property("moduleName", project.name)
|
|
|
|
manifest {
|
|
|
|
attributes["Automatic-Module-Name"] = project.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val sourcesJar by tasks.creating(Jar::class) {
|
|
|
|
group = "publishing"
|
|
|
|
description = "Assembles Kotlin sources jar"
|
2022-11-12 05:04:30 +08:00
|
|
|
archiveClassifier.set("sources")
|
2020-10-28 23:00:49 +08:00
|
|
|
from(sourceSets.getByName("main").allSource)
|
|
|
|
}
|
|
|
|
|
2022-12-21 01:13:31 +08:00
|
|
|
val isTestingEnabled: String by project
|
|
|
|
if (isTestingEnabled.toBoolean()) {
|
|
|
|
val kotestVersion: String by project
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
runtimeOnly(project(":rust-runtime"))
|
|
|
|
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
|
|
|
|
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
|
2020-10-28 23:00:49 +08:00
|
|
|
}
|
|
|
|
|
2022-12-21 01:13:31 +08:00
|
|
|
tasks.compileTestKotlin {
|
2023-12-15 04:35:18 +08:00
|
|
|
kotlinOptions.jvmTarget = "11"
|
2022-12-21 01:13:31 +08:00
|
|
|
}
|
2020-10-28 23:00:49 +08:00
|
|
|
|
2022-12-21 01:13:31 +08:00
|
|
|
tasks.test {
|
|
|
|
useJUnitPlatform()
|
|
|
|
testLogging {
|
2023-07-14 04:35:55 +08:00
|
|
|
events("failed")
|
2022-12-21 01:13:31 +08:00
|
|
|
exceptionFormat = TestExceptionFormat.FULL
|
|
|
|
showCauses = true
|
|
|
|
showExceptions = true
|
|
|
|
showStackTraces = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-28 23:00:49 +08:00
|
|
|
|
|
|
|
publishing {
|
|
|
|
publications {
|
|
|
|
create<MavenPublication>("default") {
|
|
|
|
from(components["java"])
|
|
|
|
artifact(sourcesJar)
|
|
|
|
}
|
|
|
|
}
|
2023-12-07 06:05:21 +08:00
|
|
|
repositories { maven { url = uri(layout.buildDirectory.dir("repository")) } }
|
2020-10-28 23:00:49 +08:00
|
|
|
}
|