diff options
author | Aleksey Kladov <[email protected]> | 2020-02-14 14:06:10 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-14 14:10:49 +0000 |
commit | 52dcf3243e979bed92413108864a62bad7b83f15 (patch) | |
tree | caed68c18c1d43279b22a7f4a19b850976a64ee5 | |
parent | a19f52f9ae1634fa2267c3bc7647a0d47b6014ac (diff) |
Minor
-rw-r--r-- | xtask/src/install.rs | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 99e1eddb1..a279598b9 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use std::{env, path::PathBuf, str}; | 3 | use std::{env, path::PathBuf, str}; |
4 | 4 | ||
5 | use anyhow::{Context, Result}; | 5 | use anyhow::{bail, format_err, Context, Result}; |
6 | 6 | ||
7 | use crate::cmd::{run, run_with_output, Cmd}; | 7 | use crate::cmd::{run, run_with_output, Cmd}; |
8 | 8 | ||
@@ -55,7 +55,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
55 | const ROOT_DIR: &str = ""; | 55 | const ROOT_DIR: &str = ""; |
56 | let home_dir = match env::var("HOME") { | 56 | let home_dir = match env::var("HOME") { |
57 | Ok(home) => home, | 57 | Ok(home) => home, |
58 | Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e), | 58 | Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), |
59 | }; | 59 | }; |
60 | 60 | ||
61 | [ROOT_DIR, &home_dir] | 61 | [ROOT_DIR, &home_dir] |
@@ -69,7 +69,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
69 | if !vscode_path.is_empty() { | 69 | if !vscode_path.is_empty() { |
70 | let vars = match env::var_os("PATH") { | 70 | let vars = match env::var_os("PATH") { |
71 | Some(path) => path, | 71 | Some(path) => path, |
72 | None => anyhow::bail!("Could not get PATH variable from env."), | 72 | None => bail!("Could not get PATH variable from env."), |
73 | }; | 73 | }; |
74 | 74 | ||
75 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | 75 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); |
@@ -90,7 +90,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
90 | .run(); | 90 | .run(); |
91 | 91 | ||
92 | if npm_version.is_err() { | 92 | if npm_version.is_err() { |
93 | eprintln!("\nERROR: `npm --version` failed, `npm` is required to build the VS Code plugin") | 93 | bail!("`npm --version` failed, `npm` is required to build the VS Code plugin") |
94 | } | 94 | } |
95 | 95 | ||
96 | Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" } | 96 | Cmd { unix: r"npm install", windows: r"cmd.exe /c npm install", work_dir: "./editors/code" } |
@@ -102,20 +102,20 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
102 | } | 102 | } |
103 | .run()?; | 103 | .run()?; |
104 | 104 | ||
105 | let code_binary = ["code", "code-insiders", "codium", "code-oss"].iter().find(|bin| { | 105 | let code_binary = ["code", "code-insiders", "codium", "code-oss"] |
106 | Cmd { | 106 | .iter() |
107 | unix: &format!("{} --version", bin), | 107 | .find(|bin| { |
108 | windows: &format!("cmd.exe /c {}.cmd --version", bin), | 108 | Cmd { |
109 | work_dir: "./editors/code", | 109 | unix: &format!("{} --version", bin), |
110 | } | 110 | windows: &format!("cmd.exe /c {}.cmd --version", bin), |
111 | .run() | 111 | work_dir: "./editors/code", |
112 | .is_ok() | 112 | } |
113 | }); | 113 | .run() |
114 | 114 | .is_ok() | |
115 | let code_binary = match code_binary { | 115 | }) |
116 | Some(it) => it, | 116 | .ok_or_else(|| { |
117 | None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"), | 117 | format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") |
118 | }; | 118 | })?; |
119 | 119 | ||
120 | Cmd { | 120 | Cmd { |
121 | unix: &format!(r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force", code_binary), | 121 | unix: &format!(r"{} --install-extension ./rust-analyzer-0.1.0.vsix --force", code_binary), |
@@ -135,24 +135,12 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
135 | .run_with_output()?; | 135 | .run_with_output()?; |
136 | 136 | ||
137 | if !installed_extensions.contains("rust-analyzer") { | 137 | if !installed_extensions.contains("rust-analyzer") { |
138 | anyhow::bail!( | 138 | bail!( |
139 | "Could not install the Visual Studio Code extension. \ | 139 | "Could not install the Visual Studio Code extension. \ |
140 | Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again." | 140 | Please make sure you have at least NodeJS 10.x together with the latest version of VS Code installed and try again." |
141 | ); | 141 | ); |
142 | } | 142 | } |
143 | 143 | ||
144 | if installed_extensions.contains("ra-lsp") { | ||
145 | Cmd { | ||
146 | unix: &format!(r"{} --uninstall-extension matklad.ra-lsp", code_binary), | ||
147 | windows: &format!( | ||
148 | r"cmd.exe /c {}.cmd --uninstall-extension matklad.ra-lsp", | ||
149 | code_binary | ||
150 | ), | ||
151 | work_dir: "./editors/code", | ||
152 | } | ||
153 | .run()?; | ||
154 | } | ||
155 | |||
156 | Ok(()) | 144 | Ok(()) |
157 | } | 145 | } |
158 | 146 | ||