aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--xtask/Cargo.toml1
-rw-r--r--xtask/src/main.rs36
3 files changed, 25 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c9ab3ef10..1dedf9772 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1829,7 +1829,6 @@ name = "xtask"
1829version = "0.1.0" 1829version = "0.1.0"
1830dependencies = [ 1830dependencies = [
1831 "anyhow 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)", 1831 "anyhow 1.0.19 (registry+https://github.com/rust-lang/crates.io-index)",
1832 "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
1833 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 1832 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1834 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1833 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1835 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1834 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index bba4be192..77b9ae2b4 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -6,7 +6,6 @@ authors = ["rust-analyzer developers"]
6publish = false 6publish = false
7 7
8[dependencies] 8[dependencies]
9autocfg = "0.1"
10walkdir = "2.1.3" 9walkdir = "2.1.3"
11pico-args = "0.3.0" 10pico-args = "0.3.0"
12quote = "1.0.2" 11quote = "1.0.2"
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 7eab1c949..f14e6c8ae 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -10,18 +10,17 @@
10mod help; 10mod help;
11 11
12use anyhow::Context; 12use anyhow::Context;
13use autocfg;
14use core::fmt::Write; 13use core::fmt::Write;
15use core::str; 14use core::str;
16use pico_args::Arguments; 15use pico_args::Arguments;
17use std::{env, path::PathBuf}; 16use std::{env, path::PathBuf};
18use xtask::{ 17use xtask::{
19 codegen::{self, Mode}, 18 codegen::{self, Mode},
20 install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, Cmd, Result, 19 install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, run_with_output, Cmd, Result,
21}; 20};
22 21
23// 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.
24const REQUIRED_RUST_VERSION: (usize, usize) = (1, 39); 23const REQUIRED_RUST_VERSION: u32 = 39;
25 24
26struct InstallOpt { 25struct InstallOpt {
27 client: Option<ClientOpt>, 26 client: Option<ClientOpt>,
@@ -230,15 +229,20 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
230} 229}
231 230
232fn install_server(opts: ServerOpt) -> Result<()> { 231fn install_server(opts: ServerOpt) -> Result<()> {
233 let target_dir = env::var_os("CARGO_TARGET_DIR").unwrap_or_else(|| "target".into()); 232 let mut old_rust = false;
234 let ac = autocfg::AutoCfg::with_dir(target_dir)?; 233 if let Ok(output) = run_with_output("cargo --version", ".") {
235 234 if let Ok(stdout) = String::from_utf8(output.stdout) {
236 let old_rust = !ac.probe_rustc_version(REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1); 235 println!("{}", stdout);
236 if !check_version(&stdout, REQUIRED_RUST_VERSION) {
237 old_rust = true;
238 }
239 }
240 }
237 241
238 if old_rust { 242 if old_rust {
239 eprintln!( 243 eprintln!(
240 "\nWARNING: at least rust {}.{}.0 is required to compile rust-analyzer\n", 244 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
241 REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1 245 REQUIRED_RUST_VERSION,
242 ) 246 )
243 } 247 }
244 248
@@ -250,10 +254,20 @@ fn install_server(opts: ServerOpt) -> Result<()> {
250 254
251 if res.is_err() && old_rust { 255 if res.is_err() && old_rust {
252 eprintln!( 256 eprintln!(
253 "\nWARNING: at least rust {}.{}.0 is required to compile rust-analyzer\n", 257 "\nWARNING: at least rust 1.{}.0 is required to compile rust-analyzer\n",
254 REQUIRED_RUST_VERSION.0, REQUIRED_RUST_VERSION.1 258 REQUIRED_RUST_VERSION,
255 ) 259 )
256 } 260 }
257 261
258 res 262 res
259} 263}
264
265fn check_version(version_output: &str, min_minor_version: u32) -> bool {
266 // Parse second the number out of
267 // cargo 1.39.0-beta (1c6ec66d5 2019-09-30)
268 let minor: Option<u32> = version_output.split('.').nth(1).and_then(|it| it.parse().ok());
269 match minor {
270 None => true,
271 Some(minor) => minor >= min_minor_version,
272 }
273}