about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jnelson@cloudflare.com>2022-10-01 23:42:21 -0500
committerJoshua Nelson <jnelson@cloudflare.com>2022-10-27 12:16:15 -0500
commit494cb47852ef7bb2cc14f1f440d77722bf0f759b (patch)
treec380f8efb79b5968f42e460275b091167ba90aca
parent79e86e3ea067cf531d728fb15652e4fa76f54b63 (diff)
downloadrust-494cb47852ef7bb2cc14f1f440d77722bf0f759b.tar.gz
rust-494cb47852ef7bb2cc14f1f440d77722bf0f759b.zip
build-manifest: Add a macro that makes it impossible to typo `-preview`, or have a mismatch between parsing and stringifying
-rw-r--r--src/tools/build-manifest/src/versions.rs84
1 files changed, 37 insertions, 47 deletions
diff --git a/src/tools/build-manifest/src/versions.rs b/src/tools/build-manifest/src/versions.rs
index 0186194a41f..61e8825753c 100644
--- a/src/tools/build-manifest/src/versions.rs
+++ b/src/tools/build-manifest/src/versions.rs
@@ -8,58 +8,48 @@ use tar::Archive;
 
 const DEFAULT_TARGET: &str = "x86_64-unknown-linux-gnu";
 
-#[derive(Debug, Hash, Eq, PartialEq, Clone)]
-pub(crate) enum PkgType {
-    Rust,
-    RustSrc,
-    Rustc,
-    Cargo,
-    Rls,
-    RustAnalyzer,
-    Clippy,
-    Rustfmt,
-    LlvmTools,
-    Miri,
-    JsonDocs,
-    Other(String),
-}
-
-impl PkgType {
-    pub(crate) fn from_component(component: &str) -> Self {
-        match component {
-            "rust" => PkgType::Rust,
-            "rust-src" => PkgType::RustSrc,
-            "rustc" => PkgType::Rustc,
-            "cargo" => PkgType::Cargo,
-            "rls" | "rls-preview" => PkgType::Rls,
-            "rust-analyzer" | "rust-analyzer-preview" => PkgType::RustAnalyzer,
-            "clippy" | "clippy-preview" => PkgType::Clippy,
-            "rustfmt" | "rustfmt-preview" => PkgType::Rustfmt,
-            "llvm-tools" | "llvm-tools-preview" => PkgType::LlvmTools,
-            "miri" | "miri-preview" => PkgType::Miri,
-            "rust-docs-json" | "rust-docs-json-preview" => PkgType::JsonDocs,
-            other => PkgType::Other(other.into()),
+macro_rules! pkg_type {
+    ( $($variant:ident = $component:literal $(; preview = true $(@$is_preview:tt)? )? ),+ $(,)? ) => {
+        #[derive(Debug, Hash, Eq, PartialEq, Clone)]
+        pub(crate) enum PkgType {
+            $($variant,)+
+            Other(String),
         }
-    }
 
-    /// First part of the tarball name.
-    fn tarball_component_name(&self) -> &str {
-        match self {
-            PkgType::Rust => "rust",
-            PkgType::RustSrc => "rust-src",
-            PkgType::Rustc => "rustc",
-            PkgType::Cargo => "cargo",
-            PkgType::Rls => "rls",
-            PkgType::RustAnalyzer => "rust-analyzer",
-            PkgType::Clippy => "clippy",
-            PkgType::Rustfmt => "rustfmt",
-            PkgType::LlvmTools => "llvm-tools",
-            PkgType::Miri => "miri",
-            PkgType::JsonDocs => "rust-docs-json",
-            PkgType::Other(component) => component,
+        impl PkgType {
+            pub(crate) fn from_component(component: &str) -> Self {
+                match component {
+                    $( $component  $( | concat!($($is_preview)? $component, "-preview") )? => PkgType::$variant,)+
+                    _ => PkgType::Other(component.into()),
+                }
+            }
+
+            /// First part of the tarball name.
+            fn tarball_component_name(&self) -> &str {
+                match self {
+                    $( PkgType::$variant => $component,)+
+                    PkgType::Other(component) => component,
+                }
+            }
         }
     }
+}
 
+pkg_type! {
+    Rust = "rust",
+    RustSrc = "rust-src",
+    Rustc = "rustc",
+    Cargo = "cargo",
+    Rls = "rls"; preview = true,
+    RustAnalyzer = "rust-analyzer"; preview = true,
+    Clippy = "clippy"; preview = true,
+    Rustfmt = "rustfmt"; preview = true,
+    LlvmTools = "llvm-tools"; preview = true,
+    Miri = "miri"; preview = true,
+    JsonDocs = "rust-docs-json"; preview = true,
+}
+
+impl PkgType {
     /// Whether this package has the same version as Rust itself, or has its own `version` and
     /// `git-commit-hash` files inside the tarball.
     fn should_use_rust_version(&self) -> bool {