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

Break codegen-server's dependency on codegen-client #2105

Merged
merged 21 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
53e25af
Move the allow lints customization into `codegen-core`
jdisanti Dec 14, 2022
ed84f25
Move the crate version customization into `codegen-core`
jdisanti Dec 14, 2022
bc804ce
Move "pub use" extra into `codegen-core`
jdisanti Dec 14, 2022
46494d4
Move `EventStreamSymbolProvider` into `codegen-core`
jdisanti Dec 14, 2022
40f876a
Move the streaming shape providers into `codegen-core`
jdisanti Dec 14, 2022
608f1c4
Refactor event stream marshall/unmarshall tests
jdisanti Dec 15, 2022
69cdfc8
Break `codegen-server` dependency on `codegen-client`
jdisanti Dec 15, 2022
b8b6ed5
Split up `EventStreamTestTools`
jdisanti Dec 17, 2022
d93346e
Move codegen context creation in event stream tests
jdisanti Dec 17, 2022
52899f9
Restructure tests so that #1442 is easier to resolve in the future
jdisanti Dec 17, 2022
5f7bc7e
Fix comments in `SmithyTypesPubUseExtra`
jdisanti Dec 17, 2022
2dd9881
Use pair instead of list
jdisanti Dec 17, 2022
2659182
Merge remote-tracking branch 'origin/main' into jdisanti-break-client…
jdisanti Dec 19, 2022
be77fa0
Simplify base event stream test requirements
jdisanti Dec 20, 2022
c608a77
Explode on unrecognized shape types in event stream test tools
jdisanti Dec 20, 2022
5c73370
Add client/server prefixes to test classes
jdisanti Dec 20, 2022
a47597f
Improve TODO comments in server event stream tests
jdisanti Dec 20, 2022
0b77d8f
Use correct builders for `ServerEventStreamMarshallerGeneratorTest`
jdisanti Dec 20, 2022
c898100
Merge remote-tracking branch 'origin/main' into jdisanti-break-client…
jdisanti Dec 20, 2022
38598f2
Fix shape check in event stream test tools
jdisanti Dec 20, 2022
80ed7a9
Remove test cases for protocols that don't support event streams
jdisanti Dec 20, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.Non
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider
import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
import java.util.logging.Level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ package software.amazon.smithy.rust.codegen.client.smithy.customize

import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.customizations.AllowLintsGenerator
import software.amazon.smithy.rust.codegen.client.smithy.customizations.CrateVersionGenerator
import software.amazon.smithy.rust.codegen.client.smithy.customizations.EndpointPrefixGenerator
import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpChecksumRequiredGenerator
import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpVersionListCustomization
import software.amazon.smithy.rust.codegen.client.smithy.customizations.IdempotencyTokenGenerator
import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization
import software.amazon.smithy.rust.codegen.client.smithy.customizations.pubUseSmithyTypes
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.core.rustlang.Feature
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.customizations.AllowLintsCustomization
import software.amazon.smithy.rust.codegen.core.smithy.customizations.CrateVersionCustomization
import software.amazon.smithy.rust.codegen.core.smithy.customizations.pubUseSmithyTypes
import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization

Expand Down Expand Up @@ -52,8 +52,7 @@ class RequiredCustomizations : ClientCodegenDecorator {
codegenContext: ClientCodegenContext,
baseCustomizations: List<LibRsCustomization>,
): List<LibRsCustomization> =
baseCustomizations + CrateVersionGenerator() +
AllowLintsGenerator()
baseCustomizations + CrateVersionCustomization() + AllowLintsCustomization()

override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
// Add rt-tokio feature for `ByteStream::from_path`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor
import software.amazon.smithy.rust.codegen.core.smithy.rustType
import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.protocols.eventstream

import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.testutil.clientTestRustSettings
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator
import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestModels
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestRequirements
import java.util.stream.Stream

class TestCasesProvider : ArgumentsProvider {
override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> =
EventStreamTestModels.TEST_CASES.map { Arguments.of(it) }.stream()
}

