aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/input.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-22 10:58:19 +0000
committerGitHub <[email protected]>2019-11-22 10:58:19 +0000
commitc866efdf36139502ec824bc38892fb2bda14484f (patch)
treed2d9cfb6f56cfe83b801d6e118e03051207f75a5 /crates/ra_db/src/input.rs
parent5be7bd605a09fafbc2bb91ebc3c4c3e35cf24110 (diff)
parent2c48fa087b6cc79ebfd81af9daf4a07d8019fd67 (diff)
Merge #2353
2353: Add support for environment to CrateGraph r=matklad a=matklad bors r+ Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_db/src/input.rs')
-rw-r--r--crates/ra_db/src/input.rs34
1 files changed, 24 insertions, 10 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index c0d95a13f..0015d6b5e 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -114,17 +114,23 @@ impl FromStr for Edition {
114 } 114 }
115} 115}
116 116
117#[derive(Default, Debug, Clone, PartialEq, Eq)]
118pub struct Env {
119 entries: FxHashMap<String, String>,
120}
121
117#[derive(Debug, Clone, PartialEq, Eq)] 122#[derive(Debug, Clone, PartialEq, Eq)]
118struct CrateData { 123struct CrateData {
119 file_id: FileId, 124 file_id: FileId,
120 edition: Edition, 125 edition: Edition,
121 dependencies: Vec<Dependency>, 126 dependencies: Vec<Dependency>,
122 cfg_options: CfgOptions, 127 cfg_options: CfgOptions,
128 env: Env,
123} 129}
124 130
125impl CrateData { 131impl CrateData {
126 fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions) -> CrateData { 132 fn new(file_id: FileId, edition: Edition, cfg_options: CfgOptions, env: Env) -> CrateData {
127 CrateData { file_id, edition, dependencies: Vec::new(), cfg_options } 133 CrateData { file_id, edition, dependencies: Vec::new(), cfg_options, env }
128 } 134 }
129 135
130 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { 136 fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) {
@@ -150,9 +156,11 @@ impl CrateGraph {
150 file_id: FileId, 156 file_id: FileId,
151 edition: Edition, 157 edition: Edition,
152 cfg_options: CfgOptions, 158 cfg_options: CfgOptions,
159 env: Env,
153 ) -> CrateId { 160 ) -> CrateId {
161 let data = CrateData::new(file_id, edition, cfg_options, env);
154 let crate_id = CrateId(self.arena.len() as u32); 162 let crate_id = CrateId(self.arena.len() as u32);
155 let prev = self.arena.insert(crate_id, CrateData::new(file_id, edition, cfg_options)); 163 let prev = self.arena.insert(crate_id, data);
156 assert!(prev.is_none()); 164 assert!(prev.is_none());
157 crate_id 165 crate_id
158 } 166 }
@@ -241,14 +249,17 @@ impl CrateGraph {
241 249
242#[cfg(test)] 250#[cfg(test)]
243mod tests { 251mod tests {
244 use super::{CfgOptions, CrateGraph, Edition::Edition2018, FileId, SmolStr}; 252 use super::{CfgOptions, CrateGraph, Edition::Edition2018, Env, FileId, SmolStr};
245 253
246 #[test] 254 #[test]
247 fn it_should_panic_because_of_cycle_dependencies() { 255 fn it_should_panic_because_of_cycle_dependencies() {
248 let mut graph = CrateGraph::default(); 256 let mut graph = CrateGraph::default();
249 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default()); 257 let crate1 =
250 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default()); 258 graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default(), Env::default());
251 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default()); 259 let crate2 =
260 graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default(), Env::default());
261 let crate3 =
262 graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default(), Env::default());
252 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); 263 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
253 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); 264 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
254 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err()); 265 assert!(graph.add_dep(crate3, SmolStr::new("crate1"), crate1).is_err());
@@ -257,9 +268,12 @@ mod tests {
257 #[test] 268 #[test]
258 fn it_works() { 269 fn it_works() {
259 let mut graph = CrateGraph::default(); 270 let mut graph = CrateGraph::default();
260 let crate1 = graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default()); 271 let crate1 =
261 let crate2 = graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default()); 272 graph.add_crate_root(FileId(1u32), Edition2018, CfgOptions::default(), Env::default());
262 let crate3 = graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default()); 273 let crate2 =
274 graph.add_crate_root(FileId(2u32), Edition2018, CfgOptions::default(), Env::default());
275 let crate3 =
276 graph.add_crate_root(FileId(3u32), Edition2018, CfgOptions::default(), Env::default());
263 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok()); 277 assert!(graph.add_dep(crate1, SmolStr::new("crate2"), crate2).is_ok());
264 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok()); 278 assert!(graph.add_dep(crate2, SmolStr::new("crate3"), crate3).is_ok());
265 } 279 }