From 97b1550ddaf9599dada343aa960de02f0a06de2e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 5 Mar 2021 11:12:40 +0300 Subject: Fix regression where the client was not installed --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e419db7a7..130867e23 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -63,7 +63,7 @@ fn main() -> Result<()> { let client_bin = flags.code_bin.map(|it| it.parse()).transpose()?; InstallCmd { - client: if flags.server { None } else { client_bin }, + client: if flags.server { None } else { Some(client_bin).unwrap_or_default() }, server: if flags.client { None } else { Some(ServerOpt { malloc }) }, } .run() -- cgit v1.2.3 From 142f9a03fd4bad366439b18d8de7f2237bed65ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 5 Mar 2021 11:51:32 +0300 Subject: Cleanup install command --- Cargo.lock | 8 ++++---- xtask/src/flags.rs | 33 +++++++++++++++++++++++++++++++++ xtask/src/install.rs | 33 +++++++++++++++------------------ 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" [[package]] name = "xflags" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddb4b07c0db813f8e2b5e1b2189ef56fcddb27a6f9ef71314dbf8cc50096a5db" +checksum = "222e914b43cec5d7305ac5116d10a14b3a52c50e9062d642c92631f3beabc729" dependencies = [ "xflags-macros", ] [[package]] name = "xflags-macros" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8e168a99d6ce9d5dd0d0913f1bded279377843952dd8ff83f81b862a1dad0e1" +checksum = "52f18f5b4aa7f95e209d5b9274f6164c3938920b4d5c75f97f0dd16daee25ddd" dependencies = [ "proc-macro2", ] 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 @@ #![allow(unreachable_pub)] +use crate::install::{ClientOpt, Malloc, ServerOpt}; + xflags::args_parser! { /// Run custom build command. cmd xtask { @@ -137,3 +139,34 @@ impl Xtask { } } // generated end + +impl Install { + pub(crate) fn validate(&self) -> xflags::Result<()> { + if let Some(code_bin) = &self.code_bin { + if let Err(err) = code_bin.parse::() { + return Err(xflags::Error::new(format!("failed to parse `--code-bin`: {}", err))); + } + } + Ok(()) + } + pub(crate) fn server(&self) -> Option { + if self.client && !self.server { + return None; + } + let malloc = if self.mimalloc { + Malloc::Mimalloc + } else if self.jemalloc { + Malloc::Jemalloc + } else { + Malloc::System + }; + Some(ServerOpt { malloc }) + } + pub(crate) fn client(&self) -> Option { + if !self.client && self.server { + return None; + } + let client_opt = self.code_bin.as_ref().and_then(|it| it.parse().ok()).unwrap_or_default(); + Some(client_opt) + } +} 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}; use anyhow::{bail, format_err, Context, Result}; use xshell::{cmd, pushd}; +use crate::flags; + // Latest stable, feel free to send a PR if this lags behind. const REQUIRED_RUST_VERSION: u32 = 50; -pub(crate) struct InstallCmd { - pub(crate) client: Option, - pub(crate) server: Option, +impl flags::Install { + pub(crate) fn run(self) -> Result<()> { + if cfg!(target_os = "macos") { + fix_path_for_mac().context("Fix path for mac")? + } + if let Some(server) = self.server() { + install_server(server).context("install server")?; + } + if let Some(client) = self.client() { + install_client(client).context("install client")?; + } + Ok(()) + } } #[derive(Clone, Copy)] @@ -70,21 +82,6 @@ pub(crate) enum Malloc { Jemalloc, } -impl InstallCmd { - pub(crate) fn run(self) -> Result<()> { - if cfg!(target_os = "macos") { - fix_path_for_mac().context("Fix path for mac")? - } - if let Some(server) = self.server { - install_server(server).context("install server")?; - } - if let Some(client) = self.client { - install_client(client).context("install client")?; - } - Ok(()) - } -} - fn fix_path_for_mac() -> Result<()> { let mut vscode_path: Vec = { const COMMON_APP_PATH: &str = diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 130867e23..ca27b6cec 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -28,11 +28,7 @@ use std::{ use walkdir::{DirEntry, WalkDir}; use xshell::{cmd, cp, pushd, pushenv}; -use crate::{ - codegen::Mode, - dist::DistCmd, - install::{InstallCmd, Malloc, ServerOpt}, -}; +use crate::{codegen::Mode, dist::DistCmd}; fn main() -> Result<()> { let _d = pushd(project_root())?; @@ -43,30 +39,9 @@ fn main() -> Result<()> { println!("{}", flags::Xtask::HELP); return Ok(()); } - flags::XtaskCmd::Install(flags) => { - if flags.server && flags.client { - eprintln!( - "error: The argument `--server` cannot be used with `--client`\n\n\ - For more information try --help" - ); - return Ok(()); - } - - let malloc = if flags.mimalloc { - Malloc::Mimalloc - } else if flags.jemalloc { - Malloc::Jemalloc - } else { - Malloc::System - }; - - let client_bin = flags.code_bin.map(|it| it.parse()).transpose()?; - - InstallCmd { - client: if flags.server { None } else { Some(client_bin).unwrap_or_default() }, - server: if flags.client { None } else { Some(ServerOpt { malloc }) }, - } - .run() + flags::XtaskCmd::Install(cmd) => { + cmd.validate()?; + cmd.run() } flags::XtaskCmd::Codegen(cmd) => cmd.run(), flags::XtaskCmd::Lint(_) => run_clippy(), -- cgit v1.2.3