Skip to content

Commit 0226446

Browse files
authored
Rename Rust server codegen plugins (#2306)
Rename `RustCodegenServerPlugin` to `RustServerCodegenPlugin`, for consistency with `RustClientCodegenPlugin`. This is a better name, since the plugin is named `rust-server-codegen`. This commit also renames `PythonCodegenServerPlugin` to `RustServerCodegenPythonPlugin` for the same reasons. This commit also contains other drive-by improvements made while working on #2302.
1 parent 7fdb5c9 commit 0226446

File tree

15 files changed

+40
-44
lines changed

15 files changed

+40
-44
lines changed

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class RustClientCodegenPlugin : DecoratableBuildPlugin() {
6666
}
6767

6868
companion object {
69-
/** SymbolProvider
69+
/**
7070
* When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider
7171
*
72-
* The Symbol provider is composed of a base `SymbolVisitor` which handles the core functionality, then is layered
72+
* The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered
7373
* with other symbol providers, documented inline, to handle the full scope of Smithy types.
7474
*/
7575
fun baseSymbolProvider(model: Model, serviceShape: ServiceShape, symbolVisitorConfig: SymbolVisitorConfig) =

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ class RustWriter private constructor(
510510
* Callers must take care to use [this] when writing to ensure code is written to the right place:
511511
* ```kotlin
512512
* val writer = RustWriter.forModule("model")
513-
* writer.withModule(RustModule.public("nested")) {
513+
* writer.withInlineModule(RustModule.public("nested")) {
514514
* Generator(...).render(this) // GOOD
515515
* Generator(...).render(writer) // WRONG!
516516
* }

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/DirectedWalker.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ import java.util.function.Predicate
1919
class DirectedWalker(model: Model) {
2020
private val inner = Walker(model)
2121

22-
fun walkShapes(shape: Shape): Set<Shape> {
23-
return walkShapes(shape) { _ -> true }
24-
}
22+
fun walkShapes(shape: Shape): Set<Shape> = walkShapes(shape) { true }
2523

26-
fun walkShapes(shape: Shape, predicate: Predicate<Relationship>): Set<Shape> {
27-
return inner.walkShapes(shape) { rel -> predicate.test(rel) && rel.direction == RelationshipDirection.DIRECTED }
28-
}
24+
fun walkShapes(shape: Shape, predicate: Predicate<Relationship>): Set<Shape> =
25+
inner.walkShapes(shape) { rel -> predicate.test(rel) && rel.direction == RelationshipDirection.DIRECTED }
2926
}

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ fun generatePluginContext(
194194
)
195195
}
196196

197-
val settings = settingsBuilder.merge(additionalSettings)
198-
.build()
197+
val settings = settingsBuilder.merge(additionalSettings).build()
199198
val pluginContext = PluginContext.builder().model(model).fileManifest(manifest).settings(settings).build()
200199
return pluginContext to testPath
201200
}

codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class PythonServerCodegenVisitor(
7474
serviceShape: ServiceShape,
7575
symbolVisitorConfig: SymbolVisitorConfig,
7676
publicConstrainedTypes: Boolean,
77-
) = PythonCodegenServerPlugin.baseSymbolProvider(model, serviceShape, symbolVisitorConfig, publicConstrainedTypes)
77+
) = RustServerCodegenPythonPlugin.baseSymbolProvider(model, serviceShape, symbolVisitorConfig, publicConstrainedTypes)
7878

7979
val serverSymbolProviders = ServerSymbolProviders.from(
8080
model,
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolP
1414
import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider
1515
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
1616
import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider
17-
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor
1817
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
1918
import software.amazon.smithy.rust.codegen.server.python.smithy.customizations.DECORATORS
2019
import software.amazon.smithy.rust.codegen.server.smithy.ConstrainedShapeSymbolMetadataProvider
@@ -26,16 +25,20 @@ import java.util.logging.Level
2625
import java.util.logging.Logger
2726

2827
/**
29-
* Rust with Python bindings Codegen Plugin.
28+
* Rust Server with Python bindings Codegen Plugin.
29+
*
3030
* This is the entrypoint for code generation, triggered by the smithy-build plugin.
3131
* `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which
3232
* enables the smithy-build plugin to invoke `execute` with all of the Smithy plugin context + models.
3333
*/
34-
class PythonCodegenServerPlugin : SmithyBuildPlugin {
34+
class RustServerCodegenPythonPlugin : SmithyBuildPlugin {
3535
private val logger = Logger.getLogger(javaClass.name)
3636

3737
override fun getName(): String = "rust-server-codegen-python"
3838

39+
/**
40+
* See [software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin].
41+
*/
3942
override fun execute(context: PluginContext) {
4043
// Suppress extremely noisy logs about reserved words
4144
Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF
@@ -57,10 +60,7 @@ class PythonCodegenServerPlugin : SmithyBuildPlugin {
5760

5861
companion object {
5962
/**
60-
* When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider
61-
*
62-
* The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered
63-
* with other symbol providers, documented inline, to handle the full scope of Smithy types.
63+
* See [software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin].
6464
*/
6565
fun baseSymbolProvider(
6666
model: Model,

codegen-server/python/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
# SPDX-License-Identifier: Apache-2.0
44
#
5-
software.amazon.smithy.rust.codegen.server.python.smithy.PythonCodegenServerPlugin
5+
software.amazon.smithy.rust.codegen.server.python.smithy.RustServerCodegenPythonPlugin
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,30 @@ import java.util.logging.Logger
3030
* `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which
3131
* enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models.
3232
*/
33-
class RustCodegenServerPlugin : SmithyBuildPlugin {
33+
class RustServerCodegenPlugin : SmithyBuildPlugin {
3434
private val logger = Logger.getLogger(javaClass.name)
3535

3636
override fun getName(): String = "rust-server-codegen"
3737

38-
override fun execute(context: PluginContext) {
39-
// Suppress extremely noisy logs about reserved words
38+
/**
39+
* See [software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin].
40+
*/
41+
override fun execute(
42+
context: PluginContext,
43+
) {
4044
Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF
41-
// Discover [RustCodegenDecorators] on the classpath. [RustCodegenDecorator] returns different types of
42-
// customizations. A customization is a function of:
43-
// - location (e.g. the mutate section of an operation)
44-
// - context (e.g. the of the operation)
45-
// - writer: The active RustWriter at the given location
46-
val codegenDecorator: CombinedServerCodegenDecorator =
47-
CombinedServerCodegenDecorator.fromClasspath(context, ServerRequiredCustomizations())
48-
49-
// ServerCodegenVisitor is the main driver of code generation that traverses the model and generates code
45+
val codegenDecorator =
46+
CombinedServerCodegenDecorator.fromClasspath(
47+
context,
48+
ServerRequiredCustomizations(),
49+
)
5050
logger.info("Loaded plugin to generate pure Rust bindings for the server SDK")
5151
ServerCodegenVisitor(context, codegenDecorator).execute()
5252
}
5353

5454
companion object {
5555
/**
56-
* When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider.
57-
*
58-
* The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered
59-
* with other symbol providers, documented inline, to handle the full scope of Smithy types.
56+
* See [software.amazon.smithy.rust.codegen.client.smithy.RustClientCodegenPlugin].
6057
*/
6158
fun baseSymbolProvider(
6259
model: Model,

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenContext.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
1313
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
1414

1515
/**
16-
* [ServerCodegenContext] contains code-generation context that is _specific_ to the [RustCodegenServerPlugin] plugin
16+
* [ServerCodegenContext] contains code-generation context that is _specific_ to the [RustServerCodegenPlugin] plugin
1717
* from the `rust-codegen-server` subproject.
1818
*
1919
* It inherits from [CodegenContext], which contains code-generation context that is common to _all_ smithy-rs plugins.

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ open class ServerCodegenVisitor(
129129
service,
130130
symbolVisitorConfig,
131131
settings.codegenConfig.publicConstrainedTypes,
132-
RustCodegenServerPlugin::baseSymbolProvider,
132+
RustServerCodegenPlugin::baseSymbolProvider,
133133
)
134134

135135
codegenContext = ServerCodegenContext(

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.util.Optional
2525
*/
2626

2727
/**
28-
* Settings used by [RustCodegenServerPlugin].
28+
* Settings used by [RustServerCodegenPlugin].
2929
*/
3030
data class ServerRustSettings(
3131
override val service: ShapeId,

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraints.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ data class ValidationResult(val shouldAbort: Boolean, val messages: List<LogMess
134134

135135
private val unsupportedConstraintsOnMemberShapes = allConstraintTraits - RequiredTrait::class.java
136136

137+
/**
138+
* Validate that all constrained operations have the shape [validationExceptionShapeId] shape attached to their errors.
139+
*/
137140
fun validateOperationsWithConstrainedInputHaveValidationExceptionAttached(
138141
model: Model,
139142
service: ServiceShape,

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customize/ServerCodegenDecorator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface ServerCodegenDecorator : CoreCodegenDecorator<ServerCodegenContext> {
2828
*
2929
* This makes the actual concrete codegen simpler by not needing to deal with multiple separate decorators.
3030
*/
31-
class CombinedServerCodegenDecorator(decorators: List<ServerCodegenDecorator>) :
31+
class CombinedServerCodegenDecorator(private val decorators: List<ServerCodegenDecorator>) :
3232
CombinedCoreCodegenDecorator<ServerCodegenContext, ServerCodegenDecorator>(decorators),
3333
ServerCodegenDecorator {
3434
override val name: String

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
1919
import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator
2020
import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock
2121
import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
22-
import software.amazon.smithy.rust.codegen.server.smithy.RustCodegenServerPlugin
22+
import software.amazon.smithy.rust.codegen.server.smithy.RustServerCodegenPlugin
2323
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenConfig
2424
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
2525
import software.amazon.smithy.rust.codegen.server.smithy.ServerRustSettings
@@ -53,7 +53,7 @@ fun serverTestSymbolProviders(
5353
(serviceShape ?: testServiceShapeFor(model)).id,
5454
)
5555
).codegenConfig.publicConstrainedTypes,
56-
RustCodegenServerPlugin::baseSymbolProvider,
56+
RustServerCodegenPlugin::baseSymbolProvider,
5757
)
5858

5959
fun serverTestRustSettings(
@@ -98,7 +98,7 @@ fun serverTestCodegenContext(
9898
service,
9999
ServerTestSymbolVisitorConfig,
100100
settings.codegenConfig.publicConstrainedTypes,
101-
RustCodegenServerPlugin::baseSymbolProvider,
101+
RustServerCodegenPlugin::baseSymbolProvider,
102102
)
103103

104104
return ServerCodegenContext(

codegen-server/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
# SPDX-License-Identifier: Apache-2.0
44
#
5-
software.amazon.smithy.rust.codegen.server.smithy.RustCodegenServerPlugin
5+
software.amazon.smithy.rust.codegen.server.smithy.RustServerCodegenPlugin

0 commit comments

Comments
 (0)