diff options
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index c2b33c1dc..5a0a87ed7 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -8,7 +8,7 @@ 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}; |
@@ -398,7 +398,18 @@ impl ProjectWorkspace { | |||
398 | let edition = cargo[pkg].edition; | 398 | let edition = cargo[pkg].edition; |
399 | let cfg_options = { | 399 | let cfg_options = { |
400 | let mut opts = default_cfg_options.clone(); | 400 | let mut opts = default_cfg_options.clone(); |
401 | opts.insert_features(cargo[pkg].features.iter().map(Into::into)); | 401 | for feature in cargo[pkg].features.iter() { |
402 | opts.insert_key_value("feature".into(), feature.into()); | ||
403 | } | ||
404 | for cfg in cargo[pkg].cfgs.iter() { | ||
405 | match cfg.find('=') { | ||
406 | Some(split) => opts.insert_key_value( | ||
407 | cfg[..split].into(), | ||
408 | cfg[split + 1..].trim_matches('"').into(), | ||
409 | ), | ||
410 | None => opts.insert_atom(cfg.into()), | ||
411 | }; | ||
412 | } | ||
402 | opts | 413 | opts |
403 | }; | 414 | }; |
404 | let mut env = Env::default(); | 415 | let mut env = Env::default(); |
@@ -556,25 +567,18 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { | |||
556 | } | 567 | } |
557 | } | 568 | } |
558 | 569 | ||
559 | match (|| -> Result<String> { | 570 | let rustc_cfgs = || -> Result<String> { |
560 | // `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. |
561 | let mut cmd = Command::new("rustc"); | 572 | let mut cmd = Command::new(ra_toolchain::rustc()); |
562 | cmd.args(&["--print", "cfg", "-O"]); | 573 | cmd.args(&["--print", "cfg", "-O"]); |
563 | if let Some(target) = target { | 574 | if let Some(target) = target { |
564 | cmd.args(&["--target", target.as_str()]); | 575 | cmd.args(&["--target", target.as_str()]); |
565 | } | 576 | } |
566 | let output = cmd.output().context("Failed to get output from rustc --print cfg -O")?; | 577 | let output = output(cmd)?; |
567 | if !output.status.success() { | ||
568 | bail!( | ||
569 | "rustc --print cfg -O exited with exit code ({})", | ||
570 | output | ||
571 | .status | ||
572 | .code() | ||
573 | .map_or(String::from("no exit code"), |code| format!("{}", code)) | ||
574 | ); | ||
575 | } | ||
576 | Ok(String::from_utf8(output.stdout)?) | 578 | Ok(String::from_utf8(output.stdout)?) |
577 | })() { | 579 | }(); |
580 | |||
581 | match rustc_cfgs { | ||
578 | Ok(rustc_cfgs) => { | 582 | Ok(rustc_cfgs) => { |
579 | for line in rustc_cfgs.lines() { | 583 | for line in rustc_cfgs.lines() { |
580 | match line.find('=') { | 584 | match line.find('=') { |
@@ -587,8 +591,16 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { | |||
587 | } | 591 | } |
588 | } | 592 | } |
589 | } | 593 | } |
590 | Err(e) => log::error!("failed to get rustc cfgs: {}", e), | 594 | Err(e) => log::error!("failed to get rustc cfgs: {:#}", e), |
591 | } | 595 | } |
592 | 596 | ||
593 | cfg_options | 597 | cfg_options |
594 | } | 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 | } | ||