diff options
author | Seivan Heidari <[email protected]> | 2019-11-14 22:20:27 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-14 22:20:27 +0000 |
commit | c622413bc72ea56d5f62a16788d897cb61eca948 (patch) | |
tree | 9de3dbe8b5c935ed168efac4e70770e54fbe0714 /xtask/src/main.rs | |
parent | 0525778a3ad590492b51cc11085d815f9bb8f92b (diff) | |
parent | bbb022d3999b3038549ec6c309efb065231c896a (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r-- | xtask/src/main.rs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 16bddfb28..f14e6c8ae 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -9,6 +9,7 @@ | |||
9 | //! `.cargo/config`. | 9 | //! `.cargo/config`. |
10 | mod help; | 10 | mod help; |
11 | 11 | ||
12 | use anyhow::Context; | ||
12 | use core::fmt::Write; | 13 | use core::fmt::Write; |
13 | use core::str; | 14 | use core::str; |
14 | use pico_args::Arguments; | 15 | use pico_args::Arguments; |
@@ -19,7 +20,7 @@ use xtask::{ | |||
19 | }; | 20 | }; |
20 | 21 | ||
21 | // Latest stable, feel free to send a PR if this lags behind. | 22 | // Latest stable, feel free to send a PR if this lags behind. |
22 | const REQUIRED_RUST_VERSION: u32 = 38; | 23 | const REQUIRED_RUST_VERSION: u32 = 39; |
23 | 24 | ||
24 | struct InstallOpt { | 25 | struct InstallOpt { |
25 | client: Option<ClientOpt>, | 26 | client: Option<ClientOpt>, |
@@ -113,21 +114,21 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> { | |||
113 | write!(&mut invalid_flags, "{}, ", flag)?; | 114 | write!(&mut invalid_flags, "{}, ", flag)?; |
114 | } | 115 | } |
115 | let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); | 116 | let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); |
116 | Err(format!("Invalid flags: {}", invalid_flags).into()) | 117 | anyhow::bail!("Invalid flags: {}", invalid_flags) |
117 | } else { | 118 | } else { |
118 | Err(e.to_string().into()) | 119 | anyhow::bail!(e.to_string()) |
119 | } | 120 | } |
120 | } | 121 | } |
121 | 122 | ||
122 | fn install(opts: InstallOpt) -> Result<()> { | 123 | fn install(opts: InstallOpt) -> Result<()> { |
123 | if cfg!(target_os = "macos") { | 124 | if cfg!(target_os = "macos") { |
124 | fix_path_for_mac()? | 125 | fix_path_for_mac().context("Fix path for mac")? |
125 | } | 126 | } |
126 | if let Some(server) = opts.server { | 127 | if let Some(server) = opts.server { |
127 | install_server(server)?; | 128 | install_server(server).context("install server")?; |
128 | } | 129 | } |
129 | if let Some(client) = opts.client { | 130 | if let Some(client) = opts.client { |
130 | install_client(client)?; | 131 | install_client(client).context("install client")?; |
131 | } | 132 | } |
132 | Ok(()) | 133 | Ok(()) |
133 | } | 134 | } |
@@ -139,7 +140,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
139 | const ROOT_DIR: &str = ""; | 140 | const ROOT_DIR: &str = ""; |
140 | let home_dir = match env::var("HOME") { | 141 | let home_dir = match env::var("HOME") { |
141 | Ok(home) => home, | 142 | Ok(home) => home, |
142 | Err(e) => Err(format!("Failed getting HOME from environment with error: {}.", e))?, | 143 | Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e), |
143 | }; | 144 | }; |
144 | 145 | ||
145 | [ROOT_DIR, &home_dir] | 146 | [ROOT_DIR, &home_dir] |
@@ -153,12 +154,12 @@ fn fix_path_for_mac() -> Result<()> { | |||
153 | if !vscode_path.is_empty() { | 154 | if !vscode_path.is_empty() { |
154 | let vars = match env::var_os("PATH") { | 155 | let vars = match env::var_os("PATH") { |
155 | Some(path) => path, | 156 | Some(path) => path, |
156 | None => Err("Could not get PATH variable from env.")?, | 157 | None => anyhow::bail!("Could not get PATH variable from env."), |
157 | }; | 158 | }; |
158 | 159 | ||
159 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | 160 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); |
160 | paths.append(&mut vscode_path); | 161 | paths.append(&mut vscode_path); |
161 | let new_paths = env::join_paths(paths)?; | 162 | let new_paths = env::join_paths(paths).context("build env PATH")?; |
162 | env::set_var("PATH", &new_paths); | 163 | env::set_var("PATH", &new_paths); |
163 | } | 164 | } |
164 | 165 | ||
@@ -197,7 +198,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
197 | 198 | ||
198 | let code_binary = match code_binary { | 199 | let code_binary = match code_binary { |
199 | Some(it) => it, | 200 | Some(it) => it, |
200 | None => Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?, | 201 | None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"), |
201 | }; | 202 | }; |
202 | 203 | ||
203 | Cmd { | 204 | Cmd { |
@@ -218,8 +219,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
218 | .run_with_output()?; | 219 | .run_with_output()?; |
219 | 220 | ||
220 | if !str::from_utf8(&output.stdout)?.contains("ra-lsp") { | 221 | if !str::from_utf8(&output.stdout)?.contains("ra-lsp") { |
221 | Err("Could not install the Visual Studio Code extension. \ | 222 | anyhow::bail!( |
222 | Please make sure you have at least NodeJS 10.x installed and try again.")?; | 223 | "Could not install the Visual Studio Code extension. \ |
224 | Please make sure you have at least NodeJS 10.x installed and try again." | ||
225 | ); | ||
223 | } | 226 | } |
224 | 227 | ||
225 | Ok(()) | 228 | Ok(()) |
@@ -239,7 +242,7 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
239 | if old_rust { | 242 | if old_rust { |
240 | eprintln!( | 243 | eprintln!( |
241 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 244 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", |
242 | REQUIRED_RUST_VERSION | 245 | REQUIRED_RUST_VERSION, |
243 | ) | 246 | ) |
244 | } | 247 | } |
245 | 248 | ||
@@ -252,7 +255,7 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
252 | if res.is_err() && old_rust { | 255 | if res.is_err() && old_rust { |
253 | eprintln!( | 256 | eprintln!( |
254 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 257 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", |
255 | REQUIRED_RUST_VERSION | 258 | REQUIRED_RUST_VERSION, |
256 | ) | 259 | ) |
257 | } | 260 | } |
258 | 261 | ||