Unverified Commit ad588131 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Refactor generation of versions to support generating crate versions … (#808)

* Refactor generation of versions to support generating crate versions directly

* Update changelog

* Fix generated SDK version during tests
parent c2a93dd7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ vNext (Month Day, Year)
- `<operation>.make_operation(&config)` is now an `async` function for all operations. Code should be updated to call `.await`. This will only impact users using the low-level API. (smithy-rs#797)

**New this week**
- SDK code generation now includes a version in addition to path parameters when the `version` parameter is included in smithy-build.json
- `moduleDescription` in `smithy-build.json` settings is now optional
- Upgrade to Smithy 1.12

v0.27 (October 20th, 2021)
+15 −2
Original line number Diff line number Diff line
@@ -29,8 +29,23 @@ dependencies {
    testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
}

val generateAwsSdkVersion by tasks.registering {
    // generate the version of the runtime to use as a resource.
    // this keeps us from having to manually change version numbers in multiple places
    val resourcesDir = "$buildDir/resources/main/software/amazon/smithy/rustsdk"
    val versionFile = file("$resourcesDir/sdk-crate-version.txt")
    outputs.file(versionFile)
    val crateVersion = project.properties["aws.sdk.version"]?.toString()!!
    inputs.property("crateVersion", crateVersion)
    sourceSets.main.get().output.dir(resourcesDir)
    doLast {
        versionFile.writeText(crateVersion)
    }
}

tasks.compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
    dependsOn(generateAwsSdkVersion)
}

tasks.compileTestKotlin {
@@ -67,7 +82,6 @@ tasks.test {
    }
}


// Configure jacoco (code coverage) to generate an HTML report
tasks.jacocoTestReport {
    reports {
@@ -80,7 +94,6 @@ tasks.jacocoTestReport {
// Always run the jacoco test report after testing.
tasks["test"].finalizedBy(tasks["jacocoTestReport"])


publishing {
    publications {
        create<MavenPublication>("default") {
+17 −5
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

package software.amazon.smithy.rustsdk

import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.smithy.RuntimeCrateLocation
@@ -13,9 +14,18 @@ import software.amazon.smithy.rust.codegen.smithy.crateLocation
import java.io.File
import java.nio.file.Path

fun RuntimeConfig.awsRoot(): RuntimeCrateLocation = when (runtimeCrateLocation) {
    is RuntimeCrateLocation.Path -> {
        val cratePath = (runtimeCrateLocation as RuntimeCrateLocation.Path).path
fun defaultSdkVersion(): String {
    // generated as part of the build, see codegen/build.gradle.kts
    try {
        return object {}.javaClass.getResource("sdk-crate-version.txt")?.readText()
            ?: throw CodegenException("sdk-crate-version.txt does not exist")
    } catch (ex: Exception) {
        throw CodegenException("failed to load sdk-crate-version.txt which sets the default client-runtime version", ex)
    }
}

fun RuntimeConfig.awsRoot(): RuntimeCrateLocation {
    val updatedPath = runtimeCrateLocation.path?.let { cratePath ->
        val asPath = Path.of(cratePath)
        val path = if (asPath.isAbsolute) {
            asPath.parent.resolve("aws/rust-runtime").toAbsolutePath().toString()
@@ -23,9 +33,11 @@ fun RuntimeConfig.awsRoot(): RuntimeCrateLocation = when (runtimeCrateLocation)
            cratePath
        }
        check(File(path).exists()) { "$path must exist to generate a working SDK" }
        RuntimeCrateLocation.Path(path)
        path
    }
    is RuntimeCrateLocation.Versioned -> runtimeCrateLocation
    return runtimeCrateLocation.copy(
        path = updatedPath, version = runtimeCrateLocation.version?.let { defaultSdkVersion() }
    )
}

object AwsRuntimeType {
+4 −3
Original line number Diff line number Diff line
@@ -3,10 +3,10 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

import software.amazon.smithy.model.Model
import software.amazon.smithy.aws.traits.ServiceTrait
import software.amazon.smithy.model.traits.TitleTrait
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.traits.TitleTrait
import java.util.Properties
import kotlin.streams.toList

@@ -218,7 +218,8 @@ fun generateSmithyBuild(services: List<AwsService>): String {
                "plugins": {
                    "rust-codegen": {
                        "runtimeConfig": {
                            "relativePath": "../"
                            "relativePath": "../",
                            "version": "DEFAULT"
                        },
                        "codegen": {
                            "includeFluentClient": false,
+0 −4
Original line number Diff line number Diff line
@@ -3,10 +3,6 @@
# SPDX-License-Identifier: Apache-2.0.
#

# Version number to use for the generated SDK
# Note: these must always be full 3-segment semver versions
aws.sdk.version=0.0.22-alpha
smithy.rs.runtime.crate.version=0.27.0-alpha

# timestream requires endpoint discovery: https://github.com/awslabs/aws-sdk-rust/issues/114
aws.services.fullsdk=-timestreamwrite,-timestreamquery
Loading