diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/Cargo.toml | 1 | ||||
-rw-r--r-- | xtask/src/main.rs | 35 |
2 files changed, 11 insertions, 25 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 023f6a859..72b39c3b4 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml | |||
@@ -6,6 +6,7 @@ authors = ["rust-analyzer developers"] | |||
6 | publish = false | 6 | publish = false |
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | autocfg = "0.1" | ||
9 | walkdir = "2.1.3" | 10 | walkdir = "2.1.3" |
10 | pico-args = "0.3.0" | 11 | pico-args = "0.3.0" |
11 | quote = "1.0.2" | 12 | quote = "1.0.2" |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c46eaa407..576ba003a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -9,17 +9,18 @@ | |||
9 | //! `.cargo/config`. | 9 | //! `.cargo/config`. |
10 | mod help; | 10 | mod help; |
11 | 11 | ||
12 | use autocfg; | ||
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; |
15 | use std::{env, path::PathBuf}; | 16 | use std::{env, path::PathBuf}; |
16 | use xtask::{ | 17 | use xtask::{ |
17 | codegen::{self, Mode}, | 18 | codegen::{self, Mode}, |
18 | install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, run_with_output, Cmd, Result, | 19 | install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd, Result, |
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 = 39; | 23 | const REQUIRED_RUST_VERSION: (usize, usize) = (1, 39); |
23 | 24 | ||
24 | struct InstallOpt { | 25 | struct InstallOpt { |
25 | client: Option<ClientOpt>, | 26 | client: Option<ClientOpt>, |
@@ -226,20 +227,14 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
226 | } | 227 | } |
227 | 228 | ||
228 | fn install_server(opts: ServerOpt) -> Result<()> { | 229 | fn install_server(opts: ServerOpt) -> Result<()> { |
229 | let mut old_rust = false; | 230 | let ac = autocfg::AutoCfg::with_dir("target")?; |
230 | if let Ok(output) = run_with_output("cargo --version", ".") { | 231 | |
231 | if let Ok(stdout) = String::from_utf8(output.stdout) { | 232 | let old_rust = !ac.probe_rustc_version(REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1); |
232 | println!("{}", stdout); | ||
233 | if !check_version(&stdout, REQUIRED_RUST_VERSION) { | ||
234 | old_rust = true; | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | 233 | ||
239 | if old_rust { | 234 | if old_rust { |
240 | eprintln!( | 235 | eprintln!( |
241 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 236 | "\nWARNING: at least rust {}.{}.0 is required to compile rust-analyzer\n", |
242 | REQUIRED_RUST_VERSION | 237 | REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1 |
243 | ) | 238 | ) |
244 | } | 239 | } |
245 | 240 | ||
@@ -251,20 +246,10 @@ fn install_server(opts: ServerOpt) -> Result<()> { | |||
251 | 246 | ||
252 | if res.is_err() && old_rust { | 247 | if res.is_err() && old_rust { |
253 | eprintln!( | 248 | eprintln!( |
254 | "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n", | 249 | "\nWARNING: at least rust {}.{}.0 is required to compile rust-analyzer\n", |
255 | REQUIRED_RUST_VERSION | 250 | REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1 |
256 | ) | 251 | ) |
257 | } | 252 | } |
258 | 253 | ||
259 | res | 254 | res |
260 | } | 255 | } |
261 | |||
262 | fn check_version(version_output: &str, min_minor_version: u32) -> bool { | ||
263 | // Parse second the number out of | ||
264 | // cargo 1.39.0-beta (1c6ec66d5 2019-09-30) | ||
265 | let minor: Option<u32> = version_output.split('.').nth(1).and_then(|it| it.parse().ok()); | ||
266 | match minor { | ||
267 | None => true, | ||
268 | Some(minor) => minor >= min_minor_version, | ||
269 | } | ||
270 | } | ||