From e00a1e0b79e2b2c0c20a96e5341e3a35f46f99b7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 10 Mar 2020 22:00:58 +0800 Subject: Setup Env in world --- crates/ra_project_model/src/lib.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'crates/ra_project_model') 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::{ use anyhow::{bail, Context, Result}; use ra_cfg::CfgOptions; -use ra_db::{CrateGraph, CrateName, Edition, Env, FileId}; +use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSourceId, FileId}; use rustc_hash::FxHashMap; use serde_json::from_reader; @@ -162,6 +162,7 @@ impl ProjectWorkspace { pub fn to_crate_graph( &self, default_cfg_options: &CfgOptions, + outdirs: &FxHashMap, load: &mut dyn FnMut(&Path) -> Option, ) -> CrateGraph { let mut crate_graph = CrateGraph::default(); @@ -185,6 +186,8 @@ impl ProjectWorkspace { } opts }; + + // FIXME: No crate name in json definition such that we cannot add OUT_DIR to env crates.insert( crate_id, crate_graph.add_crate_root( @@ -231,12 +234,17 @@ impl ProjectWorkspace { opts }; + let mut env = Env::default(); + if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) { + env.set_extern_path("OUT_DIR", &path, *id); + } + let crate_id = crate_graph.add_crate_root( file_id, Edition::Edition2018, Some(krate.name(&sysroot).to_string()), cfg_options, - Env::default(), + env, ); sysroot_crates.insert(krate, crate_id); } @@ -275,12 +283,16 @@ impl ProjectWorkspace { opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); opts }; + let mut env = Env::default(); + if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) { + env.set_extern_path("OUT_DIR", &path, *id); + } let crate_id = crate_graph.add_crate_root( file_id, edition, Some(pkg.name(&cargo).to_string()), cfg_options, - Env::default(), + env, ); if tgt.kind(&cargo) == TargetKind::Lib { lib_tgt = Some(crate_id); -- cgit v1.2.3 From 6ea7c319154f9ec10721f4041afc9d07d6b2476b Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 11 Mar 2020 11:04:02 +0800 Subject: Add extern source --- crates/ra_project_model/src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'crates/ra_project_model') diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index b46320304..a6274709d 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -14,7 +14,7 @@ use std::{ use anyhow::{bail, Context, Result}; use ra_cfg::CfgOptions; -use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSourceId, FileId}; +use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; use rustc_hash::FxHashMap; use serde_json::from_reader; @@ -197,6 +197,7 @@ impl ProjectWorkspace { None, cfg_options, Env::default(), + Default::default(), ), ); } @@ -235,8 +236,10 @@ impl ProjectWorkspace { }; let mut env = Env::default(); + let mut extern_source = ExternSource::default(); if let Some((id, path)) = outdirs.get(krate.name(&sysroot)) { - env.set_extern_path("OUT_DIR", &path, *id); + env.set("OUT_DIR", path.clone()); + extern_source.set_extern_path(&path, *id); } let crate_id = crate_graph.add_crate_root( @@ -245,6 +248,7 @@ impl ProjectWorkspace { Some(krate.name(&sysroot).to_string()), cfg_options, env, + extern_source, ); sysroot_crates.insert(krate, crate_id); } @@ -284,8 +288,10 @@ impl ProjectWorkspace { opts }; let mut env = Env::default(); + let mut extern_source = ExternSource::default(); if let Some((id, path)) = outdirs.get(pkg.name(&cargo)) { - env.set_extern_path("OUT_DIR", &path, *id); + env.set("OUT_DIR", path.clone()); + extern_source.set_extern_path(&path, *id); } let crate_id = crate_graph.add_crate_root( file_id, @@ -293,6 +299,7 @@ impl ProjectWorkspace { Some(pkg.name(&cargo).to_string()), cfg_options, env, + extern_source, ); if tgt.kind(&cargo) == TargetKind::Lib { lib_tgt = Some(crate_id); -- cgit v1.2.3