diff options
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 88a6ffb2a..5a0a87ed7 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -8,13 +8,12 @@ use std::{ | |||
8 | fs::{read_dir, File, ReadDir}, | 8 | fs::{read_dir, File, ReadDir}, |
9 | io::{self, BufReader}, | 9 | io::{self, BufReader}, |
10 | path::{Path, PathBuf}, | 10 | path::{Path, PathBuf}, |
11 | process::Command, | 11 | process::{Command, Output}, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | use anyhow::{bail, Context, Result}; | 14 | use anyhow::{bail, Context, Result}; |
15 | use ra_cfg::CfgOptions; | 15 | use ra_cfg::CfgOptions; |
16 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; | 16 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; |
17 | use ra_env::get_path_for_executable; | ||
18 | use rustc_hash::FxHashMap; | 17 | use rustc_hash::FxHashMap; |
19 | use serde_json::from_reader; | 18 | use serde_json::from_reader; |
20 | 19 | ||
@@ -568,25 +567,18 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { | |||
568 | } | 567 | } |
569 | } | 568 | } |
570 | 569 | ||
571 | match (|| -> Result<String> { | 570 | let rustc_cfgs = || -> Result<String> { |
572 | // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. | 571 | // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. |
573 | let mut cmd = Command::new(get_path_for_executable("rustc")?); | 572 | let mut cmd = Command::new(ra_toolchain::rustc()); |
574 | cmd.args(&["--print", "cfg", "-O"]); | 573 | cmd.args(&["--print", "cfg", "-O"]); |
575 | if let Some(target) = target { | 574 | if let Some(target) = target { |
576 | cmd.args(&["--target", target.as_str()]); | 575 | cmd.args(&["--target", target.as_str()]); |
577 | } | 576 | } |
578 | let output = cmd.output().context("Failed to get output from rustc --print cfg -O")?; | 577 | let output = output(cmd)?; |
579 | if !output.status.success() { | ||
580 | bail!( | ||
581 | "rustc --print cfg -O exited with exit code ({})", | ||
582 | output | ||
583 | .status | ||
584 | .code() | ||
585 | .map_or(String::from("no exit code"), |code| format!("{}", code)) | ||
586 | ); | ||
587 | } | ||
588 | Ok(String::from_utf8(output.stdout)?) | 578 | Ok(String::from_utf8(output.stdout)?) |
589 | })() { | 579 | }(); |
580 | |||
581 | match rustc_cfgs { | ||
590 | Ok(rustc_cfgs) => { | 582 | Ok(rustc_cfgs) => { |
591 | for line in rustc_cfgs.lines() { | 583 | for line in rustc_cfgs.lines() { |
592 | match line.find('=') { | 584 | match line.find('=') { |
@@ -599,8 +591,16 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { | |||
599 | } | 591 | } |
600 | } | 592 | } |
601 | } | 593 | } |
602 | Err(e) => log::error!("failed to get rustc cfgs: {}", e), | 594 | Err(e) => log::error!("failed to get rustc cfgs: {:#}", e), |
603 | } | 595 | } |
604 | 596 | ||
605 | cfg_options | 597 | cfg_options |
606 | } | 598 | } |
599 | |||
600 | fn output(mut cmd: Command) -> Result<Output> { | ||
601 | let output = cmd.output().with_context(|| format!("{:?} failed", cmd))?; | ||
602 | if !output.status.success() { | ||
603 | bail!("{:?} failed, {}", cmd, output.status) | ||
604 | } | ||
605 | Ok(output) | ||
606 | } | ||