Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Establish the codegen-core module #1697

Merged
merged 9 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`

Expand Down Expand Up @@ -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
```
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion aws/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 17 additions & 5 deletions buildSrc/src/main/kotlin/CodegenTestCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ")}],"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"\"imports\": [${imports.map { "\"$it\"" }.joinToString(", ")}],"
"\"imports\": [${imports.joinToString(", ") { "\"$it\"" }}],"

}

private fun generateSmithyBuild(projectDir: String, pluginName: String, tests: List<CodegenTest>): String {
val projections = tests.joinToString(",\n") {
"""
"${it.module}": {
${generateImports(it.imports)}
"plugins": {
"$pluginName": {
"runtimeConfig": {
Expand All @@ -31,8 +43,8 @@ private fun generateSmithyBuild(projectDir: String, pluginName: String, tests: L
"moduleDescription": "test",
"moduleAuthors": ["[email protected]"]
${it.extraConfig ?: ""}
}
}
}
}
}
""".trimIndent()
}
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions codegen-test/README.md → codegen-client-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
```
107 changes: 107 additions & 0 deletions codegen-client-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

extra["displayName"] = "Smithy :: Rust :: Codegen :: Test"
extra["moduleName"] = "software.amazon.smithy.kotlin.codegen.test"

tasks["jar"].enabled = false

plugins {
val smithyGradlePluginVersion: String by project
id("software.amazon.smithy").version(smithyGradlePluginVersion)
}

val smithyVersion: String by project
val defaultRustDocFlags: String by project
val properties = PropertyRetriever(rootProject, project)

val pluginName = "rust-codegen"
val workingDirUnderBuildDir = "smithyprojections/codegen-client-test/"

buildscript {
val smithyVersion: String by project
dependencies {
classpath("software.amazon.smithy:smithy-cli:$smithyVersion")
}
}

dependencies {
implementation(project(":codegen-client"))
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")
}

val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
listOf(
CodegenTest("com.amazonaws.simple#SimpleService", "simple", imports = listOf("$commonModels/simple.smithy")),
CodegenTest("com.amazonaws.dynamodb#DynamoDB_20120810", "dynamo"),
CodegenTest("com.amazonaws.ebs#Ebs", "ebs", imports = listOf("$commonModels/ebs.json")),
CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10"),
CodegenTest("aws.protocoltests.json#JsonProtocol", "json_rpc11"),
CodegenTest("aws.protocoltests.restjson#RestJson", "rest_json"),
CodegenTest("aws.protocoltests.restjson#RestJsonExtras", "rest_json_extras", imports = listOf("$commonModels/rest-json-extras.smithy")),
CodegenTest("aws.protocoltests.misc#MiscService", "misc", imports = listOf("$commonModels/misc.smithy")),
CodegenTest(
"aws.protocoltests.restxml#RestXml", "rest_xml",
extraConfig = """, "codegen": { "addMessageToErrors": false } """,
),

CodegenTest(
"aws.protocoltests.query#AwsQuery", "aws_query",
extraConfig = """, "codegen": { "addMessageToErrors": false } """,
),
CodegenTest(
"aws.protocoltests.ec2#AwsEc2", "ec2_query",
extraConfig = """, "codegen": { "addMessageToErrors": false } """,
),
CodegenTest(
"aws.protocoltests.restxml.xmlns#RestXmlWithNamespace",
"rest_xml_namespace",
extraConfig = """, "codegen": { "addMessageToErrors": false } """,
),
CodegenTest(
"aws.protocoltests.restxml#RestXmlExtras",
"rest_xml_extras",
extraConfig = """, "codegen": { "addMessageToErrors": false } """,
),
CodegenTest(
"aws.protocoltests.restxmlunwrapped#RestXmlExtrasUnwrappedErrors",
"rest_xml_extras_unwrapped",
extraConfig = """, "codegen": { "addMessageToErrors": false } """,
),
CodegenTest(
"crate#Config",
"naming_test_ops",
"""
, "codegen": { "renameErrors": false }
""".trimIndent(),
imports = listOf("$commonModels/naming-obstacle-course-ops.smithy"),
),
CodegenTest(
"naming_obs_structs#NamingObstacleCourseStructs",
"naming_test_structs",
"""
, "codegen": { "renameErrors": false }
""".trimIndent(),
imports = listOf("$commonModels/naming-obstacle-course-structs.smithy"),
),
CodegenTest("com.aws.example#PokemonService", "pokemon-service-client", imports = listOf("$commonModels/pokemon.smithy")),
)
}

project.registerGenerateSmithyBuildTask(rootProject, pluginName, allCodegenTests)
project.registerGenerateCargoWorkspaceTask(rootProject, pluginName, allCodegenTests, workingDirUnderBuildDir)
project.registerGenerateCargoConfigTomlTask(buildDir.resolve(workingDirUnderBuildDir))

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

project.registerModifyMtimeTask()
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir), defaultRustDocFlags)

tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })

tasks["clean"].doFirst { delete("smithy-build.json") }
109 changes: 109 additions & 0 deletions codegen-client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import org.gradle.api.tasks.testing.logging.TestExceptionFormat

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
jacoco
`maven-publish`
}

description = "Generates Rust client code from Smithy models"
extra["displayName"] = "Smithy :: Rust :: CodegenClient"
extra["moduleName"] = "software.amazon.smithy.rust.codegen.client"

group = "software.amazon.smithy.rust.codegen"
version = "0.1.0"

val smithyVersion: String by project
val kotestVersion: String by project

dependencies {
implementation(project(":codegen-core"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.jsoup:jsoup:1.14.3")
api("software.amazon.smithy:smithy-codegen-core:$smithyVersion")
api("com.moandjiezana.toml:toml4j:0.7.2")
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-waiters:$smithyVersion")
runtimeOnly(project(":rust-runtime"))
testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
}

tasks.compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

tasks.compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}

// 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"
classifier = "sources"
from(sourceSets.getByName("main").allSource)
}

tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showExceptions = true
showStackTraces = true
showStandardStreams = true
}
}

tasks.dokka {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
}

// Always build documentation
tasks["build"].finalizedBy(tasks["dokka"])

// Configure jacoco (code coverage) to generate an HTML report
tasks.jacocoTestReport {
reports {
xml.isEnabled = false
csv.isEnabled = false
html.destination = file("$buildDir/reports/jacoco")
}
}

// Always run the jacoco test report after testing.
tasks["test"].finalizedBy(tasks["jacocoTestReport"])

publishing {
publications {
create<MavenPublication>("default") {
from(components["java"])
artifact(sourcesJar)
}
}
repositories { maven { url = uri("$buildDir/repository") } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.core.Version
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.CratesIo
import software.amazon.smithy.rust.codegen.rustlang.DependencyLocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
package software.amazon.smithy.rust.codegen.smithy.generators

import com.moandjiezana.toml.TomlWriter
import software.amazon.smithy.rust.codegen.core.Version
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.rustlang.Feature
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.smithy.CoreRustSettings
import software.amazon.smithy.rust.codegen.smithy.Version
import software.amazon.smithy.rust.codegen.util.deepMergeWith

/**
Expand Down
Loading