aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/flags.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/flags.rs')
-rw-r--r--xtask/src/flags.rs172
1 files changed, 172 insertions, 0 deletions
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs
new file mode 100644
index 000000000..2ca05d3df
--- /dev/null
+++ b/xtask/src/flags.rs
@@ -0,0 +1,172 @@
1#![allow(unreachable_pub)]
2
3use crate::install::{ClientOpt, Malloc, ServerOpt};
4
5xflags::args_parser! {
6 /// Run custom build command.
7 cmd xtask {
8 default cmd help {
9 /// Print help information.
10 optional -h, --help
11 }
12
13 /// Install rust-analyzer server or editor plugin.
14 cmd install {
15 /// Install only VS Code plugin.
16 optional --client
17 /// One of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'.
18 optional --code-bin name: String
19
20 /// Install only the language server.
21 optional --server
22 /// Use mimalloc allocator for server
23 optional --mimalloc
24 /// Use jemalloc allocator for server
25 optional --jemalloc
26 }
27
28 cmd codegen {
29 optional --features
30 }
31
32 cmd lint {}
33 cmd fuzz-tests {}
34 cmd pre-cache {}
35
36 cmd release {
37 optional --dry-run
38 }
39 cmd promote {
40 optional --dry-run
41 }
42 cmd dist {
43 optional --nightly
44 optional --client version: String
45 }
46 cmd metrics {
47 optional --dry-run
48 }
49 /// Builds a benchmark version of rust-analyzer and puts it into `./target`.
50 cmd bb
51 required suffix: String
52 {}
53 }
54}
55
56// generated start
57// The following code is generated by `xflags` macro.
58// Run `env XFLAGS_DUMP= cargo build` to regenerate.
59#[derive(Debug)]
60pub struct Xtask {
61 pub subcommand: XtaskCmd,
62}
63
64#[derive(Debug)]
65pub enum XtaskCmd {
66 Help(Help),
67 Install(Install),
68 Codegen(Codegen),
69 Lint(Lint),
70 FuzzTests(FuzzTests),
71 PreCache(PreCache),
72 Release(Release),
73 Promote(Promote),
74 Dist(Dist),
75 Metrics(Metrics),
76 Bb(Bb),
77}
78
79#[derive(Debug)]
80pub struct Help {
81 pub help: bool,
82}
83
84#[derive(Debug)]
85pub struct Install {
86 pub client: bool,
87 pub code_bin: Option<String>,
88 pub server: bool,
89 pub mimalloc: bool,
90 pub jemalloc: bool,
91}
92
93#[derive(Debug)]
94pub struct Codegen {
95 pub features: bool,
96}
97
98#[derive(Debug)]
99pub struct Lint {}
100
101#[derive(Debug)]
102pub struct FuzzTests {}
103
104#[derive(Debug)]
105pub struct PreCache {}
106
107#[derive(Debug)]
108pub struct Release {
109 pub dry_run: bool,
110}
111
112#[derive(Debug)]
113pub struct Promote {
114 pub dry_run: bool,
115}
116
117#[derive(Debug)]
118pub struct Dist {
119 pub nightly: bool,
120 pub client: Option<String>,
121}
122
123#[derive(Debug)]
124pub struct Metrics {
125 pub dry_run: bool,
126}
127
128#[derive(Debug)]
129pub struct Bb {
130 pub suffix: String,
131}
132
133impl Xtask {
134 pub const HELP: &'static str = Self::_HELP;
135
136 pub fn from_env() -> xflags::Result<Self> {
137 let mut p = xflags::rt::Parser::new_from_env();
138 Self::_parse(&mut p)
139 }
140}
141// generated end
142
143impl Install {
144 pub(crate) fn validate(&self) -> xflags::Result<()> {
145 if let Some(code_bin) = &self.code_bin {
146 if let Err(err) = code_bin.parse::<ClientOpt>() {
147 return Err(xflags::Error::new(format!("failed to parse `--code-bin`: {}", err)));
148 }
149 }
150 Ok(())
151 }
152 pub(crate) fn server(&self) -> Option<ServerOpt> {
153 if self.client && !self.server {
154 return None;
155 }
156 let malloc = if self.mimalloc {
157 Malloc::Mimalloc
158 } else if self.jemalloc {
159 Malloc::Jemalloc
160 } else {
161 Malloc::System
162 };
163 Some(ServerOpt { malloc })
164 }
165 pub(crate) fn client(&self) -> Option<ClientOpt> {
166 if !self.client && self.server {
167 return None;
168 }
169 let client_opt = self.code_bin.as_ref().and_then(|it| it.parse().ok()).unwrap_or_default();
170 Some(client_opt)
171 }
172}