From b1ed887d813bf5775a16624694939fdf836f97b1 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 06:52:15 +0800 Subject: Introduce ra_cfg to parse and evaluate CfgExpr --- crates/ra_db/Cargo.toml | 1 + crates/ra_db/src/input.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index 2fac07bc5..c141f1a88 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml @@ -10,4 +10,5 @@ relative-path = "0.4.0" rustc-hash = "1.0" ra_syntax = { path = "../ra_syntax" } +ra_cfg = { path = "../ra_cfg" } ra_prof = { path = "../ra_prof" } diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 52f892891..5fd6edd78 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -9,6 +9,7 @@ use relative_path::{RelativePath, RelativePathBuf}; use rustc_hash::FxHashMap; +use ra_cfg::CfgOptions; use ra_syntax::SmolStr; use rustc_hash::FxHashSet; @@ -109,11 +110,13 @@ struct CrateData { file_id: FileId, edition: Edition, dependencies: Vec, + cfg_options: CfgOptions, } impl CrateData { fn new(file_id: FileId, edition: Edition) -> CrateData { - CrateData { file_id, edition, dependencies: Vec::new() } + // FIXME: cfg options + CrateData { file_id, edition, dependencies: Vec::new(), cfg_options: CfgOptions::default() } } fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { @@ -141,6 +144,10 @@ impl CrateGraph { crate_id } + pub fn cfg_options(&self, crate_id: CrateId) -> &CfgOptions { + &self.arena[&crate_id].cfg_options + } + pub fn add_dep( &mut self, from: CrateId, -- cgit v1.2.3 From d2ea776b8fbb5286a04dde75a9a8f8b14f12bfe9 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Mon, 30 Sep 2019 07:38:16 +0800 Subject: Enable CfgOptions `test` for workspace crates --- crates/ra_db/src/input.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 5fd6edd78..23148096c 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -114,9 +114,8 @@ struct CrateData { } impl CrateData { - fn new(file_id: FileId, edition: Edition) -> CrateData { - // FIXME: cfg options - CrateData { file_id, edition, dependencies: Vec::new(), cfg_options: CfgOptions::default() } + fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions) -> CrateData { + CrateData { file_id, edition, dependencies: Vec::new(), cfg_options } } fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { @@ -137,9 +136,14 @@ impl Dependency { } impl CrateGraph { - pub fn add_crate_root(&mut self, file_id: FileId, edition: Edition) -> CrateId { + pub fn add_crate_root( + &mut self, + file_id: FileId, + edition: Edition, + cfg_options: CfgOptions, + ) -> CrateId { let crate_id = CrateId(self.arena.len() as u32); - let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition)); + let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition, cfg_options)); assert!(prev.is_none()); crate_id } @@ -228,14 +232,14 @@ impl CrateGraph { #[cfg(test)] mod tests { - use super::{CrateGraph, Edition::Edition2018, FileId, SmolStr}; + use super::{CfgOptions, CrateGraph, Edition::Edition2018, FileId, SmolStr}; #[test] fn it_should_panic_because_of_cycle_dependencies() { let mut graph = CrateGraph::default(); - let crate1 = graph.add_crate_root(FileId(1u32), Edition2018); - let crate2 = graph.add_crate_root(FileId(2u32), Edition2018); - let crate3 = graph.add_crate_root(FileId(3u32), Edition2018); + let crate1 = graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default()); + let crate2 = graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default()); + let crate3 = graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default()); assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err()); @@ -244,9 +248,9 @@ mod tests { #[test] fn it_works() { let mut graph = CrateGraph::default(); - let crate1 = graph.add_crate_root(FileId(1u32), Edition2018); - let crate2 = graph.add_crate_root(FileId(2u32), Edition2018); - let crate3 = graph.add_crate_root(FileId(3u32), Edition2018); + let crate1 = graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default()); + let crate2 = graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default()); + let crate3 = graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default()); assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); } -- cgit v1.2.3