Unverified Commit eca86039 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Upgrade Smithy & Kotlin to latest (#82)

* Upgrade to Kotlin 1.4

* Upgrade Smithy version, fix some deprecations
parent fe6a56fc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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']
+1 −1
Original line number Diff line number Diff line
@@ -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)
}

/**
+2 −1
Original line number Diff line number Diff line
@@ -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),
+1 −1
Original line number Diff line number Diff line
@@ -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()
+18 −5
Original line number Diff line number Diff line
@@ -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 {
@@ -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")
Loading