Unverified Commit b98c0740 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Split SDK examples into a top-level directory (#843)

* Split SDK examples into a top-level directory

* Update changelog

* Fix `aws-config` and integration test dependency paths

* Fix path replacements
parent 93fd642d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ vNext (Month Day, Year)
- Fix epoch seconds date-time parsing bug in `aws-smithy-types` (smithy-rs#834)
- Omit trailing zeros from fraction when formatting HTTP dates in `aws-smithy-types` (smithy-rs#834)
- Model structs now have accessor methods for their members (smithy-rs#842)
- Moved examples into repository root (aws-sdk-rust#181, smithy-rs#843)
- :bug: Fix bug that caused signing to fail for requests where the body length was <=9. (smithy-rs#845)

v0.0.23-alpha (November 3rd, 2021)
+11 −11
Original line number Diff line number Diff line
@@ -32,22 +32,22 @@ dns = ["tokio/rt"]
default = ["default-provider", "rustls", "rt-tokio", "dns", "tcp-connector"]

[dependencies]
aws-sdk-sts = { path = "../../sdk/build/aws-sdk/sts", optional = true }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/aws-smithy-async" }
aws-smithy-client = { path = "../../sdk/build/aws-sdk/aws-smithy-client" }
aws-smithy-types = { path = "../../sdk/build/aws-sdk/aws-smithy-types" }
aws-types = { path = "../../sdk/build/aws-sdk/aws-types" }
aws-sdk-sts = { path = "../../sdk/build/aws-sdk/sdk/sts", optional = true }
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async" }
aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client" }
aws-smithy-types = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-types" }
aws-types = { path = "../../sdk/build/aws-sdk/sdk/aws-types" }
tokio = { version = "1", features = ["sync"], optional = true }
tracing = { version = "0.1" }

# TODO: remove when middleware stacks are moved inside of clients directly
aws-hyper = { path = "../../sdk/build/aws-sdk/aws-hyper", optional = true }
aws-hyper = { path = "../../sdk/build/aws-sdk/sdk/aws-hyper", optional = true }

# imds
aws-http = { path = "../../sdk/build/aws-sdk/aws-http", optional = true }
aws-smithy-http = { path = "../../sdk/build/aws-sdk/aws-smithy-http", optional = true }
aws-smithy-http-tower = { path = "../../sdk/build/aws-sdk/aws-smithy-http-tower", optional = true }
aws-smithy-json = { path = "../../sdk/build/aws-sdk/aws-smithy-json", optional = true }
aws-http = { path = "../../sdk/build/aws-sdk/sdk/aws-http", optional = true }
aws-smithy-http = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http", optional = true }
aws-smithy-http-tower = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-http-tower", optional = true }
aws-smithy-json = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-json", optional = true }
bytes = "1.1.0"
http = "0.2.4"
tower = { version = "0.4.8", optional = true }
@@ -68,4 +68,4 @@ arbitrary = "1.0.2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

aws-smithy-client = { path = "../../sdk/build/aws-sdk/aws-smithy-client", features = ["test-util"] }
aws-smithy-client = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-client", features = ["test-util"] }
+32 −25
Original line number Diff line number Diff line
@@ -21,7 +21,10 @@ plugins {

val smithyVersion: String by project

val sdkOutputDir = buildDir.resolve("aws-sdk")
val outputDir = buildDir.resolve("aws-sdk")
val sdkOutputDir = outputDir.resolve("sdk")
val examplesOutputDir = outputDir.resolve("examples")

val runtimeModules = listOf(
    "aws-smithy-async",
    "aws-smithy-client",
@@ -290,13 +293,13 @@ task("relocateExamples") {
        copy {
            from(projectDir)
            include("examples/**")
            into(sdkOutputDir)
            into(outputDir)
            exclude("**/target")
            filter { line -> line.replace("build/aws-sdk/", "") }
            filter { line -> line.replace("build/aws-sdk/sdk/", "sdk/") }
        }
    }
    inputs.dir(projectDir.resolve("examples"))
    outputs.dir(sdkOutputDir)
    outputs.dir(outputDir)
}

/**
@@ -305,7 +308,7 @@ task("relocateExamples") {
 */
fun rewritePathDependency(line: String): String {
    // some runtime crates are actually dependent on the generated bindings:
    return line.replace("../sdk/build/aws-sdk/", "")
    return line.replace("../sdk/build/aws-sdk/sdk/", "")
        // others use relative dependencies::
        .replace("../../rust-runtime/", "")
}
@@ -329,9 +332,9 @@ fun rewriteSmithyRsCrateVersion(line: String): String =
    rewriteCrateVersion(line, getProperty("smithy.rs.runtime.crate.version")!!)

/** Patches a file with the result of the given `operation` being run on each line */
fun patchFile(path: String, operation: (String) -> String) {
    val patchedContents = File(path).readLines().joinToString("\n", transform = operation)
    File(path).writeText(patchedContents)
fun patchFile(path: File, operation: (String) -> String) {
    val patchedContents = path.readLines().joinToString("\n", transform = operation)
    path.writeText(patchedContents)
}

tasks.register<Copy>("copyAllRuntimes") {
@@ -352,7 +355,7 @@ tasks.register("relocateAwsRuntime") {
    doLast {
        // Patch the Cargo.toml files
        awsModules.forEach { moduleName ->
            patchFile("$sdkOutputDir/$moduleName/Cargo.toml") { line ->
            patchFile(sdkOutputDir.resolve("$moduleName/Cargo.toml")) { line ->
                line.let(::rewritePathDependency)
                    .let(::rewriteAwsSdkCrateVersion)
            }
@@ -364,7 +367,7 @@ tasks.register("relocateRuntime") {
    doLast {
        // Patch the Cargo.toml files
        runtimeModules.forEach { moduleName ->
            patchFile("$sdkOutputDir/$moduleName/Cargo.toml") { line ->
            patchFile(sdkOutputDir.resolve("$moduleName/Cargo.toml")) { line ->
                line.let(::rewriteSmithyRsCrateVersion)
            }
        }
@@ -378,23 +381,27 @@ fun generateCargoWorkspace(services: List<AwsService>): String {
        .filter { generatedModules.contains(it.name) }
        .map { "examples/${it.name}" }

    val modules = services.map(AwsService::module) + runtimeModules + awsModules + examples.toList()
    val modules = (
        services.map(AwsService::module).map { "sdk/$it" } +
        runtimeModules.map { "sdk/$it" } +
        awsModules.map { "sdk/$it" } +
        examples.toList()
    ).sorted()
    return """
    [workspace]
    members = [
        ${modules.joinToString(",") { "\"$it\"" }}
    ]
    """.trimIndent()
    |[workspace]
    |members = [${"\n"}${modules.joinToString(",\n") { "|    \"$it\"" }}
    |]
    """.trimMargin()
}
task("generateCargoWorkspace") {
    description = "generate Cargo.toml workspace file"
    doFirst {
        sdkOutputDir.mkdirs()
        sdkOutputDir.resolve("Cargo.toml").writeText(generateCargoWorkspace(awsServices))
        outputDir.mkdirs()
        outputDir.resolve("Cargo.toml").writeText(generateCargoWorkspace(awsServices))
    }
    inputs.property("servicelist", awsServices.sortedBy { it.module }.toString())
    inputs.dir(projectDir.resolve("examples"))
    outputs.file(sdkOutputDir.resolve("Cargo.toml"))
    outputs.file(outputDir.resolve("Cargo.toml"))
    outputs.upToDateWhen { false }
}

@@ -418,7 +425,7 @@ tasks["assemble"].dependsOn("smithyBuildJar")
tasks["assemble"].finalizedBy("finalizeSdk")

tasks.register<Exec>("cargoCheck") {
    workingDir(sdkOutputDir)
    workingDir(outputDir)
    // disallow warnings
    environment("RUSTFLAGS", "-D warnings")
    commandLine("cargo", "check", "--lib", "--tests", "--benches")
@@ -426,7 +433,7 @@ tasks.register<Exec>("cargoCheck") {
}

tasks.register<Exec>("cargoTest") {
    workingDir(sdkOutputDir)
    workingDir(outputDir)
    // disallow warnings
    environment("RUSTFLAGS", "-D warnings")
    commandLine("cargo", "test")
@@ -434,7 +441,7 @@ tasks.register<Exec>("cargoTest") {
}

tasks.register<Exec>("cargoDocs") {
    workingDir(sdkOutputDir)
    workingDir(outputDir)
    // disallow warnings
    environment("RUSTDOCFLAGS", "-D warnings")
    commandLine("cargo", "doc", "--no-deps", "--document-private-items")
@@ -442,7 +449,7 @@ tasks.register<Exec>("cargoDocs") {
}

tasks.register<Exec>("cargoClippy") {
    workingDir(sdkOutputDir)
    workingDir(outputDir)
    // disallow warnings
    commandLine("cargo", "clippy", "--", "-D", "warnings")
    dependsOn("assemble")
@@ -450,10 +457,10 @@ tasks.register<Exec>("cargoClippy") {

tasks.register<RunExampleTask>("runExample") {
    dependsOn("assemble")
    outputDir = sdkOutputDir
    outputDir = outputDir
}

// TODO: validate that the example exists. Otherwise this fails with a hiden error.
// TODO: validate that the example exists. Otherwise this fails with a hidden error.
open class RunExampleTask @javax.inject.Inject constructor() : Exec() {
    @Option(option = "example", description = "Example to run")
    var example: String? = null
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { path = "../../build/aws-sdk/aws-config" }
aws-sdk-apigateway = { path = "../../build/aws-sdk/apigateway", package = "aws-sdk-apigateway" }
aws-config = { path = "../../build/aws-sdk/sdk/aws-config" }
aws-sdk-apigateway = { path = "../../build/aws-sdk/sdk/apigateway" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.18"
+3 −3
Original line number Diff line number Diff line
@@ -7,9 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { path = "../../build/aws-sdk/aws-config" }
aws-sdk-applicationautoscaling = { package = "aws-sdk-applicationautoscaling", path = "../../build/aws-sdk/applicationautoscaling" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
aws-config = { path = "../../build/aws-sdk/sdk/aws-config" }
aws-sdk-applicationautoscaling = { path = "../../build/aws-sdk/sdk/applicationautoscaling" }
aws-types = { path = "../../build/aws-sdk/sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
Loading