]> git.lizzy.rs Git - rust.git/commitdiff
Merge #7876
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Fri, 5 Mar 2021 08:52:07 +0000 (08:52 +0000)
committerGitHub <noreply@github.com>
Fri, 5 Mar 2021 08:52:07 +0000 (08:52 +0000)
7876: Cleanup install command r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Cargo.lock
xtask/src/flags.rs
xtask/src/install.rs
xtask/src/main.rs

index 799127891f3226838825b218dbe4c78573176b8b..e8f10b9385e1bed6063afcc8383f3fbee58b7bd5 100644 (file)
@@ -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",
 ]
index 5710fbdb5d56d7899e397e5f680b7eb96dfc4bbc..2ca05d3dfe59092c14affe5e858ca60d30e7e105 100644 (file)
@@ -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 @@ pub fn from_env() -> xflags::Result<Self> {
     }
 }
 // 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::<ClientOpt>() {
+                return Err(xflags::Error::new(format!("failed to parse `--code-bin`: {}", err)));
+            }
+        }
+        Ok(())
+    }
+    pub(crate) fn server(&self) -> Option<ServerOpt> {
+        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<ClientOpt> {
+        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)
+    }
+}
index ea21942485489582a51ae5a466dbf7983a02996b..3e8fbe0a6243ce66f8a9e87e0bf4407194d27db6 100644 (file)
@@ -5,12 +5,24 @@
 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<ClientOpt>,
-    pub(crate) server: Option<ServerOpt>,
+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<PathBuf> = {
         const COMMON_APP_PATH: &str =
index e419db7a717f94dabd1ca7a3556fe39050678a6d..ca27b6cec4d749c83a2075390f3dd4ccb8845c44 100644 (file)
 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 { client_bin },
-                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(),