mirror of https://github.com/smithy-lang/smithy-rs
Update Rust version (#276)
* Update Rust version * wip * Refactor handling of clippy lints * Delete old version of clippy lints * Delete unused code
This commit is contained in:
parent
5cbfbf580d
commit
e7a0f1fa60
|
@ -3,7 +3,7 @@ on: [push]
|
|||
name: CI
|
||||
|
||||
env:
|
||||
rust_version: 1.50.0
|
||||
rust_version: 1.51.0
|
||||
java_version: 14
|
||||
|
||||
jobs:
|
||||
|
|
|
@ -230,7 +230,7 @@ pub enum UserAgentStageError {
|
|||
#[error("User agent missing from property bag")]
|
||||
UserAgentMissing,
|
||||
#[error("Provided user agent header was invalid")]
|
||||
InvalidUAHeader(#[from] InvalidHeaderValue),
|
||||
InvalidHeader(#[from] InvalidHeaderValue),
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
|
|
|
@ -113,7 +113,7 @@ tasks.register<Exec>("cargoDocs") {
|
|||
tasks.register<Exec>("cargoClippy") {
|
||||
workingDir("build/smithyprojections/sdk-codegen-test/")
|
||||
// disallow warnings
|
||||
commandLine("cargo", "clippy", "--", "-D", "warnings", "-Aclippy::upper_case_acronyms", "-Aclippy::large-enum-variant")
|
||||
commandLine("cargo", "clippy", "--", "-D", "warnings")
|
||||
dependsOn("assemble")
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat
|
|||
CargoDependency.SmithyHttp(runtimeConfig).asType()
|
||||
)
|
||||
}
|
||||
else -> emptySection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ class PubUseCredentials(private val runtimeConfig: RuntimeConfig) : LibRsCustomi
|
|||
override fun section(section: LibRsSection): Writable {
|
||||
return when (section) {
|
||||
is LibRsSection.Body -> writable { rust("pub use #T::Credentials;", awsAuth(runtimeConfig).asType()) }
|
||||
else -> emptySection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,9 +56,12 @@ class FluentClientDecorator : RustCodegenDecorator {
|
|||
baseCustomizations: List<LibRsCustomization>
|
||||
): List<LibRsCustomization> {
|
||||
return baseCustomizations + object : LibRsCustomization() {
|
||||
override fun section(section: LibRsSection) = writable {
|
||||
Attribute.Cfg.feature("client").render(this)
|
||||
rust("pub use client::Client;")
|
||||
override fun section(section: LibRsSection) = when (section) {
|
||||
is LibRsSection.Body -> writable {
|
||||
Attribute.Cfg.feature("client").render(this)
|
||||
rust("pub use client::Client;")
|
||||
}
|
||||
else -> emptySection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ class PubUseRegion(private val runtimeConfig: RuntimeConfig) : LibRsCustomizatio
|
|||
override fun section(section: LibRsSection): Writable {
|
||||
return when (section) {
|
||||
is LibRsSection.Body -> writable { rust("pub use #T::Region;", region(runtimeConfig)) }
|
||||
else -> emptySection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ class ApiVersion(private val runtimeConfig: RuntimeConfig, serviceTrait: Service
|
|||
override fun section(section: LibRsSection): Writable = when (section) {
|
||||
// PKG_VERSION comes from CrateVersionGenerator
|
||||
is LibRsSection.Body -> writable { rust("static API_METADATA: #1T::ApiMetadata = #1T::ApiMetadata::new(${serviceId.dq()}, PKG_VERSION);", runtimeConfig.userAgentModule()) }
|
||||
else -> emptySection
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ tasks.register<Exec>("cargoDocs") {
|
|||
tasks.register<Exec>("cargoClippy") {
|
||||
workingDir(sdkOutputDir)
|
||||
// disallow warnings
|
||||
commandLine("cargo", "clippy", "--", "-D", "warnings", "-Aclippy::upper_case_acronyms", "-Aclippy::large-enum-variant", "-Aclippy::module-inception")
|
||||
commandLine("cargo", "clippy", "--", "-D", "warnings")
|
||||
dependsOn("assemble")
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ tasks.register<Exec>("cargoDocs") {
|
|||
tasks.register<Exec>("cargoClippy") {
|
||||
workingDir("build/smithyprojections/codegen-test/")
|
||||
// disallow warnings
|
||||
commandLine("cargo", "clippy", "--", "-D", "warnings", "-Aclippy::upper_case_acronyms", "-Aclippy::large-enum-variant")
|
||||
commandLine("cargo", "clippy", "--", "-D", "warnings")
|
||||
dependsOn("assemble")
|
||||
}
|
||||
|
||||
|
|
|
@ -222,9 +222,20 @@ sealed class Attribute {
|
|||
}
|
||||
}
|
||||
|
||||
data class Custom(val annotation: String, val symbols: List<RuntimeType> = listOf()) : Attribute() {
|
||||
/**
|
||||
* A custom Attribute
|
||||
*
|
||||
* [annotation] represents the body of the attribute, eg. `cfg(foo)` in `#[cfg(foo)]`
|
||||
* If [container] is set, this attribute refers to its container rather than its successor. This generates `#![cfg(foo)]`
|
||||
*
|
||||
* Finally, any symbols listed will be imported when this attribute is rendered. This enables using attributes like
|
||||
* `#[serde(Serialize)]` where `Serialize` is actually a symbol that must be imported.
|
||||
*/
|
||||
data class Custom(val annotation: String, val symbols: List<RuntimeType> = listOf(), val container: Boolean = false) : Attribute() {
|
||||
override fun render(writer: RustWriter) {
|
||||
writer.raw("#[$annotation]")
|
||||
|
||||
val bang = if (container) "!" else ""
|
||||
writer.raw("#$bang[$annotation]")
|
||||
symbols.forEach {
|
||||
writer.addDependency(it.dependency)
|
||||
}
|
||||
|
|
|
@ -173,14 +173,9 @@ class RustWriter private constructor(
|
|||
private val filename: String,
|
||||
val namespace: String,
|
||||
private val commentCharacter: String = "//",
|
||||
private var printWarning: Boolean = true
|
||||
private val printWarning: Boolean = true
|
||||
) :
|
||||
CodegenWriter<RustWriter, UseDeclarations>(null, UseDeclarations(namespace)) {
|
||||
private var headerDocs: String? = null
|
||||
fun setHeaderDocs(docs: String) {
|
||||
headerDocs = RustWriter("", "", printWarning = false).docs(docs, newlinePrefix = "//! ").toString()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun root() = forModule(null)
|
||||
fun forModule(module: String?): RustWriter = if (module == null) {
|
||||
|
@ -204,6 +199,7 @@ class RustWriter private constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private val preamble = mutableListOf<Writable>()
|
||||
private val formatter = RustSymbolFormatter()
|
||||
private var n = 0
|
||||
|
||||
|
@ -225,6 +221,10 @@ class RustWriter private constructor(
|
|||
return "${prefix}_$n"
|
||||
}
|
||||
|
||||
fun first(prewriter: RustWriter.() -> Unit) {
|
||||
preamble.add(prewriter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an inline module.
|
||||
*
|
||||
|
@ -300,17 +300,21 @@ class RustWriter private constructor(
|
|||
|
||||
override fun toString(): String {
|
||||
val contents = super.toString()
|
||||
val preheader = if (preamble.isNotEmpty()) {
|
||||
val prewriter = RustWriter(filename, namespace, printWarning = false)
|
||||
preamble.forEach { it(prewriter) }
|
||||
prewriter.toString()
|
||||
} else null
|
||||
|
||||
// Hack to support TOML
|
||||
// TODO: consider creating a TOML writer
|
||||
val header = if (printWarning) {
|
||||
"$commentCharacter Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT."
|
||||
} else null
|
||||
val useDecls = importContainer.toString().let {
|
||||
if (it.isEmpty()) {
|
||||
null
|
||||
} else it
|
||||
val useDecls = importContainer.toString().ifEmpty {
|
||||
null
|
||||
}
|
||||
return listOfNotNull(headerDocs, header, useDecls, contents).joinToString(separator = "\n", postfix = "\n")
|
||||
return listOfNotNull(preheader, header, useDecls, contents).joinToString(separator = "\n", postfix = "\n")
|
||||
}
|
||||
|
||||
fun format(r: Any):
|
||||
|
|
|
@ -16,14 +16,12 @@ import software.amazon.smithy.model.shapes.StructureShape
|
|||
import software.amazon.smithy.model.shapes.UnionShape
|
||||
import software.amazon.smithy.model.traits.EnumTrait
|
||||
import software.amazon.smithy.rust.codegen.smithy.customize.RustCodegenDecorator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.CrateVersionGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.EnumGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.HttpProtocolGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.ModelBuilderGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolConfig
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolGeneratorFactory
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.ServiceGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.SmithyTypesPubUseGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.StructureGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.UnionGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.implBlock
|
||||
|
@ -87,7 +85,7 @@ class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustC
|
|||
settings,
|
||||
codegenDecorator.libRsCustomizations(
|
||||
protocolConfig,
|
||||
listOf(CrateVersionGenerator(), SmithyTypesPubUseGenerator(protocolConfig.runtimeConfig))
|
||||
listOf()
|
||||
)
|
||||
)
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
package software.amazon.smithy.rust.codegen.smithy.customizations
|
||||
|
||||
import software.amazon.smithy.rust.codegen.rustlang.Attribute
|
||||
import software.amazon.smithy.rust.codegen.rustlang.writable
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsCustomization
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsSection
|
||||
|
||||
val ClippyAllowLints = listOf(
|
||||
// Sometimes a operation be named the same as our module eg. output leading to `output::output`
|
||||
"module_inception",
|
||||
// Currently, we don't recase acronyms in models, eg. SSEVersion
|
||||
"upper_case_acronyms",
|
||||
// Large errors trigger this warning, we are unlikely to optimize this case currently
|
||||
"large_enum_variant"
|
||||
)
|
||||
|
||||
class AllowClippyLints() : LibRsCustomization() {
|
||||
override fun section(section: LibRsSection) = when (section) {
|
||||
is LibRsSection.Attributes -> writable {
|
||||
ClippyAllowLints.forEach {
|
||||
Attribute.Custom("allow(clippy::$it)", container = true).render(this)
|
||||
}
|
||||
// add a newline at the end
|
||||
this.write("")
|
||||
}
|
||||
else -> emptySection
|
||||
}
|
||||
}
|
|
@ -3,10 +3,12 @@
|
|||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
package software.amazon.smithy.rust.codegen.smithy.generators
|
||||
package software.amazon.smithy.rust.codegen.smithy.customizations
|
||||
|
||||
import software.amazon.smithy.rust.codegen.rustlang.rust
|
||||
import software.amazon.smithy.rust.codegen.rustlang.writable
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsCustomization
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsSection
|
||||
|
||||
/**
|
||||
* Add `PGK_VERSION` const in lib.rs to enable knowing the version of the current module
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
package software.amazon.smithy.rust.codegen.smithy.generators
|
||||
package software.amazon.smithy.rust.codegen.smithy.customizations
|
||||
|
||||
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
|
||||
import software.amazon.smithy.rust.codegen.rustlang.asType
|
||||
|
@ -11,10 +11,12 @@ import software.amazon.smithy.rust.codegen.rustlang.rust
|
|||
import software.amazon.smithy.rust.codegen.rustlang.writable
|
||||
import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig
|
||||
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsCustomization
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsSection
|
||||
|
||||
fun pubUseTypes(runtimeConfig: RuntimeConfig) = listOf(
|
||||
RuntimeType.Blob(runtimeConfig),
|
||||
CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError")
|
||||
CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"),
|
||||
)
|
||||
|
||||
class SmithyTypesPubUseGenerator(private val runtimeConfig: RuntimeConfig) : LibRsCustomization() {
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
|
||||
package software.amazon.smithy.rust.codegen.smithy.customize
|
||||
|
||||
import software.amazon.smithy.rust.codegen.smithy.customizations.AllowClippyLints
|
||||
import software.amazon.smithy.rust.codegen.smithy.customizations.CrateVersionGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.customizations.SmithyTypesPubUseGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsCustomization
|
||||
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolConfig
|
||||
|
||||
/** A set of customizations that are included in all protocols.
|
||||
*
|
||||
* This exists as a convenient place to gather these modifications, these are not true customizations.
|
||||
*/
|
||||
class BaseCustomizations : RustCodegenDecorator {
|
||||
override val name: String = "Base"
|
||||
override val order: Byte = -1
|
||||
|
||||
override fun libRsCustomizations(
|
||||
protocolConfig: ProtocolConfig,
|
||||
baseCustomizations: List<LibRsCustomization>
|
||||
): List<LibRsCustomization> {
|
||||
return baseCustomizations + CrateVersionGenerator() + SmithyTypesPubUseGenerator(protocolConfig.runtimeConfig) + AllowClippyLints()
|
||||
}
|
||||
}
|
|
@ -123,12 +123,10 @@ open class CombinedCodegenDecorator(decorators: List<RustCodegenDecorator>) : Ru
|
|||
RustCodegenDecorator::class.java,
|
||||
context.pluginClassLoader.orElse(RustCodegenDecorator::class.java.classLoader)
|
||||
)
|
||||
.also { decorators ->
|
||||
decorators.forEach {
|
||||
logger.info("Adding Codegen Decorator: ${it.javaClass.name}")
|
||||
}
|
||||
.onEach {
|
||||
logger.info("Adding Codegen Decorator: ${it.javaClass.name}")
|
||||
}.toList()
|
||||
return CombinedCodegenDecorator(decorators)
|
||||
return CombinedCodegenDecorator(decorators + BaseCustomizations())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,13 @@ package software.amazon.smithy.rust.codegen.smithy.generators
|
|||
|
||||
import software.amazon.smithy.rust.codegen.rustlang.RustModule
|
||||
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
|
||||
import software.amazon.smithy.rust.codegen.rustlang.docs
|
||||
import software.amazon.smithy.rust.codegen.rustlang.escape
|
||||
import software.amazon.smithy.rust.codegen.smithy.customize.NamedSectionGenerator
|
||||
import software.amazon.smithy.rust.codegen.smithy.customize.Section
|
||||
|
||||
sealed class LibRsSection(name: String) : Section(name) {
|
||||
object Attributes : LibRsSection("Attributes")
|
||||
object Body : LibRsSection("Body")
|
||||
}
|
||||
|
||||
|
@ -23,7 +25,10 @@ class LibRsGenerator(
|
|||
private val customizations: List<LibRsCustomization>
|
||||
) {
|
||||
fun render(writer: RustWriter) {
|
||||
writer.setHeaderDocs(writer.escape(libraryDocs))
|
||||
writer.first {
|
||||
customizations.forEach { it.section(LibRsSection.Attributes)(this) }
|
||||
docs(escape(libraryDocs))
|
||||
}
|
||||
modules.forEach { it.render(writer) }
|
||||
customizations.forEach { it.section(LibRsSection.Body)(writer) }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue