From 4add629de44c62a2182d6a3af86e8dff2fd88f2a Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Mon, 6 Nov 2023 13:56:06 -0600 Subject: [PATCH] Verify places managing crates stabilities are in sync This commit addresses https://github.com/awslabs/smithy-rs/pull/3082#discussion_r1378629003 --- buildSrc/src/main/kotlin/CrateSet.kt | 6 +- buildSrc/src/test/kotlin/CrateSetTest.kt | 72 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 buildSrc/src/test/kotlin/CrateSetTest.kt diff --git a/buildSrc/src/main/kotlin/CrateSet.kt b/buildSrc/src/main/kotlin/CrateSet.kt index 6b6b1f9d46..d8a95838e6 100644 --- a/buildSrc/src/main/kotlin/CrateSet.kt +++ b/buildSrc/src/main/kotlin/CrateSet.kt @@ -7,7 +7,7 @@ data class Crate(val name: String, val versionPropertyName: String) object CrateSet { const val STABLE_VERSION_PROP_NAME = "smithy.rs.runtime.crate.stable.version" - private const val UNSTABLE_VERSION_PROP_NAME = "smithy.rs.runtime.crate.unstable.version" + const val UNSTABLE_VERSION_PROP_NAME = "smithy.rs.runtime.crate.unstable.version" /* * Crates marked as `STABLE_VERSION_PROP_NAME` should have the following package metadata in their `Cargo.toml` @@ -29,7 +29,7 @@ object CrateSet { Crate("aws-types", STABLE_VERSION_PROP_NAME), ) - private val SMITHY_RUNTIME_COMMON = listOf( + val SMITHY_RUNTIME_COMMON = listOf( Crate("aws-smithy-async", STABLE_VERSION_PROP_NAME), Crate("aws-smithy-checksums", UNSTABLE_VERSION_PROP_NAME), Crate("aws-smithy-client", UNSTABLE_VERSION_PROP_NAME), @@ -49,7 +49,7 @@ object CrateSet { val AWS_SDK_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON - private val SERVER_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON + listOf( + val SERVER_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON + listOf( Crate("aws-smithy-http-server", UNSTABLE_VERSION_PROP_NAME), Crate("aws-smithy-http-server-python", UNSTABLE_VERSION_PROP_NAME), Crate("aws-smithy-http-server-typescript", UNSTABLE_VERSION_PROP_NAME), diff --git a/buildSrc/src/test/kotlin/CrateSetTest.kt b/buildSrc/src/test/kotlin/CrateSetTest.kt new file mode 100644 index 0000000000..59b1c82551 --- /dev/null +++ b/buildSrc/src/test/kotlin/CrateSetTest.kt @@ -0,0 +1,72 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import CrateSet.AWS_SDK_RUNTIME +import CrateSet.SERVER_SMITHY_RUNTIME +import CrateSet.SMITHY_RUNTIME_COMMON +import CrateSet.STABLE_VERSION_PROP_NAME +import CrateSet.UNSTABLE_VERSION_PROP_NAME +import com.moandjiezana.toml.Toml +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import java.io.File +import java.util.logging.Logger + +class CrateSetTest { + private val logger: Logger = Logger.getLogger("CrateSetTest") + + /* + * Checks whether `versionPropertyName` for a system under test, i.e. `Crate` in `CrateSet.kt`, + * matches what `package.metadata.smithy-rs-release-tooling` says in the `Cargo.toml` + * for the corresponding crate. + */ + private fun sutStabilityMatchesManifestStability(versionPropertyName: String, stabilityInManifest: Boolean) { + when (stabilityInManifest) { + true -> assertEquals(STABLE_VERSION_PROP_NAME, versionPropertyName) + false -> assertEquals(UNSTABLE_VERSION_PROP_NAME, versionPropertyName) + } + } + + /* + * Checks whether each element in `crateSet` specifies the correct `versionPropertyName` according to + * what `package.metadata.smithy-rs-release-tooling` says in the `Cargo.toml` for the corresponding crate, + * located at `relativePathToRustRuntime`. + * + * If `package.metadata.smithy-rs-release-tooling` does not exist in a `Cargo.toml`, the implementation + * will treat that crate as unstable. + */ + private fun crateSetStabilitiesMatchManifestStabilities(crateSet: List, relativePathToRustRuntime: String) { + crateSet.forEach { + val path = "$relativePathToRustRuntime/${it.name}/Cargo.toml" + val contents = File(path).readText() + val manifest = try { + Toml().read(contents) + } catch (e: java.lang.IllegalStateException) { + // Currently, `aws-sigv4` cannot be read as a `TOML` because of the following error: + // Invalid table definition on line 54: [target.'cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))'.dev-dependencies]] + logger.info("failed to read ${it.name} as TOML: $e") + Toml() + } + manifest.getTable("package.metadata.smithy-rs-release-tooling")?.entrySet()?.map { entry -> + sutStabilityMatchesManifestStability(it.versionPropertyName, entry.value as Boolean) + } ?: sutStabilityMatchesManifestStability(it.versionPropertyName, false) + } + } + + @Test + fun `aws runtime stabilities should match those in manifest files`() { + crateSetStabilitiesMatchManifestStabilities(AWS_SDK_RUNTIME, "../aws/rust-runtime") + } + + @Test + fun `common smithy runtime stabilities should match those in manifest files`() { + crateSetStabilitiesMatchManifestStabilities(SMITHY_RUNTIME_COMMON, "../rust-runtime") + } + + @Test + fun `server smithy runtime stabilities should match those in manifest files`() { + crateSetStabilitiesMatchManifestStabilities(SERVER_SMITHY_RUNTIME, "../rust-runtime") + } +}