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

Do not generate public empty modules #1803

Merged
merged 8 commits into from
Oct 4, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
LukeMathWalker marked this conversation as resolved.
Show resolved Hide resolved
default("operation", visibility = visibility, documentation = "All operations that this crate can perform.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ open class RustCrate(
*/
val DefaultPublicModules = setOf(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a better approach is to move DefaultPublicModules into the client and server modules, since it doesn't seem like there's a good reason to share it in codegen-core. This would also allow us to tailor the module docs to the client/servers separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In 8f1b0a8 I removed DefaultPublicModules and gave client/server/test the responsibility to handle their own list of default public modules.
I haven't inlined the definitions of the various module in those lists, but happy to do so if you think that's useful at this stage.

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."),
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.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
Expand Down Expand Up @@ -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)
}

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