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

Establish the `codegen-core` module (#1697)

* Create the `codegen-core` module
* Move the `Version` class into `codegen-core`
* Rename `codegen` to `codegen-client`
* Rename `codegen-test` to `codegen-client-test`
* Move shared test models to common location
* Fix Smithy validation errors in `misc.smithy`
parent e3239e1a
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -32,8 +32,9 @@ Project Layout
  * `./gradlew :aws:sdk:assemble`: Generate (but do not test / compile etc.) a fresh SDK into `sdk/build/aws-sdk`
  * `./gradlew :aws:sdk:test`: Generate & run all tests for a fresh SDK
  * `./gradlew :aws:sdk:{cargoCheck, cargoTest, cargoDocs, cargoClippy}`: Generate & run specified cargo command.
* `codegen`: Whitelabel Smithy client code generation
* `codegen-test`: Smithy protocol test generation & integration tests for Smithy client whitelabel code
* `codegen-core`: Common code generation logic useful for clients and servers
* `codegen-client`: Whitelabel Smithy client code generation
* `codegen-client-test`: Smithy protocol test generation & integration tests for Smithy client whitelabel code
* [`design`](design): Design documentation. See the [design/README.md](design/README.md) for details about building / viewing.
* `codegen-server`: Whitelabel Smithy server code generation
* `codegen-server-test`: Smithy protocol test generation & integration tests for Smithy server whitelabel code
@@ -52,7 +53,7 @@ In general, the components of smithy-rs affect each other in the following order
3. `aws/rust-runtime`
4. `aws/sdk-codegen`

Some components, such as `codegen-test` and `codegen-server-test`, are purely for testing other components.
Some components, such as `codegen-client-test` and `codegen-server-test`, are purely for testing other components.

### Testing `rust-runtime` and `aws/rust-runtime`

@@ -84,9 +85,11 @@ To test the code generation, the following can be used:

```bash
# Run Kotlin codegen unit tests
./gradlew codegen:check
./gradlew codegen-core:check
./gradlew codegen-client:check
./gradlew codegen-server:check
# Run client codegen tests
./gradlew codegen-test:check
./gradlew codegen-client-test:check
# Run server codegen tests
./gradlew codegen-server-test:check
```
@@ -95,8 +98,8 @@ Several Kotlin unit tests generate Rust projects and compile them. When these fa
output links to the location of the generated code so that it can be inspected.

To look at generated code when the codegen tests fail, check these paths depending on the test suite that's failing:
- For codegen-test: `codegen-test/build/smithyprojections/codegen-test`
- For codgen-server-test: `codegen-server-test/build/smithyprojections/codegen-server-test`
- For codegen-client-test: `codegen-client-test/build/smithyprojections/codegen-client-test`
- For codegen-server-test: `codegen-server-test/build/smithyprojections/codegen-server-test`

### Testing SDK Codegen

+2 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ val smithyVersion: String by project
val kotestVersion: String by project

dependencies {
    implementation(project(":codegen"))
    implementation(project(":codegen-core"))
    implementation(project(":codegen-client"))
    runtimeOnly(project(":aws:rust-runtime"))
    implementation("org.jsoup:jsoup:1.14.3")
    implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
+17 −5
Original line number Diff line number Diff line
@@ -10,16 +10,28 @@ import org.gradle.kotlin.dsl.register
import java.io.File

/**
 * This file contains common functionality shared across the buildscripts for the `codegen-test` and `codegen-server-test`
 * modules.
 * This file contains common functionality shared across the build scripts for the
 * `codegen-client-test` and `codegen-server-test` modules.
 */

data class CodegenTest(val service: String, val module: String, val extraConfig: String? = null)
data class CodegenTest(
    val service: String,
    val module: String,
    val extraConfig: String? = null,
    val imports: List<String> = emptyList(),
)

fun generateImports(imports: List<String>): String = if (imports.isEmpty()) {
    ""
} else {
    "\"imports\": [${imports.map { "\"$it\"" }.joinToString(", ")}],"
}

private fun generateSmithyBuild(projectDir: String, pluginName: String, tests: List<CodegenTest>): String {
    val projections = tests.joinToString(",\n") {
        """
        "${it.module}": {
            ${generateImports(it.imports)}
            "plugins": {
                "$pluginName": {
                    "runtimeConfig": {
+4 −4
Original line number Diff line number Diff line
@@ -13,14 +13,14 @@ These commands are all meant to be run from the repository root.
To run all protocol tests of all the integration test services:

```sh
./gradlew codegen-test:build
./gradlew codegen-client-test:build
```

To run only a _subset_ of the integration test services (refer to
`./build.gradle.kts` for a full list):

```sh
./gradlew codegen-test:build -P modules='simple,rest_json'
./gradlew codegen-client-test:build -P modules='simple,rest_json'
```

The Gradle task will run `cargo check`, `cargo test`, `cargo docs` and `cargo
@@ -29,7 +29,7 @@ subset of these commands. For instance, if you're working on documentation and
want to check that the crates also compile, you can run:

```sh
./gradlew codegen-test:build -P cargoCommands='check,docs'
./gradlew codegen-client-test:build -P cargoCommands='check,docs'
```

For fast development iteration cycles on protocol tests, we recommend you write
@@ -38,5 +38,5 @@ test. Alternatively, you can write a minimal integration test service
definition in `model/simple.smithy` and run:

```sh
./gradlew codegen-test:build -P cargoCommands='test' -P modules='simple'
./gradlew codegen-client-test:build -P cargoCommands='test' -P modules='simple'
```
Loading