diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-05 08:52:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-05 08:52:07 +0000 |
commit | 9707acb59b3f1f74bcc2f806ea5eab59279fad5e (patch) | |
tree | d57e4695c79e7485a1295adac9a2aafa20e9a3df | |
parent | 16a76aa158d0898d6a46d7bba7310150555a69b9 (diff) | |
parent | 142f9a03fd4bad366439b18d8de7f2237bed65ab (diff) |
Merge #7876
7876: Cleanup install command r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | Cargo.lock | 8 | ||||
-rw-r--r-- | xtask/src/flags.rs | 33 | ||||
-rw-r--r-- | xtask/src/install.rs | 33 | ||||
-rw-r--r-- | xtask/src/main.rs | 33 |
4 files changed, 56 insertions, 51 deletions
diff --git a/Cargo.lock b/Cargo.lock index 799127891..e8f10b938 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1919,18 +1919,18 @@ checksum = "06069a848f95fceae3e5e03c0ddc8cb78452b56654ee0c8e68f938cf790fb9e3" | |||
1919 | 1919 | ||
1920 | [[package]] | 1920 | [[package]] |
1921 | name = "xflags" | 1921 | name = "xflags" |
1922 | version = "0.1.3" | 1922 | version = "0.1.4" |
1923 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1923 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1924 | checksum = "ddb4b07c0db813f8e2b5e1b2189ef56fcddb27a6f9ef71314dbf8cc50096a5db" | 1924 | checksum = "222e914b43cec5d7305ac5116d10a14b3a52c50e9062d642c92631f3beabc729" |
1925 | dependencies = [ | 1925 | dependencies = [ |
1926 | "xflags-macros", | 1926 | "xflags-macros", |
1927 | ] | 1927 | ] |
1928 | 1928 | ||
1929 | [[package]] | 1929 | [[package]] |
1930 | name = "xflags-macros" | 1930 | name = "xflags-macros" |
1931 | version = "0.1.3" | 1931 | version = "0.1.4" |
1932 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1932 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1933 | checksum = "f8e168a99d6ce9d5dd0d0913f1bded279377843952dd8ff83f81b862a1dad0e1" | 1933 | checksum = "52f18f5b4aa7f95e209d5b9274f6164c3938920b4d5c75f97f0dd16daee25ddd" |
1934 | dependencies = [ | 1934 | dependencies = [ |
1935 | "proc-macro2", | 1935 | "proc-macro2", |
1936 | ] | 1936 | ] |
diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs index 5710fbdb5..2ca05d3df 100644 --- a/xtask/src/flags.rs +++ b/xtask/src/flags.rs | |||
@@ -1,5 +1,7 @@ | |||
1 | #![allow(unreachable_pub)] | 1 | #![allow(unreachable_pub)] |
2 | 2 | ||
3 | use crate::install::{ClientOpt, Malloc, ServerOpt}; | ||
4 | |||
3 | xflags::args_parser! { | 5 | xflags::args_parser! { |
4 | /// Run custom build command. | 6 | /// Run custom build command. |
5 | cmd xtask { | 7 | cmd xtask { |
@@ -137,3 +139,34 @@ impl Xtask { | |||
137 | } | 139 | } |
138 | } | 140 | } |
139 | // generated end | 141 | // generated end |
142 | |||
143 | impl 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 | } | ||
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index ea2194248..3e8fbe0a6 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -5,12 +5,24 @@ use std::{env, path::PathBuf, str}; | |||
5 | use anyhow::{bail, format_err, Context, Result}; | 5 | use anyhow::{bail, format_err, Context, Result}; |
6 | use xshell::{cmd, pushd}; | 6 | use xshell::{cmd, pushd}; |
7 | 7 | ||
8 | use crate::flags; | ||
9 | |||
8 | // Latest stable, feel free to send a PR if this lags behind. | 10 | // Latest stable, feel free to send a PR if this lags behind. |
9 | const REQUIRED_RUST_VERSION: u32 = 50; | 11 | const REQUIRED_RUST_VERSION: u32 = 50; |
10 | 12 | ||
11 | pub(crate) struct InstallCmd { | 13 | impl flags::Install { |
12 | pub(crate) client: Option<ClientOpt>, | 14 | pub(crate) fn run(self) -> Result<()> { |
13 | pub(crate) server: Option<ServerOpt>, | 15 | if cfg!(target_os = "macos") { |
16 | fix_path_for_mac().context("Fix path for mac")? | ||
17 | } | ||
18 | if let Some(server) = self.server() { | ||
19 | install_server(server).context("install server")?; | ||
20 | } | ||
21 | if let Some(client) = self.client() { | ||
22 | install_client(client).context("install client")?; | ||
23 | } | ||
24 | Ok(()) | ||
25 | } | ||
14 | } | 26 | } |
15 | 27 | ||
16 | #[derive(Clone, Copy)] | 28 | #[derive(Clone, Copy)] |
@@ -70,21 +82,6 @@ pub(crate) enum Malloc { | |||
70 | Jemalloc, | 82 | Jemalloc, |
71 | } | 83 | } |
72 | 84 | ||
73 | impl InstallCmd { | ||
74 | pub(crate) fn run(self) -> Result<()> { | ||
75 | if cfg!(target_os = "macos") { | ||
76 | fix_path_for_mac().context("Fix path for mac")? | ||
77 | } | ||
78 | if let Some(server) = self.server { | ||
79 | install_server(server).context("install server")?; | ||
80 | } | ||
81 | if let Some(client) = self.client { | ||
82 | install_client(client).context("install client")?; | ||
83 | } | ||
84 | Ok(()) | ||
85 | } | ||
86 | } | ||
87 | |||
88 | fn fix_path_for_mac() -> Result<()> { | 85 | fn fix_path_for_mac() -> Result<()> { |
89 | let mut vscode_path: Vec<PathBuf> = { | 86 | let mut vscode_path: Vec<PathBuf> = { |
90 | const COMMON_APP_PATH: &str = | 87 | const COMMON_APP_PATH: &str = |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e419db7a7..ca27b6cec 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -28,11 +28,7 @@ use std::{ | |||
28 | use walkdir::{DirEntry, WalkDir}; | 28 | use walkdir::{DirEntry, WalkDir}; |
29 | use xshell::{cmd, cp, pushd, pushenv}; | 29 | use xshell::{cmd, cp, pushd, pushenv}; |
30 | 30 | ||
31 | use crate::{ | 31 | use crate::{codegen::Mode, dist::DistCmd}; |
32 | codegen::Mode, | ||
33 | dist::DistCmd, | ||
34 | install::{InstallCmd, Malloc, ServerOpt}, | ||
35 | }; | ||
36 | 32 | ||
37 | fn main() -> Result<()> { | 33 | fn main() -> Result<()> { |
38 | let _d = pushd(project_root())?; | 34 | let _d = pushd(project_root())?; |
@@ -43,30 +39,9 @@ fn main() -> Result<()> { | |||
43 | println!("{}", flags::Xtask::HELP); | 39 | println!("{}", flags::Xtask::HELP); |
44 | return Ok(()); | 40 | return Ok(()); |
45 | } | 41 | } |
46 | flags::XtaskCmd::Install(flags) => { | 42 | flags::XtaskCmd::Install(cmd) => { |
47 | if flags.server && flags.client { | 43 | cmd.validate()?; |
48 | eprintln!( | 44 | cmd.run() |
49 | "error: The argument `--server` cannot be used with `--client`\n\n\ | ||
50 | For more information try --help" | ||
51 | ); | ||
52 | return Ok(()); | ||
53 | } | ||
54 | |||
55 | let malloc = if flags.mimalloc { | ||
56 | Malloc::Mimalloc | ||
57 | } else if flags.jemalloc { | ||
58 | Malloc::Jemalloc | ||
59 | } else { | ||
60 | Malloc::System | ||
61 | }; | ||
62 | |||
63 | let client_bin = flags.code_bin.map(|it| it.parse()).transpose()?; | ||
64 | |||
65 | InstallCmd { | ||
66 | client: if flags.server { None } else { client_bin }, | ||
67 | server: if flags.client { None } else { Some(ServerOpt { malloc }) }, | ||
68 | } | ||
69 | .run() | ||
70 | } | 45 | } |
71 | flags::XtaskCmd::Codegen(cmd) => cmd.run(), | 46 | flags::XtaskCmd::Codegen(cmd) => cmd.run(), |
72 | flags::XtaskCmd::Lint(_) => run_clippy(), | 47 | flags::XtaskCmd::Lint(_) => run_clippy(), |