aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/main.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-14 08:11:32 +0000
committerAleksey Kladov <[email protected]>2019-11-14 08:12:52 +0000
commitc65f42325fa9213ad79fcf12115213a923b651df (patch)
treea8ca8d4f048281a25636c7ec300fbd31f2199a68 /xtask/src/main.rs
parent8af85263f7cd249356382aa61b98094594165364 (diff)
Revert #2230
Looks like autocfg tries to do slightly more than we need (see #2231), so let's stick with minimal home-grown solution.
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r--xtask/src/main.rs36
1 files changed, 25 insertions, 11 deletions
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}