aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-13 16:42:50 +0000
committerGitHub <[email protected]>2019-11-13 16:42:50 +0000
commit47865566575eb58cc107e7df9b71f227938a8e14 (patch)
tree2677f84e1e5081b376462eb65775400582d89548
parentc486f8477aca4a42800e81b0b99fd56c14c6219f (diff)
parent06754b78ac462d7b9fe8bd176ff7831772c0b1c8 (diff)
Merge #2230
2230: Use autocfg to determine rust version r=matklad a=kjeremy Fixes #2229 Co-authored-by: kjeremy <[email protected]>
-rw-r--r--Cargo.lock1
-rw-r--r--xtask/Cargo.toml1
-rw-r--r--xtask/src/main.rs35
3 files changed, 12 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 3fa6e931c..97452951c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1823,6 +1823,7 @@ dependencies = [
1823name = "xtask" 1823name = "xtask"
1824version = "0.1.0" 1824version = "0.1.0"
1825dependencies = [ 1825dependencies = [
1826 "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
1826 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 1827 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1827 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1828 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1828 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1829 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
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"]
6publish = false 6publish = false
7 7
8[dependencies] 8[dependencies]
9autocfg = "0.1"
9walkdir = "2.1.3" 10walkdir = "2.1.3"
10pico-args = "0.3.0" 11pico-args = "0.3.0"
11quote = "1.0.2" 12quote = "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`.
10mod help; 10mod help;
11 11
12use autocfg;
12use core::fmt::Write; 13use core::fmt::Write;
13use core::str; 14use core::str;
14use pico_args::Arguments; 15use pico_args::Arguments;
15use std::{env, path::PathBuf}; 16use std::{env, path::PathBuf};
16use xtask::{ 17use 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.
22const REQUIRED_RUST_VERSION: u32 = 39; 23const REQUIRED_RUST_VERSION: (usize, usize) = (1, 39);
23 24
24struct InstallOpt { 25struct InstallOpt {
25 client: Option<ClientOpt>, 26 client: Option<ClientOpt>,
@@ -226,20 +227,14 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
226} 227}
227 228
228fn install_server(opts: ServerOpt) -> Result<()> { 229fn 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
262fn 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}