Skip to content

Commit

Permalink
Merge branch 'main' into 1860
Browse files Browse the repository at this point in the history
  • Loading branch information
82marbag authored and Daniele Ahmed committed Nov 29, 2022
2 parents 684d2af + 9a4c1f3 commit 7fd9538
Show file tree
Hide file tree
Showing 108 changed files with 3,186 additions and 1,007 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ message = """
* The `length` trait on `string` shapes.
* The `length` trait on `map` shapes.
* The `range` trait on `integer` shapes.
* The `pattern` trait on `string` shapes.
Upon receiving a request that violates the modeled constraints, the server SDK will reject it with a message indicating why.
Unsupported (constraint trait, target shape) combinations will now fail at code generation time, whereas previously they were just ignored. This is a breaking change to raise awareness in service owners of their server SDKs behaving differently than what was modeled. To continue generating a server SDK with unsupported constraint traits, set `codegenConfig.ignoreUnsupportedConstraints` to `true` in your `smithy-build.json`.
"""
references = ["smithy-rs#1199", "smithy-rs#1342", "smithy-rs#1401"]
references = ["smithy-rs#1199", "smithy-rs#1342", "smithy-rs#1401", "smithy-rs#2005", "smithy-rs#1998"]
meta = { "breaking" = true, "tada" = true, "bug" = false, "target" = "server" }
author = "david-perez"