abstract class ClientEventStreamBaseRequirements : EventStreamTestRequirements<ClientCodegenContext> {
Velfi marked this conversation as resolved.
Show resolved Hide resolved
override fun createCodegenContext(
model: Model,
serviceShape: ServiceShape,
protocolShapeId: ShapeId,
codegenTarget: CodegenTarget,
): ClientCodegenContext = ClientCodegenContext(
model,
testSymbolProvider(model),
serviceShape,
protocolShapeId,
clientTestRustSettings(),
CombinedClientCodegenDecorator(emptyList()),
)

override fun renderBuilderForShape(
writer: RustWriter,
codegenContext: ClientCodegenContext,
shape: StructureShape,
) {
BuilderGenerator(codegenContext.model, codegenContext.symbolProvider, shape).apply {
render(writer)
writer.implBlock(shape, codegenContext.symbolProvider) {
renderConvenienceMethod(writer)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.protocols.eventstream

import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ArgumentsSource
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.EventStreamMarshallerGenerator
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestModels
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestTools
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestVariety
import software.amazon.smithy.rust.codegen.core.testutil.TestEventStreamProject
import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig

class ClientEventStreamMarshallerGeneratorTest {
@ParameterizedTest
@ArgumentsSource(TestCasesProvider::class)
fun test(testCase: EventStreamTestModels.TestCase) {
EventStreamTestTools.runTestCase(
testCase,
object : ClientEventStreamBaseRequirements() {
override fun renderGenerator(
codegenContext: ClientCodegenContext,
project: TestEventStreamProject,
protocol: Protocol,
): RuntimeType = EventStreamMarshallerGenerator(
project.model,
CodegenTarget.CLIENT,
TestRuntimeConfig,
project.symbolProvider,
project.streamShape,
protocol.structuredDataSerializer(project.operationShape),
testCase.requestContentType,
).render()
},
CodegenTarget.CLIENT,
EventStreamTestVariety.Marshall,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.protocols.eventstream

import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ArgumentsSource
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol
import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol
import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.EventStreamUnmarshallerGenerator
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestModels
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestTools
import software.amazon.smithy.rust.codegen.core.testutil.EventStreamTestVariety
import software.amazon.smithy.rust.codegen.core.testutil.TestEventStreamProject

class ClientEventStreamUnmarshallerGeneratorTest {
@ParameterizedTest
@ArgumentsSource(TestCasesProvider::class)
fun test(testCase: EventStreamTestModels.TestCase) {
EventStreamTestTools.runTestCase(
testCase,
object : ClientEventStreamBaseRequirements() {
override fun renderGenerator(
codegenContext: ClientCodegenContext,
project: TestEventStreamProject,
protocol: Protocol,
): RuntimeType {
fun builderSymbol(shape: StructureShape): Symbol = shape.builderSymbol(codegenContext.symbolProvider)
return EventStreamUnmarshallerGenerator(
protocol,
codegenContext,
project.operationShape,
project.streamShape,
::builderSymbol,
).render()
}
},
CodegenTarget.CLIENT,
EventStreamTestVariety.Unmarshall,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy
package software.amazon.smithy.rust.codegen.core.smithy

import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.Model
Expand All @@ -14,13 +14,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
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.rustlang.stripOuter
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol
import software.amazon.smithy.rust.codegen.core.smithy.rustType
import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait
import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait
import software.amazon.smithy.rust.codegen.core.smithy.transformers.eventStreamErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy
package software.amazon.smithy.rust.codegen.core.smithy

import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.Model
Expand All @@ -14,13 +14,6 @@ import software.amazon.smithy.model.shapes.StringShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.shapes.UnionShape
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.core.smithy.Default
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.SymbolMetadataProvider
import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata
import software.amazon.smithy.rust.codegen.core.smithy.setDefault
import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait
import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait
import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.customizations
package software.amazon.smithy.rust.codegen.core.smithy.customizations

import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection

val AllowedRustcLints = listOf(
private val allowedRustcLints = listOf(
// Deprecated items should be safe to compile, so don't block the compilation.
"deprecated",
)

val AllowedClippyLints = listOf(
private val allowedClippyLints = listOf(
// Sometimes operations are named the same as our module e.g. output leading to `output::output`.
"module_inception",

Expand Down Expand Up @@ -54,16 +54,16 @@ val AllowedClippyLints = listOf(
// "result_large_err",
)

val AllowedRustdocLints = listOf(
private val allowedRustdocLints = listOf(
// Rust >=1.53.0 requires links to be wrapped in `<link>`. This is extremely hard to enforce for
// docs that come from the modeled documentation, so we need to disable this lint
"bare_urls",
)

class AllowLintsGenerator(
private val rustcLints: List<String> = AllowedRustcLints,
private val clippyLints: List<String> = AllowedClippyLints,
private val rustdocLints: List<String> = AllowedRustdocLints,
class AllowLintsCustomization(
private val rustcLints: List<String> = allowedRustcLints,
private val clippyLints: List<String> = allowedClippyLints,
private val rustdocLints: List<String> = allowedRustdocLints,
) : LibRsCustomization() {
override fun section(section: LibRsSection) = when (section) {
is LibRsSection.Attributes -> writable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.customizations
package software.amazon.smithy.rust.codegen.core.smithy.customizations

import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.writable
Expand All @@ -13,7 +13,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
/**
* Add `PGK_VERSION` const in lib.rs to enable knowing the version of the current module
*/
class CrateVersionGenerator : LibRsCustomization() {
class CrateVersionCustomization : LibRsCustomization() {
Velfi marked this conversation as resolved.
Show resolved Hide resolved
override fun section(section: LibRsSection) =
writable {
if (section is LibRsSection.Body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.customizations
package software.amazon.smithy.rust.codegen.core.smithy.customizations

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.rustlang.rust
Expand All @@ -30,23 +31,19 @@ private fun hasStreamingOperations(model: Model): Boolean {
}
}

/** Returns true if the model has any blob shapes or members */
private fun hasBlobs(model: Model): Boolean {
return model.structureShapes.any { structure ->
structure.members().any { member -> model.expectShape(member.target).isBlobShape }
// TODO(https://github.com/awslabs/smithy-rs/issues/2111): Fix this logic to consider collection/map shapes
private fun structUnionMembersMatchPredicate(model: Model, predicate: (Shape) -> Boolean): Boolean =
model.structureShapes.any { structure ->
structure.members().any { member -> predicate(model.expectShape(member.target)) }
} || model.unionShapes.any { union ->
union.members().any { member -> model.expectShape(member.target).isBlobShape }
union.members().any { member -> predicate(model.expectShape(member.target)) }
}
}

/** Returns true if the model has any timestamp shapes or members */
private fun hasDateTimes(model: Model): Boolean {
return model.structureShapes.any { structure ->
structure.members().any { member -> model.expectShape(member.target).isTimestampShape }
} || model.unionShapes.any { union ->
union.members().any { member -> model.expectShape(member.target).isTimestampShape }
}
}
/** Returns true if the model uses any blob shapes */
private fun hasBlobs(model: Model): Boolean = structUnionMembersMatchPredicate(model, Shape::isBlobShape)

/** Returns true if the model uses any timestamp shapes */
private fun hasDateTimes(model: Model): Boolean = structUnionMembersMatchPredicate(model, Shape::isTimestampShape)

/** Returns a list of types that should be re-exported for the given model */
internal fun pubUseTypes(runtimeConfig: RuntimeConfig, model: Model): List<RuntimeType> {
Expand Down
Loading