aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-10 14:00:58 +0000
committerEdwin Cheng <[email protected]>2020-03-10 17:06:01 +0000
commite00a1e0b79e2b2c0c20a96e5341e3a35f46f99b7 (patch)
treeb363f9ff36e14e7f90808e79ac36a35f96b50438 /crates/ra_project_model
parent22f064cca7651eaf2980fcfa27618d99c633a589 (diff)
Setup Env in world
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 37845ca56..b46320304 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -14,7 +14,7 @@ use std::{
14 14
15use anyhow::{bail, Context, Result}; 15use anyhow::{bail, Context, Result};
16use ra_cfg::CfgOptions; 16use ra_cfg::CfgOptions;
17use ra_db::{CrateGraph, CrateName, Edition, Env, FileId}; 17use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSourceId, FileId};
18use rustc_hash::FxHashMap; 18use rustc_hash::FxHashMap;
19use serde_json::from_reader; 19use serde_json::from_reader;
20 20
@@ -162,6 +162,7 @@ impl ProjectWorkspace {
162 pub fn to_crate_graph( 162 pub fn to_crate_graph(
163 &self, 163 &self,
164 default_cfg_options: &CfgOptions, 164 default_cfg_options: &CfgOptions,
165 outdirs: &FxHashMap<String, (ExternSourceId, String)>,
165 load: &mut dyn FnMut(&Path) -> Option<FileId>, 166 load: &mut dyn FnMut(&Path) -> Option<FileId>,
166 ) -> CrateGraph { 167 ) -> CrateGraph {
167 let mut crate_graph = CrateGraph::default(); 168 let mut crate_graph = CrateGraph::default();
@@ -185,6 +186,8 @@ impl ProjectWorkspace {
185 } 186 }
186 opts 187 opts
187 }; 188 };
189
190 // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env
188 crates.insert( 191 crates.insert(
189 crate_id, 192 crate_id,
190 crate_graph.add_crate_root( 193 crate_graph.add_crate_root(
@@ -231,12 +234,17 @@ impl ProjectWorkspace {
231 opts 234 opts
232 }; 235 };
233 236
237 let mut env = Env::default();
238 if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) {
239 env.set_extern_path("OUT_DIR", &path, *id);
240 }
241
234 let crate_id = crate_graph.add_crate_root( 242 let crate_id = crate_graph.add_crate_root(
235 file_id, 243 file_id,
236 Edition::Edition2018, 244 Edition::Edition2018,
237 Some(krate.name(&sysroot).to_string()), 245 Some(krate.name(&sysroot).to_string()),
238 cfg_options, 246 cfg_options,
239 Env::default(), 247 env,
240 ); 248 );
241 sysroot_crates.insert(krate, crate_id); 249 sysroot_crates.insert(krate, crate_id);
242 } 250 }
@@ -275,12 +283,16 @@ impl ProjectWorkspace {
275 opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); 283 opts.insert_features(pkg.features(&cargo).iter().map(Into::into));
276 opts 284 opts
277 }; 285 };
286 let mut env = Env::default();
287 if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) {
288 env.set_extern_path("OUT_DIR", &path, *id);
289 }
278 let crate_id = crate_graph.add_crate_root( 290 let crate_id = crate_graph.add_crate_root(
279 file_id, 291 file_id,
280 edition, 292 edition,
281 Some(pkg.name(&cargo).to_string()), 293 Some(pkg.name(&cargo).to_string()),
282 cfg_options, 294 cfg_options,
283 Env::default(), 295 env,
284 ); 296 );
285 if tgt.kind(&cargo) == TargetKind::Lib { 297 if tgt.kind(&cargo) == TargetKind::Lib {
286 lib_tgt = Some(crate_id); 298 lib_tgt = Some(crate_id);