@@ -8,58 +8,48 @@ use tar::Archive;
8
8
9
9
const DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
10
10
11
- #[ derive( Debug , Hash , Eq , PartialEq , Clone ) ]
12
- pub ( crate ) enum PkgType {
13
- Rust ,
14
- RustSrc ,
15
- Rustc ,
16
- Cargo ,
17
- Rls ,
18
- RustAnalyzer ,
19
- Clippy ,
20
- Rustfmt ,
21
- LlvmTools ,
22
- Miri ,
23
- JsonDocs ,
24
- Other ( String ) ,
25
- }
26
-
27
- impl PkgType {
28
- pub ( crate ) fn from_component ( component : & str ) -> Self {
29
- match component {
30
- "rust" => PkgType :: Rust ,
31
- "rust-src" => PkgType :: RustSrc ,
32
- "rustc" => PkgType :: Rustc ,
33
- "cargo" => PkgType :: Cargo ,
34
- "rls" | "rls-preview" => PkgType :: Rls ,
35
- "rust-analyzer" | "rust-analyzer-preview" => PkgType :: RustAnalyzer ,
36
- "clippy" | "clippy-preview" => PkgType :: Clippy ,
37
- "rustfmt" | "rustfmt-preview" => PkgType :: Rustfmt ,
38
- "llvm-tools" | "llvm-tools-preview" => PkgType :: LlvmTools ,
39
- "miri" | "miri-preview" => PkgType :: Miri ,
40
- "rust-docs-json" | "rust-docs-json-preview" => PkgType :: JsonDocs ,
41
- other => PkgType :: Other ( other. into ( ) ) ,
11
+ macro_rules! pkg_type {
12
+ ( $( $variant: ident = $component: literal $( ; preview = true $( @$is_preview: tt) ? ) ? ) ,+ $( , ) ? ) => {
13
+ #[ derive( Debug , Hash , Eq , PartialEq , Clone ) ]
14
+ pub ( crate ) enum PkgType {
15
+ $( $variant, ) +
16
+ Other ( String ) ,
42
17
}
43
- }
44
18
45
- /// First part of the tarball name.
46
- fn tarball_component_name ( & self ) -> & str {
47
- match self {
48
- PkgType :: Rust => "rust" ,
49
- PkgType :: RustSrc => "rust-src" ,
50
- PkgType :: Rustc => "rustc" ,
51
- PkgType :: Cargo => "cargo" ,
52
- PkgType :: Rls => "rls" ,
53
- PkgType :: RustAnalyzer => "rust-analyzer" ,
54
- PkgType :: Clippy => "clippy" ,
55
- PkgType :: Rustfmt => "rustfmt" ,
56
- PkgType :: LlvmTools => "llvm-tools" ,
57
- PkgType :: Miri => "miri" ,
58
- PkgType :: JsonDocs => "rust-docs-json" ,
59
- PkgType :: Other ( component ) => component ,
19
+ impl PkgType {
20
+ pub ( crate ) fn from_component ( component : & str ) -> Self {
21
+ match component {
22
+ $ ( $component $ ( | concat! ( $ ( $is_preview ) ? $component , "-preview" ) ) ? => PkgType :: $variant , ) +
23
+ _ => PkgType :: Other ( component . into ( ) ) ,
24
+ }
25
+ }
26
+
27
+ /// First part of the tarball name.
28
+ fn tarball_component_name ( & self ) -> & str {
29
+ match self {
30
+ $ ( PkgType :: $variant => $component , ) +
31
+ PkgType :: Other ( component ) => component ,
32
+ }
33
+ }
60
34
}
61
35
}
36
+ }
62
37
38
+ pkg_type ! {
39
+ Rust = "rust" ,
40
+ RustSrc = "rust-src" ,
41
+ Rustc = "rustc" ,
42
+ Cargo = "cargo" ,
43
+ Rls = "rls" ; preview = true ,
44
+ RustAnalyzer = "rust-analyzer" ; preview = true ,
45
+ Clippy = "clippy" ; preview = true ,
46
+ Rustfmt = "rustfmt" ; preview = true ,
47
+ LlvmTools = "llvm-tools" ; preview = true ,
48
+ Miri = "miri" ; preview = true ,
49
+ JsonDocs = "rust-docs-json" ; preview = true ,
50
+ }
51
+
52
+ impl PkgType {
63
53
/// Whether this package has the same version as Rust itself, or has its own `version` and
64
54
/// `git-commit-hash` files inside the tarball.
65
55
fn should_use_rust_version ( & self ) -> bool {
0 commit comments