From ce22621f1064a07c247dbdfc2d0190c5ce2b6f63 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 3 Oct 2022 12:38:25 +0100 Subject: [PATCH 1/7] Mark `operation_handler` module as private in the generated server code since it does not contain any public type. Tune the visibility of the 'operation' module based on the rendering context --- .../generators/client/CustomizableOperationGenerator.kt | 3 ++- .../smithy/rust/codegen/core/rustlang/RustModule.kt | 8 +++++++- .../smithy/rust/codegen/core/smithy/CodegenDelegator.kt | 1 - .../server/smithy/generators/ServerServiceGenerator.kt | 5 ++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index d3d43563fd..51e6db8c72 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg 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.asType import software.amazon.smithy.rust.codegen.core.rustlang.docs import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -34,7 +35,7 @@ class CustomizableOperationGenerator( private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() fun render(crate: RustCrate) { - crate.withModule(RustModule.Operation) { writer -> + crate.withModule(RustModule.operationModule(Visibility.PUBLIC)) { writer -> writer.docs("Operation customization and supporting types") writer.rust("pub mod customize;") } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index 0ec62243d1..c34a44a9ef 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -25,6 +25,12 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata, val docu val Config = public("config", documentation = "Configuration for the service.") val Error = public("error", documentation = "All error types that operations can return.") - val Operation = public("operation", documentation = "All operations that this crate can perform.") + + /** + * Helper method to generate the `operation` Rust module. + * Its visibility depends on the generation context (client or server). + */ + fun operationModule(visibility: Visibility): RustModule = + default("operation", visibility = visibility, documentation = "All operations that this crate can perform.") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt index 53473cb671..692e156f7e 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt @@ -175,7 +175,6 @@ open class RustCrate( */ val DefaultPublicModules = setOf( RustModule.Error, - RustModule.Operation, RustModule.public("model", documentation = "Data structures used by operation inputs/outputs."), RustModule.public("input", documentation = "Input structures for operations."), RustModule.public("output", documentation = "Output structures for operations."), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index a9670d013b..993a436e8f 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -13,7 +13,6 @@ 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.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -41,7 +40,7 @@ open class ServerServiceGenerator( * which assigns a symbol location to each shape. */ fun render() { - rustCrate.withModule(DefaultPublicModules["operation"]!!) { writer -> + rustCrate.withModule(RustModule.operationModule(Visibility.PRIVATE)) { writer -> ServerProtocolTestGenerator(codegenContext, protocolSupport, protocolGenerator).render(writer) } @@ -52,7 +51,7 @@ open class ServerServiceGenerator( } } } - rustCrate.withModule(RustModule.public("operation_handler", "Operation handlers definition and implementation.")) { writer -> + rustCrate.withModule(RustModule.private("operation_handler", "Operation handlers definition and implementation.")) { writer -> renderOperationHandler(writer, operations) } rustCrate.withModule( From 17d87fb91cb60ec7e795128e8f2a3693a73df769 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 3 Oct 2022 13:18:11 +0100 Subject: [PATCH 2/7] Add changelog.next entry. --- CHANGELOG.next.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 4129e44710..18d9fa6ff1 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -10,6 +10,16 @@ # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} # author = "rcoh" + +[[smithy-rs]] +message = """ +Mark `operation` and `operation_handler` modules as private in the generated server crate. +Both modules did not contain any public types, therefore there should be no actual breakage when updating. +""" +references = ["smithy-rs#1803"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server"} +author = "LukeMathWalker" + [[smithy-rs]] message = "Pokémon Service example code now runs clippy during build." references = ["smithy-rs#1727"] From afafbcc3379f487e1f7f6b082b8e8b84abff58a4 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 3 Oct 2022 14:17:34 +0100 Subject: [PATCH 3/7] Rename `operationModule` to `operation`. --- .../smithy/generators/client/CustomizableOperationGenerator.kt | 2 +- .../amazon/smithy/rust/codegen/core/rustlang/RustModule.kt | 2 +- .../codegen/server/smithy/generators/ServerServiceGenerator.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index 51e6db8c72..f954f79496 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -35,7 +35,7 @@ class CustomizableOperationGenerator( private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() fun render(crate: RustCrate) { - crate.withModule(RustModule.operationModule(Visibility.PUBLIC)) { writer -> + crate.withModule(RustModule.operation(Visibility.PUBLIC)) { writer -> writer.docs("Operation customization and supporting types") writer.rust("pub mod customize;") } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index c34a44a9ef..56acbfed63 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -30,7 +30,7 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata, val docu * Helper method to generate the `operation` Rust module. * Its visibility depends on the generation context (client or server). */ - fun operationModule(visibility: Visibility): RustModule = + fun operation(visibility: Visibility): RustModule = default("operation", visibility = visibility, documentation = "All operations that this crate can perform.") } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index 993a436e8f..1b987f0f59 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -40,7 +40,7 @@ open class ServerServiceGenerator( * which assigns a symbol location to each shape. */ fun render() { - rustCrate.withModule(RustModule.operationModule(Visibility.PRIVATE)) { writer -> + rustCrate.withModule(RustModule.operation(Visibility.PRIVATE)) { writer -> ServerProtocolTestGenerator(codegenContext, protocolSupport, protocolGenerator).render(writer) } From 3e5a56c0cbce7b03b25bdca29052b5adec6c9d02 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 3 Oct 2022 14:39:26 +0100 Subject: [PATCH 4/7] Ensure that `operation` is added to the list of public modules for the generated client. --- .../smithy/rust/codegen/client/smithy/CodegenVisitor.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt index 0e66b6ba3d..5b53508f70 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt @@ -23,6 +23,8 @@ 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.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider @@ -81,10 +83,12 @@ class CodegenVisitor( symbolProvider = RustCodegenPlugin.baseSymbolProvider(model, service, symbolVisitorConfig) codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings) + val publicModules = DefaultPublicModules.toMutableMap() + publicModules["operation"] = RustModule.operation(Visibility.PUBLIC) rustCrate = RustCrate( context.fileManifest, symbolProvider, - DefaultPublicModules, + publicModules, codegenContext.settings.codegenConfig, ) protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) From 8f1b0a8d812e71b9c88d2863e69785560e5fb08f Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 4 Oct 2022 14:28:55 +0100 Subject: [PATCH 5/7] Remove DefaultModules from codegen-core --- .../rust/codegen/client/smithy/CodegenVisitor.kt | 14 ++++++++++---- .../rust/codegen/core/rustlang/RustModule.kt | 4 ++++ .../rust/codegen/core/smithy/CodegenDelegator.kt | 11 ----------- .../smithy/rust/codegen/core/testutil/Rust.kt | 15 +++++++++++++-- .../codegen/server/smithy/ServerCodegenVisitor.kt | 11 +++++++++-- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt index 5b53508f70..f7c68c6583 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt @@ -25,7 +25,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.transformers.AddErrorMe 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.smithy.DefaultPublicModules 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 @@ -83,12 +82,19 @@ class CodegenVisitor( symbolProvider = RustCodegenPlugin.baseSymbolProvider(model, service, symbolVisitorConfig) codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings) - val publicModules = DefaultPublicModules.toMutableMap() - publicModules["operation"] = RustModule.operation(Visibility.PUBLIC) + + val clientPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, + RustModule.operation(Visibility.PUBLIC), + ).associateBy { it.name } rustCrate = RustCrate( context.fileManifest, symbolProvider, - publicModules, + clientPublicModules, codegenContext.settings.codegenConfig, ) protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index 56acbfed63..8cfbcb206c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -23,8 +23,12 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata, val docu fun private(name: String, documentation: String? = null): RustModule = default(name, visibility = Visibility.PRIVATE, documentation = documentation) + /* Common modules used across client, server and tests */ val Config = public("config", documentation = "Configuration for the service.") val Error = public("error", documentation = "All error types that operations can return.") + val Model = public("model", documentation = "Data structures used by operation inputs/outputs.") + val Input = public("input", documentation = "Input structures for operations.") + val Output = public("output", documentation = "Output structures for operations.") /** * Helper method to generate the `operation` Rust module. diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt index 692e156f7e..32ba37f3d3 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt @@ -170,17 +170,6 @@ open class RustCrate( } } -/** - * Allowlist of modules that will be exposed publicly in generated crates - */ -val DefaultPublicModules = setOf( - RustModule.Error, - RustModule.public("model", documentation = "Data structures used by operation inputs/outputs."), - RustModule.public("input", documentation = "Input structures for operations."), - RustModule.public("output", documentation = "Output structures for operations."), - RustModule.Config, -).associateBy { it.name } - /** * Finalize all the writers by: * - inlining inline dependencies that have been used diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 328eb4e134..96eade88ec 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -18,11 +18,11 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency 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.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustCrate @@ -199,7 +199,18 @@ class TestWriterDelegator( symbolProvider: RustSymbolProvider, val codegenConfig: CoreCodegenConfig, ) : - RustCrate(fileManifest, symbolProvider, DefaultPublicModules, codegenConfig) { + RustCrate( + fileManifest, + symbolProvider, + setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, + ).associateBy { it.name }, + codegenConfig, + ) { val baseDir: Path = fileManifest.baseDir fun generatedFiles(): List = fileManifest.files.toList().sorted() diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 1735a81bfd..651017d4c2 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -18,9 +18,9 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules 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 @@ -92,7 +92,14 @@ open class ServerCodegenVisitor( settings, ) - rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultPublicModules, settings.codegenConfig) + val serverPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, + ).associateBy { it.name } + rustCrate = RustCrate(context.fileManifest, symbolProvider, serverPublicModules, settings.codegenConfig) protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) } From 91533fe1be858ef8c439ca08f72a9c33b771edfb Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 4 Oct 2022 15:38:25 +0100 Subject: [PATCH 6/7] Fix Python server. --- .../python/smithy/PythonServerCodegenVisitor.kt | 4 ++-- .../server/smithy/ServerCodegenVisitor.kt | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index 6f824ef1f8..c4e07d60d9 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -16,7 +16,6 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator @@ -25,6 +24,7 @@ import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerEnumGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerServiceGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerStructureGenerator +import software.amazon.smithy.rust.codegen.server.smithy.DefaultServerPublicModules import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -69,7 +69,7 @@ class PythonServerCodegenVisitor( codegenContext = ServerCodegenContext(model, symbolProvider, service, protocol, settings) // Override `rustCrate` which carries the symbolProvider. - rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultPublicModules, settings.codegenConfig) + rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultServerPublicModules, settings.codegenConfig) // Override `protocolGenerator` which carries the symbolProvider. protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 651017d4c2..db93c5cfff 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -42,6 +42,14 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader import java.util.logging.Logger +val DefaultServerPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, +).associateBy { it.name } + /** * Entrypoint for server-side code generation. This class will walk the in-memory model and * generate all the needed types by calling the accept() function on the available shapes. @@ -92,14 +100,7 @@ open class ServerCodegenVisitor( settings, ) - val serverPublicModules = setOf( - RustModule.Error, - RustModule.Model, - RustModule.Input, - RustModule.Output, - RustModule.Config, - ).associateBy { it.name } - rustCrate = RustCrate(context.fileManifest, symbolProvider, serverPublicModules, settings.codegenConfig) + rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultServerPublicModules, settings.codegenConfig) protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) } From a98d41e40e7b570db23b0cde2030696179cbc114 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 4 Oct 2022 16:04:55 +0100 Subject: [PATCH 7/7] Expose TestDefaultPublicModules. --- .../smithy/rust/codegen/core/testutil/Rust.kt | 16 +++++++++------- .../error/TopLevelErrorGeneratorTest.kt | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 96eade88ec..b45b014c0e 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -189,6 +189,14 @@ fun RustWriter.unitTest( return rustBlock("fn $name()", *args, block = block) } +val DefaultTestPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, +).associateBy { it.name } + /** * WriterDelegator used for test purposes * @@ -202,13 +210,7 @@ class TestWriterDelegator( RustCrate( fileManifest, symbolProvider, - setOf( - RustModule.Error, - RustModule.Model, - RustModule.Input, - RustModule.Output, - RustModule.Config, - ).associateBy { it.name }, + DefaultTestPublicModules, codegenConfig, ) { val baseDir: Path = fileManifest.baseDir diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt index d4b6d5efa9..b17e48cd92 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt @@ -13,9 +13,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.testutil.DefaultTestPublicModules import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider @@ -75,7 +75,7 @@ internal class TopLevelErrorGeneratorTest { val rustCrate = RustCrate( pluginContext.fileManifest, symbolProvider, - DefaultPublicModules, + DefaultTestPublicModules, codegenContext.settings.codegenConfig, )