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

Remove enableNewCrateOrganizationScheme codegen flag #2507

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ author = "jdisanti"
message = "Streaming operations now emit the request ID at the `debug` log level like their non-streaming counterparts."
references = ["smithy-rs#2495"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
author = "jdisanti"
author = "jdisanti"

[[smithy-rs]]
message = "The `enableNewCrateOrganizationScheme` codegen flag has been removed. If you opted out of the new crate organization scheme, it must be adopted now in order to upgrade (see [the upgrade guidance](https://github.com/awslabs/smithy-rs/discussions/2449) from March 23rd's release)."
references = ["smithy-rs#2507"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.featureGatedCustomizeModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDocs
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator
Expand Down Expand Up @@ -97,12 +96,12 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
reexportSmithyClientBuilder = false,
generics = generics,
customizations = listOf(
AwsPresignedFluentBuilderMethod(codegenContext, runtimeConfig),
AwsPresignedFluentBuilderMethod(runtimeConfig),
AwsFluentClientDocs(codegenContext),
),
retryClassifier = AwsRuntimeType.awsHttp(runtimeConfig).resolve("retry::AwsResponseRetryClassifier"),
).render(rustCrate)
rustCrate.withModule(codegenContext.featureGatedCustomizeModule()) {
rustCrate.withModule(ClientRustModule.Client.customize) {
renderCustomizableOperationSendMethod(runtimeConfig, generics, this)
}
rustCrate.withModule(ClientRustModule.client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware
import software.amazon.smithy.rustsdk.traits.PresignableTrait
import kotlin.streams.toList

private val presigningTypes: List<Pair<String, Any>> = listOf(
"PresignedRequest" to AwsRuntimeType.presigning().resolve("PresignedRequest"),
"PresigningConfig" to AwsRuntimeType.presigning().resolve("PresigningConfig"),
)

internal enum class PayloadSigningType {
EMPTY,
UNSIGNED_PAYLOAD,
Expand Down Expand Up @@ -135,8 +140,8 @@ class AwsInputPresignedMethod(
private val symbolProvider = codegenContext.symbolProvider

private val codegenScope = (
presigningTypes(codegenContext) + listOf(
"PresignedRequestService" to AwsRuntimeType.presigning(codegenContext)
presigningTypes + listOf(
"PresignedRequestService" to AwsRuntimeType.presigning()
.resolve("service::PresignedRequestService"),
"SdkError" to RuntimeType.sdkError(runtimeConfig),
"aws_sigv4" to AwsRuntimeType.awsSigv4(runtimeConfig),
Expand Down Expand Up @@ -241,12 +246,11 @@ class AwsInputPresignedMethod(
}

class AwsPresignedFluentBuilderMethod(
codegenContext: ClientCodegenContext,
runtimeConfig: RuntimeConfig,
) : FluentClientCustomization() {
private val codegenScope = (
presigningTypes(codegenContext) + arrayOf(
"Error" to AwsRuntimeType.presigning(codegenContext).resolve("config::Error"),
presigningTypes + arrayOf(
"Error" to AwsRuntimeType.presigning().resolve("config::Error"),
"SdkError" to RuntimeType.sdkError(runtimeConfig),
)
).toTypedArray()
Expand Down Expand Up @@ -365,15 +369,3 @@ private fun RustWriter.documentPresignedMethod(hasConfigArg: Boolean) {
""",
)
}

private fun presigningTypes(codegenContext: ClientCodegenContext): List<Pair<String, Any>> =
when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) {
true -> listOf(
"PresignedRequest" to AwsRuntimeType.presigning(codegenContext).resolve("PresignedRequest"),
"PresigningConfig" to AwsRuntimeType.presigning(codegenContext).resolve("PresigningConfig"),
)
else -> listOf(
"PresignedRequest" to AwsRuntimeType.presigning(codegenContext).resolve("request::PresignedRequest"),
"PresigningConfig" to AwsRuntimeType.presigning(codegenContext).resolve("config::PresigningConfig"),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package software.amazon.smithy.rustsdk

import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
Expand Down Expand Up @@ -42,17 +41,8 @@ fun RuntimeConfig.awsRoot(): RuntimeCrateLocation {
}

object AwsRuntimeType {
fun presigning(codegenContext: ClientCodegenContext): RuntimeType =
when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) {
true -> RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", visibility = Visibility.PUBLIC))
else -> RuntimeType.forInlineDependency(
InlineAwsDependency.forRustFileAs(
file = "old_presigning",
moduleName = "presigning",
visibility = Visibility.PUBLIC,
),
)
}
fun presigning(): RuntimeType =
RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", visibility = Visibility.PUBLIC))

fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency(
InlineAwsDependency.forRustFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ abstract class BaseRequestIdDecorator : ClientCodegenDecorator {
): List<BuilderCustomization> = baseCustomizations + listOf(RequestIdBuilderCustomization())

override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
rustCrate.withModule(
when (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) {
true -> ClientRustModule.Operation
else -> ClientRustModule.types
},
) {
rustCrate.withModule(ClientRustModule.Operation) {
// Re-export RequestId in generated crate
rust("pub use #T;", accessorTrait(codegenContext))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.customize.TestUtilFeature
import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.core.rustlang.rust
Expand Down Expand Up @@ -41,7 +41,7 @@ class CredentialsProviderDecorator : ClientCodegenDecorator {
override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
rustCrate.mergeFeature(TestUtilFeature.copy(deps = listOf("aws-credential-types/test-util")))

rustCrate.withModule(codegenContext.featureGatedConfigModule()) {
rustCrate.withModule(ClientRustModule.Config) {
rust(
"pub use #T::Credentials;",
AwsRuntimeType.awsCredentialTypes(codegenContext.runtimeConfig),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rulesengine.language.syntax.parameters.Builtins
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization
import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
Expand Down Expand Up @@ -116,7 +116,7 @@ class RegionDecorator : ClientCodegenDecorator {

override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
if (usesRegion(codegenContext)) {
rustCrate.withModule(codegenContext.featureGatedConfigModule()) {
rustCrate.withModule(ClientRustModule.Config) {
rust("pub use #T::Region;", region(codegenContext.runtimeConfig))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package software.amazon.smithy.rustsdk
import software.amazon.smithy.aws.traits.ServiceTrait
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule
import software.amazon.smithy.rust.codegen.client.smithy.featureGatedMetaModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
Expand Down Expand Up @@ -67,18 +66,18 @@ class UserAgentDecorator : ClientCodegenDecorator {
val serviceTrait = codegenContext.serviceShape.expectTrait<ServiceTrait>()
val serviceId = serviceTrait.sdkId.lowercase().replace(" ", "")

rustCrate.withModule(codegenContext.featureGatedMetaModule()) {
rustCrate.withModule(ClientRustModule.Meta) {
rustTemplate(
"""
pub(crate) static API_METADATA: #{user_agent}::ApiMetadata =
#{user_agent}::ApiMetadata::new(${serviceId.dq()}, #{PKG_VERSION});
""",
"user_agent" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent"),
"PKG_VERSION" to CrateVersionCustomization.pkgVersion(codegenContext.featureGatedMetaModule()),
"PKG_VERSION" to CrateVersionCustomization.pkgVersion(ClientRustModule.Meta),
)
}

rustCrate.withModule(codegenContext.featureGatedConfigModule()) {
rustCrate.withModule(ClientRustModule.Config) {
// Re-export the app name so that it can be specified in config programmatically without an explicit dependency
rustTemplate(
"pub use #{AppName};",
Expand All @@ -105,7 +104,7 @@ class UserAgentDecorator : ClientCodegenDecorator {
}
${section.request}.properties_mut().insert(user_agent);
""",
"meta" to codegenContext.featureGatedMetaModule(),
"meta" to ClientRustModule.Meta,
"ua_module" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent"),
"Env" to AwsRuntimeType.awsTypes(runtimeConfig).resolve("os_shim_internal::Env"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ fun awsSdkIntegrationTest(
"codegen",
ObjectNode.builder()
.withMember("includeFluentClient", false)
.withMember("enableNewCrateOrganizationScheme", true)
.build(),
).build(),
),
Expand Down
1 change: 0 additions & 1 deletion buildSrc/src/main/kotlin/CodegenTestCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private fun generateSmithyBuild(projectDir: String, pluginName: String, tests: L
"relativePath": "$projectDir/rust-runtime"
},
"codegen": {
"enableNewCrateOrganizationScheme": true
},
"service": "${it.service}",
"module": "${it.module}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package software.amazon.smithy.rust.codegen.client.smithy

import software.amazon.smithy.build.PluginContext
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.knowledge.NullableIndex
import software.amazon.smithy.model.shapes.OperationShape
Expand Down Expand Up @@ -41,7 +40,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.contextName
import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator
import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator
import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator
import software.amazon.smithy.rust.codegen.core.smithy.module
import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory
import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer
import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer
Expand Down Expand Up @@ -79,16 +77,8 @@ class ClientCodegenVisitor(
runtimeConfig = settings.runtimeConfig,
renameExceptions = settings.codegenConfig.renameExceptions,
nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1,
moduleProvider = when (settings.codegenConfig.enableNewCrateOrganizationScheme) {
true -> ClientModuleProvider
else -> OldModuleSchemeClientModuleProvider
},
nameBuilderFor = { symbol ->
when (settings.codegenConfig.enableNewCrateOrganizationScheme) {
true -> "${symbol.name}Builder"
else -> "Builder"
}
},
moduleProvider = ClientModuleProvider,
nameBuilderFor = { symbol -> "${symbol.name}Builder" },
)
val baseModel = baselineTransform(context.model)
val untransformedService = settings.getService(baseModel)
Expand Down Expand Up @@ -207,19 +197,6 @@ class ClientCodegenVisitor(
override fun getDefault(shape: Shape?) {
}

// TODO(CrateReorganization): Remove this function when cleaning up `enableNewCrateOrganizationScheme`
private fun RustCrate.maybeInPrivateModuleWithReexport(
privateModule: RustModule.LeafModule,
symbol: Symbol,
writer: Writable,
) {
if (codegenContext.settings.codegenConfig.enableNewCrateOrganizationScheme) {
inPrivateModuleWithReexport(privateModule, symbol, writer)
} else {
withModule(symbol.module(), writer)
}
}

private fun privateModule(shape: Shape): RustModule.LeafModule =
RustModule.private(privateModuleName(shape), parent = symbolProvider.moduleForShape(shape))

Expand Down Expand Up @@ -278,10 +255,10 @@ class ClientCodegenVisitor(
}

val privateModule = privateModule(shape)
rustCrate.maybeInPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) {
rustCrate.inPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) {
renderStruct(this)
}
rustCrate.maybeInPrivateModuleWithReexport(privateModule, symbolProvider.symbolForBuilder(shape)) {
rustCrate.inPrivateModuleWithReexport(privateModule, symbolProvider.symbolForBuilder(shape)) {
renderBuilder(this)
}
}
Expand All @@ -294,7 +271,7 @@ class ClientCodegenVisitor(
override fun stringShape(shape: StringShape) {
if (shape.hasTrait<EnumTrait>()) {
val privateModule = privateModule(shape)
rustCrate.maybeInPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) {
rustCrate.inPrivateModuleWithReexport(privateModule, symbolProvider.toSymbol(shape)) {
ClientEnumGenerator(codegenContext, shape).render(this)
}
}
Expand All @@ -308,7 +285,7 @@ class ClientCodegenVisitor(
* Note: this does not generate serializers
*/
override fun unionShape(shape: UnionShape) {
rustCrate.maybeInPrivateModuleWithReexport(privateModule(shape), symbolProvider.toSymbol(shape)) {
rustCrate.inPrivateModuleWithReexport(privateModule(shape), symbolProvider.toSymbol(shape)) {
UnionGenerator(model, symbolProvider, this, shape, renderUnknownVariant = true).render()
}
if (shape.isEventStream()) {
Expand Down
Loading