diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 64d434f5f9cc1d5fc6db67fa380a4d4de47ca2d0..edfc6e29c6a8a406f2a78efe9c42ca31e728b193 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,6 +9,6 @@ repos: rev: v1.6.1 hooks: - id: pretty-format-kotlin - args: [--autofix, --ktlint-version, 0.39.0] + args: [--autofix, --ktlint-version, 0.40.0] - id: pretty-format-yaml args: [--autofix, --indent, '2'] diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt index 1b870ec8771b3e9effbeededde30f4747edee4d4..f8bb003464c27c19ede50e9eaa7035e6e4950794 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt @@ -29,7 +29,7 @@ fun T.withBlock( vararg args: Any, block: T.() -> Unit ): T { - return conditionalBlock(textBeforeNewLine, textAfterNewLine, conditional = true, block = block, args = *args) + return conditionalBlock(textBeforeNewLine, textAfterNewLine, conditional = true, block = block, args = args) } /** diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt index 98df6822268be486545b150783346a9a7b36f478..a9f42bf09015bcdb0cbbb02e19a81622516731cd 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt @@ -42,10 +42,11 @@ import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.util.toSnakeCase import software.amazon.smithy.utils.StringUtils +import kotlin.reflect.KClass // TODO: currently, respecting integer types. // Should we not? [Go does not] -val SimpleShapes = mapOf( +val SimpleShapes: Map, RustType> = mapOf( BooleanShape::class to RustType.Bool, FloatShape::class to RustType.Float(32), DoubleShape::class to RustType.Float(64), diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/RecursiveShapeBoxer.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/RecursiveShapeBoxer.kt index 361f301fff722c711bca5cbe9a93b237cc6b390a..b9a3563f0b7d7e81fe3f76c3f49a79eb1338a61c 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/RecursiveShapeBoxer.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/RecursiveShapeBoxer.kt @@ -59,7 +59,7 @@ object RecursiveShapeBoxer { return loopToFix?.let { loop: List -> check(loop.isNotEmpty()) // pick the shape to box in a deterministic way - val shapeToBox = loop.filterIsInstance().minBy { it.id }!! + val shapeToBox = loop.filterIsInstance().minByOrNull { it.id }!! ModelTransformer.create().mapShapes(model) { shape -> if (shape == shapeToBox) { shape.asMemberShape().get().toBuilder().addTrait(RustBoxTrait()).build() diff --git a/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/Rust.kt b/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/Rust.kt index 3eb0fa9c1b9e473d9c69fbc670dfeb2db75508b1..af10ac84b76ebfaf7080df0f7ff7260acefd04b2 100644 --- a/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/Rust.kt +++ b/codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/Rust.kt @@ -27,15 +27,28 @@ import software.amazon.smithy.rust.codegen.util.CommandFailed import software.amazon.smithy.rust.codegen.util.dq import software.amazon.smithy.rust.codegen.util.runCommand import java.io.File +import java.nio.file.Files.createTempDirectory import java.nio.file.Path +/** + * Waiting for Kotlin to stabilize their temp directory stuff + */ +private fun tempDir(directory: File? = null): File { + return if (directory != null) { + createTempDirectory(directory.toPath(), "smithy-test").toFile() + } else { + createTempDirectory("smithy-test").toFile() + } +} + /** * Creates a Cargo workspace shared among all tests * * This workspace significantly improves test performance by sharing dependencies between different tests. */ object TestWorkspace { - private val baseDir = System.getenv("SMITHY_TEST_WORKSPACE")?.let { File(it) } ?: createTempDir() + private val baseDir = + System.getenv("SMITHY_TEST_WORKSPACE")?.let { File(it) } ?: tempDir() private val subprojects = mutableListOf() init { @@ -56,7 +69,7 @@ object TestWorkspace { fun subproject(): File { synchronized(subprojects) { - val newProject = createTempDir(directory = baseDir) + val newProject = tempDir(directory = baseDir) subprojects.add(newProject.name) generate() return newProject @@ -114,7 +127,7 @@ fun TestWriterDelegator.compileAndTest() { // TODO: unify these test helpers a bit fun String.shouldParseAsRust() { // quick hack via rustfmt - val tempFile = createTempFile(suffix = ".rs") + val tempFile = File.createTempFile("rust_test", ".rs") tempFile.writeText(this) "rustfmt ${tempFile.absolutePath}".runCommand() } @@ -205,8 +218,8 @@ fun String.compileAndTest( fun String.shouldCompile(): File { this.shouldParseAsRust() - val tempFile = createTempFile(suffix = ".rs") - val tempDir = createTempDir() + val tempFile = File.createTempFile("rust_test", ".rs") + val tempDir = tempDir() tempFile.writeText(this) if (!this.contains("fn main")) { tempFile.appendText("\nfn main() {}\n") diff --git a/gradle.properties b/gradle.properties index 71822fe198e3b2741d5d778be049080f3874a53a..b3b3b69ea9bd36a5bd262f6aa737d492bb98e3e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,10 +6,10 @@ kotlin.code.style=official # codegen -smithyVersion=1.4.0 +smithyVersion=1.5.0 # kotlin -kotlinVersion=1.3.72 +kotlinVersion=1.4.21 kotlin.native.ignoreDisabledTargets=true # kotlin libraries @@ -20,5 +20,5 @@ ktorVersion=1.3.2 # testing/utility # FIXME - junit5 not working junitVersion=4.12 -ktlintVersion=0.39.0 +ktlintVersion=0.40.0 kotestVersion=4.2.6