Skip to content

Commit

Permalink
update: CargoDependency companion fn names for smithy runtime crates (#…
Browse files Browse the repository at this point in the history
…1996)

* update: CargoDependency companion fn names for smithy runtime crates
rename: CargoDependency.asType to CargoDependency.toType
fix: errors in InlineDependency doc comment
formatting: run import optimizer for all kotlin files
fix: gradle issue with incorrectly named tasks

* fix: server test broken by removal of rustName
  • Loading branch information
Velfi authored Nov 17, 2022
1 parent d99a0db commit 4aca7b3
Show file tree
Hide file tree
Showing 71 changed files with 275 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
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.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
Expand Down Expand Up @@ -95,18 +94,18 @@ class EndpointConfigCustomization(
) :
ConfigCustomization() {
private val runtimeConfig = codegenContext.runtimeConfig
private val resolveAwsEndpoint = runtimeConfig.awsEndpoint().asType().copy(name = "ResolveAwsEndpoint")
private val resolveAwsEndpoint = runtimeConfig.awsEndpoint().toType().copy(name = "ResolveAwsEndpoint")
private val smithyEndpointResolver =
CargoDependency.SmithyHttp(runtimeConfig).asType().member("endpoint::ResolveEndpoint")
private val placeholderEndpointParams = runtimeConfig.awsEndpoint().asType().member("Params")
private val endpointShim = runtimeConfig.awsEndpoint().asType().member("EndpointShim")
CargoDependency.smithyHttp(runtimeConfig).toType().member("endpoint::ResolveEndpoint")
private val placeholderEndpointParams = runtimeConfig.awsEndpoint().toType().member("Params")
private val endpointShim = runtimeConfig.awsEndpoint().toType().member("EndpointShim")
private val moduleUseName = codegenContext.moduleUseName()
private val codegenScope = arrayOf(
"SmithyResolver" to smithyEndpointResolver,
"PlaceholderParams" to placeholderEndpointParams,
"ResolveAwsEndpoint" to resolveAwsEndpoint,
"EndpointShim" to endpointShim,
"aws_types" to awsTypes(runtimeConfig).asType(),
"aws_types" to awsTypes(runtimeConfig).toType(),
)

override fun section(section: ServiceConfig): Writable = writable {
Expand Down Expand Up @@ -184,7 +183,7 @@ class EndpointConfigCustomization(

class EndpointResolverFeature(private val runtimeConfig: RuntimeConfig, private val operationShape: OperationShape) :
OperationCustomization() {
private val placeholderEndpointParams = runtimeConfig.awsEndpoint().asType().member("Params")
private val placeholderEndpointParams = runtimeConfig.awsEndpoint().toType().member("Params")
private val codegenScope = arrayOf(
"PlaceholderParams" to placeholderEndpointParams,
"BuildError" to runtimeConfig.operationBuildError(),
Expand Down Expand Up @@ -215,7 +214,7 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat
is LibRsSection.Body -> writable {
rust(
"pub use #T::endpoint::Endpoint;",
CargoDependency.SmithyHttp(runtimeConfig).asType(),
CargoDependency.smithyHttp(runtimeConfig).toType(),
)
}
else -> emptySection
Expand All @@ -226,8 +225,8 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat
class EndpointResolverGenerator(codegenContext: CodegenContext, private val endpointData: ObjectNode) {
private val runtimeConfig = codegenContext.runtimeConfig
private val endpointPrefix = codegenContext.serviceShape.expectTrait<ServiceTrait>().endpointPrefix
private val awsEndpoint = runtimeConfig.awsEndpoint().asType()
private val awsTypes = runtimeConfig.awsTypes().asType()
private val awsEndpoint = runtimeConfig.awsEndpoint().toType()
private val awsTypes = runtimeConfig.awsTypes().toType()
private val codegenScope =
arrayOf(
"Partition" to awsEndpoint.member("Partition"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
Expand All @@ -39,13 +38,13 @@ import software.amazon.smithy.rust.codegen.core.util.expectTrait
import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware

private class Types(runtimeConfig: RuntimeConfig) {
private val smithyTypesDep = CargoDependency.SmithyTypes(runtimeConfig)
private val smithyClientDep = CargoDependency.SmithyClient(runtimeConfig)
private val smithyHttpDep = CargoDependency.SmithyHttp(runtimeConfig)
private val smithyTypesDep = CargoDependency.smithyTypes(runtimeConfig)
private val smithyClientDep = CargoDependency.smithyClient(runtimeConfig)
private val smithyHttpDep = CargoDependency.smithyHttp(runtimeConfig)

val awsTypes = awsTypes(runtimeConfig).asType()
val awsTypes = awsTypes(runtimeConfig).toType()
val smithyClientRetry = RuntimeType("retry", smithyClientDep, "aws_smithy_client")
val awsSmithyClient = smithyClientDep.asType()
val awsSmithyClient = smithyClientDep.toType()

val connectorSettings = RuntimeType("ConnectorSettings", smithyClientDep, "aws_smithy_client::http_connector")
val defaultMiddleware = runtimeConfig.defaultMiddleware()
Expand Down Expand Up @@ -106,7 +105,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator<ClientProtocolGenerator, C
AwsPresignedFluentBuilderMethod(runtimeConfig),
AwsFluentClientDocs(codegenContext),
),
retryClassifier = runtimeConfig.awsHttp().asType().member("retry::AwsResponseRetryClassifier"),
retryClassifier = runtimeConfig.awsHttp().toType().member("retry::AwsResponseRetryClassifier"),
).render(rustCrate)
rustCrate.withNonRootModule(CustomizableOperationGenerator.CUSTOMIZE_MODULE) {
renderCustomizableOperationSendMethod(runtimeConfig, generics, this)
Expand Down Expand Up @@ -214,7 +213,7 @@ private class AwsFluentClientDocs(private val codegenContext: CodegenContext) :
private val serviceShape = codegenContext.serviceShape
private val crateName = codegenContext.moduleUseName()
private val codegenScope =
arrayOf("aws_config" to codegenContext.runtimeConfig.awsConfig().copy(scope = DependencyScope.Dev).asType())
arrayOf("aws_config" to codegenContext.runtimeConfig.awsConfig().copy(scope = DependencyScope.Dev).toType())

// If no `aws-config` version is provided, assume that docs referencing `aws-config` cannot be given.
// Also, STS and SSO must NOT reference `aws-config` since that would create a circular dependency.
Expand Down Expand Up @@ -279,7 +278,7 @@ private fun renderCustomizableOperationSendMethod(
generics: FluentClientGenerics,
writer: RustWriter,
) {
val smithyHttp = CargoDependency.SmithyHttp(runtimeConfig).asType()
val smithyHttp = CargoDependency.smithyHttp(runtimeConfig).toType()

val operationGenerics = RustGenerics(GenericTypeArg("O"), GenericTypeArg("Retry"))
val handleGenerics = generics.toRustGenerics()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
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
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
Expand Down Expand Up @@ -145,10 +144,10 @@ class AwsInputPresignedMethod(
"PresignedRequest" to AwsRuntimeType.Presigning.member("request::PresignedRequest"),
"PresignedRequestService" to AwsRuntimeType.Presigning.member("service::PresignedRequestService"),
"PresigningConfig" to AwsRuntimeType.Presigning.member("config::PresigningConfig"),
"SdkError" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"),
"aws_sigv4" to runtimeConfig.awsRuntimeDependency("aws-sigv4").asType(),
"sig_auth" to runtimeConfig.sigAuth().asType(),
"tower" to CargoDependency.Tower.asType(),
"SdkError" to CargoDependency.smithyHttp(runtimeConfig).toType().member("result::SdkError"),
"aws_sigv4" to runtimeConfig.awsRuntimeDependency("aws-sigv4").toType(),
"sig_auth" to runtimeConfig.sigAuth().toType(),
"tower" to CargoDependency.Tower.toType(),
"Middleware" to runtimeConfig.defaultMiddleware(),
)

Expand Down Expand Up @@ -253,7 +252,7 @@ class AwsPresignedFluentBuilderMethod(
"Error" to AwsRuntimeType.Presigning.member("config::Error"),
"PresignedRequest" to AwsRuntimeType.Presigning.member("request::PresignedRequest"),
"PresigningConfig" to AwsRuntimeType.Presigning.member("config::PresigningConfig"),
"SdkError" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"),
"SdkError" to CargoDependency.smithyHttp(runtimeConfig).toType().member("result::SdkError"),
)

override fun section(section: FluentClientSection): Writable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ object AwsRuntimeType {
fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency(
InlineAwsDependency.forRustFile(
"middleware", visibility = Visibility.PUBLIC,
CargoDependency.SmithyHttp(this),
CargoDependency.SmithyHttpTower(this),
CargoDependency.SmithyClient(this),
CargoDependency.smithyHttp(this),
CargoDependency.smithyHttpTower(this),
CargoDependency.smithyClient(this),
CargoDependency.Tower,
sigAuth(),
awsHttp(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Confi
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
Expand Down Expand Up @@ -60,7 +59,7 @@ class CredentialsProviderDecorator : RustCodegenDecorator<ClientProtocolGenerato
class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomization() {
private val defaultProvider = defaultProvider()
private val codegenScope = arrayOf(
"credentials" to awsTypes(runtimeConfig).asType().member("credentials"),
"credentials" to awsTypes(runtimeConfig).toType().member("credentials"),
"DefaultProvider" to defaultProvider,
)

Expand Down Expand Up @@ -131,7 +130,7 @@ class PubUseCredentials(private val runtimeConfig: RuntimeConfig) : LibRsCustomi
is LibRsSection.Body -> writable {
rust(
"pub use #T::Credentials;",
awsTypes(runtimeConfig).asType(),
awsTypes(runtimeConfig).toType(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDe
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.client.smithy.generators.protocol.ClientProtocolGenerator
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.SmithyClient
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.smithyClient
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
Expand All @@ -39,7 +38,7 @@ class HttpConnectorConfigCustomization(
private val runtimeConfig = codegenContext.runtimeConfig
private val moduleUseName = codegenContext.moduleUseName()
private val codegenScope = arrayOf(
"HttpConnector" to SmithyClient(runtimeConfig).asType().member("http_connector::HttpConnector"),
"HttpConnector" to smithyClient(runtimeConfig).toType().member("http_connector::HttpConnector"),
)

override fun section(section: ServiceConfig): Writable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli
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.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
Expand All @@ -32,9 +31,9 @@ fun RuntimeConfig.awsInlineableBodyWithChecksum() = RuntimeType.forInlineDepende
"http_body_checksum", visibility = Visibility.PUBLIC,
CargoDependency.Http,
CargoDependency.HttpBody,
CargoDependency.SmithyHttp(this),
CargoDependency.SmithyChecksums(this),
CargoDependency.SmithyTypes(this),
CargoDependency.smithyHttp(this),
CargoDependency.smithyChecksums(this),
CargoDependency.smithyTypes(this),
CargoDependency.Bytes,
CargoDependency.Tracing,
this.sigAuth(),
Expand Down Expand Up @@ -105,7 +104,7 @@ private fun HttpChecksumTrait.checksumAlgorithmToStr(
};
""",
"BuildError" to runtimeConfig.operationBuildError(),
"ChecksumAlgorithm" to CargoDependency.SmithyChecksums(runtimeConfig).asType().member("ChecksumAlgorithm"),
"ChecksumAlgorithm" to CargoDependency.smithyChecksums(runtimeConfig).toType().member("ChecksumAlgorithm"),
)

// If a request checksum is not required and there's no way to set one, do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.AsyncStd
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.AsyncStream
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.BytesUtils
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Criterion
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.FuturesCore
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.FuturesUtil
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Hound
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.SerdeJson
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Smol
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.TempFile
import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Tokio
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Tracing
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.TracingSubscriber
import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.writable
Expand Down Expand Up @@ -66,10 +76,10 @@ class IntegrationTestDependencies(
override fun section(section: LibRsSection) = when (section) {
is LibRsSection.Body -> writable {
if (hasTests) {
val smithyClient = CargoDependency.SmithyClient(runtimeConfig)
val smithyClient = CargoDependency.smithyClient(runtimeConfig)
.copy(features = setOf("test-util"), scope = DependencyScope.Dev)
addDependency(smithyClient)
addDependency(CargoDependency.SmithyProtocolTestHelpers(runtimeConfig))
addDependency(CargoDependency.smithyProtocolTestHelpers(runtimeConfig))
addDependency(SerdeJson)
addDependency(Tokio)
addDependency(FuturesUtil)
Expand All @@ -88,7 +98,7 @@ class IntegrationTestDependencies(

private fun serviceSpecificCustomizations(): List<LibRsCustomization> = when (moduleName) {
"transcribestreaming" -> listOf(TranscribeTestDependencies())
"s3" -> listOf(S3TestDependencies(runtimeConfig))
"s3" -> listOf(S3TestDependencies())
else -> emptyList()
}
}
Expand All @@ -102,30 +112,12 @@ class TranscribeTestDependencies : LibRsCustomization() {
}
}

class S3TestDependencies(
private val runtimeConfig: RuntimeConfig,
) : LibRsCustomization() {
class S3TestDependencies : LibRsCustomization() {
override fun section(section: LibRsSection): Writable =
writable {
addDependency(AsyncStd)
addDependency(BytesUtils)
addDependency(Smol)
addDependency(TempFile)
runtimeConfig.runtimeCrate("async", scope = DependencyScope.Dev)
runtimeConfig.runtimeCrate("client", scope = DependencyScope.Dev)
runtimeConfig.runtimeCrate("http", scope = DependencyScope.Dev)
runtimeConfig.runtimeCrate("types", scope = DependencyScope.Dev)
}
}

private val AsyncStd = CargoDependency("async-std", CratesIo("1.12.0"), scope = DependencyScope.Dev)
private val AsyncStream = CargoDependency("async-stream", CratesIo("0.3.0"), DependencyScope.Dev)
private val Criterion = CargoDependency("criterion", CratesIo("0.4.0"), scope = DependencyScope.Dev)
private val FuturesCore = CargoDependency("futures-core", CratesIo("0.3.0"), DependencyScope.Dev)
private val FuturesUtil = CargoDependency("futures-util", CratesIo("0.3.0"), scope = DependencyScope.Dev)
private val Hound = CargoDependency("hound", CratesIo("3.4.0"), DependencyScope.Dev)
private val SerdeJson = CargoDependency("serde_json", CratesIo("1.0.0"), features = emptySet(), scope = DependencyScope.Dev)
private val Smol = CargoDependency("smol", CratesIo("1.2.0"), scope = DependencyScope.Dev)
private val Tokio = CargoDependency("tokio", CratesIo("1.8.4"), features = setOf("macros", "test-util"), scope = DependencyScope.Dev)
private val Tracing = CargoDependency("tracing", CratesIo("0.1.0"), scope = DependencyScope.Dev)
private val TracingSubscriber = CargoDependency("tracing-subscriber", CratesIo("0.3.15"), scope = DependencyScope.Dev, features = setOf("env-filter"))
Loading

0 comments on commit 4aca7b3

Please sign in to comment.