Expand Down Expand Up @@ -478,3 +480,9 @@ x-amzn-errortype: com.example.service#InvalidRequestException
references = ["smithy-rs#1982"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" }
author = "david-perez"

[[smithy-rs]]
message = "Make generated enum `values()` functions callable in const contexts."
references = ["smithy-rs#2011"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
author = "lsr0"
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator<ClientProtocolGenerator, C
),
retryClassifier = runtimeConfig.awsHttp().toType().member("retry::AwsResponseRetryClassifier"),
).render(rustCrate)
rustCrate.withNonRootModule(CustomizableOperationGenerator.CUSTOMIZE_MODULE) {
rustCrate.withModule(CustomizableOperationGenerator.CustomizeModule) {
renderCustomizableOperationSendMethod(runtimeConfig, generics, this)
}
rustCrate.withModule(FluentClientGenerator.clientModule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility

object InlineAwsDependency {
fun forRustFile(file: String, visibility: Visibility = Visibility.PRIVATE, vararg additionalDependency: RustDependency): InlineDependency =
InlineDependency.Companion.forRustFile(file, "aws-inlineable", visibility, *additionalDependency)
InlineDependency.Companion.forRustFile(RustModule.new(file, visibility), "/aws-inlineable/src/$file.rs", *additionalDependency)
}
14 changes: 11 additions & 3 deletions aws/sdk/integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Handwritten Integration Test Root

This folder contains hand-written integration tests that are specific to
This folder contains handwritten integration tests that are specific to
individual services. In order for your test to be merged into the final artifact:

- The crate name must match the generated crate name, e.g. `kms`, `dynamodb`
Expand All @@ -13,8 +13,8 @@ tests & inserted into the `tests` folder of the final generated service crate.

Some integration test roots have a `benches/` directory. In these, `cargo bench` can be
invoked to run the benchmarks against the current version of smithy-rs. To compare
across smithy-rs versions, you can use git to checkout the version to compare against,
run the benchmark, and then checkout the other version and run it again:
across smithy-rs versions, you can `git checkout` the version to compare against,
run the benchmark, and then `git checkout` the other version and run it again:

```bash
# For example, this was the very first commit that had a benchmark
Expand Down Expand Up @@ -42,3 +42,11 @@ cargo bench

# Compare!
```

## Adding dependencies to tests

When adding new dependencies or adding new features to old dependencies, don't forget to update the
[`IntegrationTestDependencies` file][IntegrationTestDependencies]. Otherwise, after your tests have been copied into
their respective SDK crates may fail when run due to a dependency resolution error.

[IntegrationTestDependencies]: ../../sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ hyper = "0.14.12"
serde_json = "1"
smol = "1.2"
tempfile = "3"
tokio = { version = "1.8.4", features = ["full", "test-util"] }
tokio = { version = "1.8.4", features = ["macros", "test-util", "rt-multi-thread"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientProtocolLoader
import software.amazon.smithy.rust.codegen.client.smithy.transformers.AddErrorMessage
import software.amazon.smithy.rust.codegen.client.smithy.transformers.RemoveEventStreamOperations
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
Expand Down Expand Up @@ -83,19 +80,9 @@ class CodegenVisitor(

codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings, codegenDecorator)

val clientPublicModules = setOf(
RustModule.Error,
RustModule.Model,
RustModule.Input,
RustModule.Output,
RustModule.Config,
RustModule.Types,
RustModule.operation(Visibility.PUBLIC),
).associateBy { it.name }
rustCrate = RustCrate(
context.fileManifest,
symbolProvider,
clientPublicModules,
codegenContext.settings.codegenConfig,
)
protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators

import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
Expand All @@ -24,7 +22,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.lensName

/** Generator for accessing nested fields through optional values **/
class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) {
private val module = RustModule("lens", RustMetadata(visibility = Visibility.PUBLIC), "Generated accessors for nested fields")
private val module = RustModule.private("lens", "Generated accessors for nested fields")

/**
* Generate an accessor on [root] that consumes [root] and returns an `Option<T>` for the nested item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import software.amazon.smithy.model.traits.IdempotencyTokenTrait
import software.amazon.smithy.model.traits.PaginatedTrait
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.render
import software.amazon.smithy.rust.codegen.core.rustlang.rust
Expand Down Expand Up @@ -78,11 +76,7 @@ class PaginatorGenerator private constructor(
private val idx = PaginatedIndex.of(model)
private val paginationInfo =
idx.getPaginationInfo(service, operation).orNull() ?: PANIC("failed to load pagination info")
private val module = RustModule(
"paginator",
RustMetadata(visibility = Visibility.PUBLIC),
documentation = "Paginators for the service",
)
private val module = RustModule.public("paginator", "Paginators for the service")

private val inputType = symbolProvider.toSymbol(operation.inputShape(model))
private val outputShape = operation.outputShape(model)
Expand All @@ -99,7 +93,12 @@ class PaginatorGenerator private constructor(
"generics" to generics.decl,
"bounds" to generics.bounds,
"page_size_setter" to pageSizeSetter(),
"send_bounds" to generics.sendBounds(symbolProvider.toSymbol(operation), outputType, errorType, retryClassifier),
"send_bounds" to generics.sendBounds(
symbolProvider.toSymbol(operation),
outputType,
errorType,
retryClassifier,
),

// Operation Types
"operation" to symbolProvider.toSymbol(operation),
Expand Down Expand Up @@ -288,7 +287,8 @@ class PaginatorGenerator private constructor(
private fun pageSizeSetter() = writable {
paginationInfo.pageSizeMember.orNull()?.also {
val memberName = symbolProvider.toMemberName(it)
val pageSizeT = symbolProvider.toSymbol(it).rustType().stripOuter<RustType.Option>().render(true)
val pageSizeT =
symbolProvider.toSymbol(it).rustType().stripOuter<RustType.Option>().render(true)
rust(
"""
/// Set the page size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.docs
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
Expand All @@ -26,20 +24,16 @@ class CustomizableOperationGenerator(
private val generics: FluentClientGenerics,
private val includeFluentClient: Boolean,
) {

companion object {
const val CUSTOMIZE_MODULE = "crate::operation::customize"
val CustomizeModule = RustModule.public("customize", "Operation customization and supporting types", parent = RustModule.operation(Visibility.PUBLIC))
}

private val smithyHttp = CargoDependency.smithyHttp(runtimeConfig).toType()
private val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).toType()

fun render(crate: RustCrate) {
crate.withModule(RustModule.operation(Visibility.PUBLIC)) {
docs("Operation customization and supporting types")
rust("pub mod customize;")
}

crate.withNonRootModule(CUSTOMIZE_MODULE) {
crate.withModule(CustomizeModule) {
rustTemplate(
"""
pub use #{Operation};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.asArgumentType
import software.amazon.smithy.rust.codegen.core.rustlang.asOptional
import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape
Expand Down Expand Up @@ -220,7 +221,7 @@ class FluentClientGenerator(
)
}
}
writer.withModule(RustModule.public("fluent_builders")) {
writer.withInlineModule(RustModule.new("fluent_builders", visibility = Visibility.PUBLIC, inline = true)) {
docs(
"""
Utilities to ergonomically construct a request to the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ProtocolTestGenerator(
Attribute.Custom("allow(unreachable_code, unused_variables)"),
),
)
writer.withModule(RustModule(testModuleName, moduleMeta)) {
writer.withInlineModule(RustModule.LeafModule(testModuleName, moduleMeta, inline = true)) {
renderAllTestCases(allTests)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel

class SmithyTypesPubUseGeneratorTest {
private fun emptyModel() = modelWithMember()
private fun modelWithMember(
inputMember: String = "",
outputMember: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCusto
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext
import kotlin.io.path.createDirectory
import kotlin.io.path.writeText

class CodegenVisitorTest {
@Test
Expand Down Expand Up @@ -48,8 +46,6 @@ class CodegenVisitorTest {
}
""".asSmithyModel(smithyVersion = "2.0")
val (ctx, testDir) = generatePluginContext(model)
testDir.resolve("src").createDirectory()
testDir.resolve("src/main.rs").writeText("fn main() {}")
val codegenDecorator =
CombinedCodegenDecorator.fromClasspath(
ctx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import software.amazon.smithy.model.traits.SparseTrait
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.rustlang.render
import software.amazon.smithy.rust.codegen.core.smithy.Errors
import software.amazon.smithy.rust.codegen.core.smithy.Models
import software.amazon.smithy.rust.codegen.core.smithy.Operations
import software.amazon.smithy.rust.codegen.core.smithy.ErrorsModule
import software.amazon.smithy.rust.codegen.core.smithy.ModelsModule
import software.amazon.smithy.rust.codegen.core.smithy.OperationsModule
import software.amazon.smithy.rust.codegen.core.smithy.isOptional
import software.amazon.smithy.rust.codegen.core.smithy.rustType
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
Expand All @@ -57,7 +57,7 @@ class SymbolVisitorTest {
val provider: SymbolProvider = testSymbolProvider(model)
val sym = provider.toSymbol(struct)
sym.rustType().render(false) shouldBe "MyStruct"
sym.definitionFile shouldContain Models.filename
sym.definitionFile shouldContain ModelsModule.definitionFile()
sym.namespace shouldBe "crate::model"
}

Expand All @@ -77,7 +77,7 @@ class SymbolVisitorTest {
val provider: SymbolProvider = testSymbolProvider(model)
val sym = provider.toSymbol(struct)
sym.rustType().render(false) shouldBe "TerribleError"
sym.definitionFile shouldContain Errors.filename
sym.definitionFile shouldContain ErrorsModule.definitionFile()
}

@Test
Expand All @@ -101,7 +101,7 @@ class SymbolVisitorTest {
val provider: SymbolProvider = testSymbolProvider(model)
val sym = provider.toSymbol(shape)
sym.rustType().render(false) shouldBe "StandardUnit"
sym.definitionFile shouldContain Models.filename
sym.definitionFile shouldContain ModelsModule.definitionFile()
sym.namespace shouldBe "crate::model"
}

Expand Down Expand Up @@ -260,7 +260,7 @@ class SymbolVisitorTest {
}
""".asSmithyModel()
val symbol = testSymbolProvider(model).toSymbol(model.expectShape(ShapeId.from("smithy.example#PutObject")))
symbol.definitionFile shouldBe("src/${Operations.filename}")
symbol.definitionFile shouldBe(OperationsModule.definitionFile())
symbol.name shouldBe "PutObject"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import software.amazon.smithy.model.traits.EndpointTrait
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock
Expand Down Expand Up @@ -59,7 +58,7 @@ internal class EndpointTraitBindingsTest {
operationShape.expectTrait(EndpointTrait::class.java),
)
val project = TestWorkspace.testProject()
project.withModule(RustModule.default("test", visibility = Visibility.PRIVATE)) {
project.withModule(RustModule.private("test")) {
rust(
"""
struct GetStatusInput {
Expand Down
Loading

0 comments on commit 7fd9538

Please sign in to comment.