]> git.proxmox.com Git - rustc.git/blob - src/tools/rust-analyzer/xtask/src/flags.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / rust-analyzer / xtask / src / flags.rs
1 #![allow(unreachable_pub)]
2
3 use std::str::FromStr;
4
5 use crate::install::{ClientOpt, Malloc, ServerOpt};
6
7 xflags::xflags! {
8 src "./src/flags.rs"
9
10 /// Run custom build command.
11 cmd xtask {
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 fuzz-tests {}
29
30 cmd release {
31 optional --dry-run
32 }
33 cmd promote {
34 optional --dry-run
35 }
36 cmd dist {
37 optional --client-patch-version version: String
38 }
39 /// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
40 cmd publish-release-notes {
41 /// Only run conversion and show the result.
42 optional --dry-run
43 /// Target changelog file.
44 required changelog: String
45 }
46 cmd metrics {
47 optional measurement_type: MeasurementType
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 UPDATE_XFLAGS=1 cargo build` to regenerate.
59 #[derive(Debug)]
60 pub struct Xtask {
61 pub subcommand: XtaskCmd,
62 }
63
64 #[derive(Debug)]
65 pub enum XtaskCmd {
66 Install(Install),
67 FuzzTests(FuzzTests),
68 Release(Release),
69 Promote(Promote),
70 Dist(Dist),
71 PublishReleaseNotes(PublishReleaseNotes),
72 Metrics(Metrics),
73 Bb(Bb),
74 }
75
76 #[derive(Debug)]
77 pub struct Install {
78 pub client: bool,
79 pub code_bin: Option<String>,
80 pub server: bool,
81 pub mimalloc: bool,
82 pub jemalloc: bool,
83 }
84
85 #[derive(Debug)]
86 pub struct FuzzTests;
87
88 #[derive(Debug)]
89 pub struct Release {
90 pub dry_run: bool,
91 }
92
93 #[derive(Debug)]
94 pub struct Promote {
95 pub dry_run: bool,
96 }
97
98 #[derive(Debug)]
99 pub struct Dist {
100 pub client_patch_version: Option<String>,
101 }
102
103 #[derive(Debug)]
104 pub struct PublishReleaseNotes {
105 pub changelog: String,
106
107 pub dry_run: bool,
108 }
109
110 #[derive(Debug)]
111 pub enum MeasurementType {
112 Build,
113 AnalyzeSelf,
114 AnalyzeRipgrep,
115 AnalyzeWebRender,
116 AnalyzeDiesel,
117 AnalyzeHyper,
118 }
119
120 impl FromStr for MeasurementType {
121 type Err = String;
122 fn from_str(s: &str) -> Result<Self, Self::Err> {
123 match s {
124 "build" => Ok(Self::Build),
125 "self" => Ok(Self::AnalyzeSelf),
126 "ripgrep-13.0.0" => Ok(Self::AnalyzeRipgrep),
127 "webrender-2022" => Ok(Self::AnalyzeWebRender),
128 "diesel-1.4.8" => Ok(Self::AnalyzeDiesel),
129 "hyper-0.14.18" => Ok(Self::AnalyzeHyper),
130 _ => Err("Invalid option".to_string()),
131 }
132 }
133 }
134 impl AsRef<str> for MeasurementType {
135 fn as_ref(&self) -> &str {
136 match self {
137 Self::Build => "build",
138 Self::AnalyzeSelf => "self",
139 Self::AnalyzeRipgrep => "ripgrep-13.0.0",
140 Self::AnalyzeWebRender => "webrender-2022",
141 Self::AnalyzeDiesel => "diesel-1.4.8",
142 Self::AnalyzeHyper => "hyper-0.14.18",
143 }
144 }
145 }
146
147 #[derive(Debug)]
148 pub struct Metrics {
149 pub measurement_type: Option<MeasurementType>,
150 }
151
152 #[derive(Debug)]
153 pub struct Bb {
154 pub suffix: String,
155 }
156
157 impl Xtask {
158 #[allow(dead_code)]
159 pub fn from_env_or_exit() -> Self {
160 Self::from_env_or_exit_()
161 }
162
163 #[allow(dead_code)]
164 pub fn from_env() -> xflags::Result<Self> {
165 Self::from_env_()
166 }
167
168 #[allow(dead_code)]
169 pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
170 Self::from_vec_(args)
171 }
172 }
173 // generated end
174
175 impl Install {
176 pub(crate) fn server(&self) -> Option<ServerOpt> {
177 if self.client && !self.server {
178 return None;
179 }
180 let malloc = if self.mimalloc {
181 Malloc::Mimalloc
182 } else if self.jemalloc {
183 Malloc::Jemalloc
184 } else {
185 Malloc::System
186 };
187 Some(ServerOpt { malloc })
188 }
189 pub(crate) fn client(&self) -> Option<ClientOpt> {
190 if !self.client && self.server {
191 return None;
192 }
193 Some(ClientOpt { code_bin: self.code_bin.clone() })
194 }
195 }