]>
Commit | Line | Data |
---|---|---|
064997fb FG |
1 | #![allow(unreachable_pub)] |
2 | ||
3 | use crate::install::{ClientOpt, Malloc, ServerOpt}; | |
4 | ||
5 | xflags::xflags! { | |
6 | src "./src/flags.rs" | |
7 | ||
8 | /// Run custom build command. | |
9 | cmd xtask { | |
064997fb FG |
10 | |
11 | /// Install rust-analyzer server or editor plugin. | |
12 | cmd install { | |
13 | /// Install only VS Code plugin. | |
14 | optional --client | |
15 | /// One of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'. | |
16 | optional --code-bin name: String | |
17 | ||
18 | /// Install only the language server. | |
19 | optional --server | |
20 | /// Use mimalloc allocator for server | |
21 | optional --mimalloc | |
22 | /// Use jemalloc allocator for server | |
23 | optional --jemalloc | |
24 | } | |
25 | ||
26 | cmd fuzz-tests {} | |
27 | ||
28 | cmd release { | |
29 | optional --dry-run | |
30 | } | |
31 | cmd promote { | |
32 | optional --dry-run | |
33 | } | |
34 | cmd dist { | |
35 | optional --client-patch-version version: String | |
36 | } | |
37 | cmd metrics { | |
38 | optional --dry-run | |
39 | } | |
40 | /// Builds a benchmark version of rust-analyzer and puts it into `./target`. | |
2b03887a | 41 | cmd bb { |
064997fb | 42 | required suffix: String |
2b03887a | 43 | } |
064997fb FG |
44 | } |
45 | } | |
46 | ||
47 | // generated start | |
48 | // The following code is generated by `xflags` macro. | |
49 | // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate. | |
50 | #[derive(Debug)] | |
51 | pub struct Xtask { | |
52 | pub subcommand: XtaskCmd, | |
53 | } | |
54 | ||
55 | #[derive(Debug)] | |
56 | pub enum XtaskCmd { | |
064997fb FG |
57 | Install(Install), |
58 | FuzzTests(FuzzTests), | |
59 | Release(Release), | |
60 | Promote(Promote), | |
61 | Dist(Dist), | |
62 | Metrics(Metrics), | |
63 | Bb(Bb), | |
64 | } | |
65 | ||
064997fb FG |
66 | #[derive(Debug)] |
67 | pub struct Install { | |
68 | pub client: bool, | |
69 | pub code_bin: Option<String>, | |
70 | pub server: bool, | |
71 | pub mimalloc: bool, | |
72 | pub jemalloc: bool, | |
73 | } | |
74 | ||
75 | #[derive(Debug)] | |
76 | pub struct FuzzTests; | |
77 | ||
78 | #[derive(Debug)] | |
79 | pub struct Release { | |
80 | pub dry_run: bool, | |
81 | } | |
82 | ||
83 | #[derive(Debug)] | |
84 | pub struct Promote { | |
85 | pub dry_run: bool, | |
86 | } | |
87 | ||
88 | #[derive(Debug)] | |
89 | pub struct Dist { | |
90 | pub client_patch_version: Option<String>, | |
91 | } | |
92 | ||
93 | #[derive(Debug)] | |
94 | pub struct Metrics { | |
95 | pub dry_run: bool, | |
96 | } | |
97 | ||
98 | #[derive(Debug)] | |
99 | pub struct Bb { | |
100 | pub suffix: String, | |
101 | } | |
102 | ||
103 | impl Xtask { | |
2b03887a FG |
104 | #[allow(dead_code)] |
105 | pub fn from_env_or_exit() -> Self { | |
106 | Self::from_env_or_exit_() | |
107 | } | |
064997fb FG |
108 | |
109 | #[allow(dead_code)] | |
110 | pub fn from_env() -> xflags::Result<Self> { | |
111 | Self::from_env_() | |
112 | } | |
113 | ||
114 | #[allow(dead_code)] | |
115 | pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> { | |
116 | Self::from_vec_(args) | |
117 | } | |
118 | } | |
119 | // generated end | |
120 | ||
121 | impl Install { | |
122 | pub(crate) fn server(&self) -> Option<ServerOpt> { | |
123 | if self.client && !self.server { | |
124 | return None; | |
125 | } | |
126 | let malloc = if self.mimalloc { | |
127 | Malloc::Mimalloc | |
128 | } else if self.jemalloc { | |
129 | Malloc::Jemalloc | |
130 | } else { | |
131 | Malloc::System | |
132 | }; | |
133 | Some(ServerOpt { malloc }) | |
134 | } | |
135 | pub(crate) fn client(&self) -> Option<ClientOpt> { | |
136 | if !self.client && self.server { | |
137 | return None; | |
138 | } | |
139 | Some(ClientOpt { code_bin: self.code_bin.clone() }) | |
140 | } | |
141 | } |