]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/xtask/src/flags.rs
Auto merge of #106495 - JohnTitor:issue-100772, r=compiler-errors
[rust.git] / src / tools / rust-analyzer / xtask / src / flags.rs
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 {
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         /// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
38         cmd publish-release-notes {
39             /// Only run conversion and show the result.
40             optional --dry-run
41             /// Target changelog file.
42             required changelog: String
43         }
44         cmd metrics {
45             optional --dry-run
46         }
47         /// Builds a benchmark version of rust-analyzer and puts it into `./target`.
48         cmd bb {
49             required suffix: String
50         }
51     }
52 }
53
54 // generated start
55 // The following code is generated by `xflags` macro.
56 // Run `env UPDATE_XFLAGS=1 cargo build` to regenerate.
57 #[derive(Debug)]
58 pub struct Xtask {
59     pub subcommand: XtaskCmd,
60 }
61
62 #[derive(Debug)]
63 pub enum XtaskCmd {
64     Install(Install),
65     FuzzTests(FuzzTests),
66     Release(Release),
67     Promote(Promote),
68     Dist(Dist),
69     PublishReleaseNotes(PublishReleaseNotes),
70     Metrics(Metrics),
71     Bb(Bb),
72 }
73
74 #[derive(Debug)]
75 pub struct Install {
76     pub client: bool,
77     pub code_bin: Option<String>,
78     pub server: bool,
79     pub mimalloc: bool,
80     pub jemalloc: bool,
81 }
82
83 #[derive(Debug)]
84 pub struct FuzzTests;
85
86 #[derive(Debug)]
87 pub struct Release {
88     pub dry_run: bool,
89 }
90
91 #[derive(Debug)]
92 pub struct Promote {
93     pub dry_run: bool,
94 }
95
96 #[derive(Debug)]
97 pub struct Dist {
98     pub client_patch_version: Option<String>,
99 }
100
101 #[derive(Debug)]
102 pub struct PublishReleaseNotes {
103     pub changelog: String,
104
105     pub dry_run: bool,
106 }
107
108 #[derive(Debug)]
109 pub struct Metrics {
110     pub dry_run: bool,
111 }
112
113 #[derive(Debug)]
114 pub struct Bb {
115     pub suffix: String,
116 }
117
118 impl Xtask {
119     #[allow(dead_code)]
120     pub fn from_env_or_exit() -> Self {
121         Self::from_env_or_exit_()
122     }
123
124     #[allow(dead_code)]
125     pub fn from_env() -> xflags::Result<Self> {
126         Self::from_env_()
127     }
128
129     #[allow(dead_code)]
130     pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
131         Self::from_vec_(args)
132     }
133 }
134 // generated end
135
136 impl Install {
137     pub(crate) fn server(&self) -> Option<ServerOpt> {
138         if self.client && !self.server {
139             return None;
140         }
141         let malloc = if self.mimalloc {
142             Malloc::Mimalloc
143         } else if self.jemalloc {
144             Malloc::Jemalloc
145         } else {
146             Malloc::System
147         };
148         Some(ServerOpt { malloc })
149     }
150     pub(crate) fn client(&self) -> Option<ClientOpt> {
151         if !self.client && self.server {
152             return None;
153         }
154         Some(ClientOpt { code_bin: self.code_bin.clone() })
155     }
156 }