From eca86039a1babd922c1e20c8c8d3135352528dfa Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 14 Dec 2020 10:58:04 -0500 Subject: [PATCH] Upgrade Smithy & Kotlin to latest (#82) * Upgrade to Kotlin 1.4 * Upgrade Smithy version, fix some deprecations --- .pre-commit-config.yaml | 2 +- .../smithy/rust/codegen/lang/RustWriter.kt | 2 +- .../rust/codegen/smithy/SymbolVisitor.kt | 3 ++- .../transformers/RecursiveShapeBoxer.kt | 2 +- .../amazon/smithy/rust/testutil/Rust.kt | 23 +++++++++++++++---- gradle.properties | 6 ++--- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 64d434f5f..edfc6e29c 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 1b870ec87..f8bb00346 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 98df68222..a9f42bf09 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 361f301ff..b9a3563f0 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 3eb0fa9c1..af10ac84b 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 71822fe19..b3b3b69ea 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 -- GitLab