aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/lib.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-05-08 13:54:29 +0100
committerAleksey Kladov <[email protected]>2020-05-08 13:55:28 +0100
commitecff5dc141046c5b9e40639657247a05fb9b0344 (patch)
tree871ebe102579fd2c8a35d2d5df4ed18b27219fd6 /crates/ra_project_model/src/lib.rs
parent7c0409e0c7249fe793b5d05829fcd984d06ec770 (diff)
Cleanup
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r--crates/ra_project_model/src/lib.rs32
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 4f0b9c77e..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
14use anyhow::{bail, Context, Result}; 14use anyhow::{bail, Context, Result};
15use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
16use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; 16use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId};
17use ra_toolchain::get_path_for_executable;
18use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
19use serde_json::from_reader; 18use 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
600fn 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}