Loading .pre-commit-config.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -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'] codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ fun <T : CodeWriter> 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) } /** Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt +2 −1 Original line number Diff line number Diff line Loading @@ -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<KClass<out Shape>, RustType> = mapOf( BooleanShape::class to RustType.Bool, FloatShape::class to RustType.Float(32), DoubleShape::class to RustType.Float(64), Loading codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/RecursiveShapeBoxer.kt +1 −1 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ object RecursiveShapeBoxer { return loopToFix?.let { loop: List<Shape> -> check(loop.isNotEmpty()) // pick the shape to box in a deterministic way val shapeToBox = loop.filterIsInstance<MemberShape>().minBy { it.id }!! val shapeToBox = loop.filterIsInstance<MemberShape>().minByOrNull { it.id }!! ModelTransformer.create().mapShapes(model) { shape -> if (shape == shapeToBox) { shape.asMemberShape().get().toBuilder().addTrait(RustBoxTrait()).build() Loading codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/Rust.kt +18 −5 Original line number Diff line number Diff line Loading @@ -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<String>() init { Loading @@ -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 Loading Loading @@ -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() } Loading Loading @@ -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") Loading Loading
.pre-commit-config.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -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']
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustWriter.kt +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ fun <T : CodeWriter> 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) } /** Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt +2 −1 Original line number Diff line number Diff line Loading @@ -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<KClass<out Shape>, RustType> = mapOf( BooleanShape::class to RustType.Bool, FloatShape::class to RustType.Float(32), DoubleShape::class to RustType.Float(64), Loading
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/RecursiveShapeBoxer.kt +1 −1 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ object RecursiveShapeBoxer { return loopToFix?.let { loop: List<Shape> -> check(loop.isNotEmpty()) // pick the shape to box in a deterministic way val shapeToBox = loop.filterIsInstance<MemberShape>().minBy { it.id }!! val shapeToBox = loop.filterIsInstance<MemberShape>().minByOrNull { it.id }!! ModelTransformer.create().mapShapes(model) { shape -> if (shape == shapeToBox) { shape.asMemberShape().get().toBuilder().addTrait(RustBoxTrait()).build() Loading
codegen/src/test/kotlin/software/amazon/smithy/rust/testutil/Rust.kt +18 −5 Original line number Diff line number Diff line Loading @@ -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<String>() init { Loading @@ -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 Loading Loading @@ -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() } Loading Loading @@ -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") Loading