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

Productionize Integration Test Machinery (#15)

* Productionize Integration Test Machinery

smithy-build.json is now dynamically generated along with a Cargo.toml to facilitate easy adding of new integration tests.

* We don't need REPO_ROOT anymore
parent 787d3178
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -80,11 +80,8 @@ jobs:
        uses: actions/setup-java@v1
        with:
          java-version: 8
      - name: set REPO_ROOT
        run: echo "REPO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
      - name: integration-tests
        run: ./gradlew :codegen-test:test
      # TODO: when the multi repo integration tests are merged, update this to glob all of them
      - uses: actions/upload-artifact@v2
        name: Upload Codegen Output for inspection
        # Always upload the output even if the tests failed
@@ -92,7 +89,8 @@ jobs:
        with:
          name: codegen-output
          path: |
            codegen-test/build/smithyprojections/codegen-test/source/rust-codegen/
            codegen-test/build/smithyprojections/codegen-test/*/rust-codegen/
            codegen-test/build/smithyprojections/codegen-test/Cargo.toml
            !**/target
  runtime-tests:
    name: Rust runtime tests
+1 −0
Original line number Diff line number Diff line
smithy-build.json
+3 −6
Original line number Diff line number Diff line
# Codegen Integration Test
This module defines an integration test of the code generation machinery. Models defined in `model` are built and generated into a Rust package. A `cargoCheck` Gradle task ensures that the generated Rust code compiles. This is added as a finalizer of the `test` task. 
This module defines an integration test of the code generation machinery. `.build.gradle.kts` will generate a `smithy-build.json` file as part of the build. The Smithy build plugin then invokes our codegen machinery and generates Rust crates.

The `test` task will run `cargo check` and `cargo clippy` to validate that the generated Rust compiles and is idiomatic.
## Usage
```
# Compile codegen, Regenerate Rust, compile:
# REPO_ROOT allows the runtime deps to be specified properly:
REPO_ROOT=../ ../gradlew test
../gradlew test
```

The `smithy-build.json` configures the runtime dependencies to point directly to `../rust-runtime/*` via relative paths.
 No newline at end of file
+71 −2
Original line number Diff line number Diff line
@@ -16,12 +16,77 @@ val smithyVersion: String by project

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

data class CodegenTest(val service: String, val module: String)

val CodgenTests = listOf(
    CodegenTest("com.amazonaws.dynamodb#DynamoDB_20120810", "dynamo"),
    CodegenTest("com.amazonaws.ebs#Ebs", "ebs"),
    CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10")
)

fun generateSmithyBuild(tests: List<CodegenTest>): String {
    val projections = tests.joinToString(",\n") {
        """
            "${it.module}": {
                "plugins": { 
                    "rust-codegen": { 
                      "runtimeConfig": {
                        "relativePath": "${rootProject.projectDir.absolutePath}/rust-runtime"
                      },
                      "service": "${it.service}",
                      "module": "${it.module}",
                      "moduleVersion": "0.0.1",
                      "build": {
                        "rootProject": true
                      }
                 } 
               }
            }
        """.trimIndent()
    }
    return """
    {
        "version": "1.0",
        "projections": { $projections }
    }
    """
}


task("generateSmithyBuild") {
    description = "generate smithy-build.json"
    doFirst {
        projectDir.resolve("smithy-build.json").writeText(generateSmithyBuild(CodgenTests))
    }
}


fun generateCargoWorkspace(tests: List<CodegenTest>): String {
    return """
    [workspace]
    members = [
        ${tests.joinToString(",") { "\"${it.module}/rust-codegen\"" }}
    ]
    """.trimIndent()
}
task("generateCargoWorkspace") {
    description = "generate Cargo.toml workspace file"
    doFirst {
        buildDir.resolve("smithyprojections/codegen-test/Cargo.toml").writeText(generateCargoWorkspace(CodgenTests))
    }
}

tasks["smithyBuildJar"].dependsOn("generateSmithyBuild")
tasks["build"].finalizedBy("generateCargoWorkspace")


tasks.register<Exec>("cargoCheck") {
    workingDir("build/smithyprojections/codegen-test/source/rust-codegen/")
    workingDir("build/smithyprojections/codegen-test/")
    // disallow warnings
    environment("RUSTFLAGS", "-D warnings")
    commandLine("cargo", "check")
@@ -29,7 +94,7 @@ tasks.register<Exec>("cargoCheck") {
}

tasks.register<Exec>("cargoClippy") {
    workingDir("build/smithyprojections/codegen-test/source/rust-codegen/")
    workingDir("build/smithyprojections/codegen-test/")
    // disallow warnings
    environment("RUSTFLAGS", "-D warnings")
    commandLine("cargo", "clippy")
@@ -37,3 +102,7 @@ tasks.register<Exec>("cargoClippy") {
}

tasks["test"].finalizedBy("cargoCheck", "cargoClippy")

tasks["clean"].doFirst {
    delete("smithy-build.json")
}

codegen-test/smithy-build.json

deleted100644 → 0
+0 −17
Original line number Diff line number Diff line
{
  "version": "1.0",
  "outputDirectory": "target",
  "plugins": {
    "rust-codegen": {
      "runtimeConfig": {
        "relativePath": "${REPO_ROOT}/rust-runtime"
      },
      "service": "com.amazonaws.ebs#Ebs",
      "module": "weather",
      "moduleVersion": "0.0.1",
      "build": {
        "rootProject": true
      }
    }
  }
}
Loading