aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
authorEmil Lauridsen <[email protected]>2020-03-16 13:10:13 +0000
committerEmil Lauridsen <[email protected]>2020-03-17 13:47:05 +0000
commitf5a2fcf8f59eda3498bbdcb87568e5ba6b4db8b7 (patch)
tree1ace16a13f74d6165780b8054b0b4e8b43f945c2 /crates/ra_project_model
parent33c6c7abc6621f8b0cf083a98f7e4788cf4b5b54 (diff)
Change existing OUT_DIR override config to make use of new infrastructure
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs8
-rw-r--r--crates/ra_project_model/src/lib.rs28
2 files changed, 14 insertions, 22 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index eeeb10233..97fa48b8b 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -39,6 +39,9 @@ pub struct CargoFeatures {
39 39
40 /// Runs cargo check on launch to figure out the correct values of OUT_DIR 40 /// Runs cargo check on launch to figure out the correct values of OUT_DIR
41 pub load_out_dirs_from_check: bool, 41 pub load_out_dirs_from_check: bool,
42
43 /// Fine grained controls for additional `OUT_DIR` env variables
44 pub out_dir_overrides: FxHashMap<PackageId, PathBuf>,
42} 45}
43 46
44impl Default for CargoFeatures { 47impl Default for CargoFeatures {
@@ -48,6 +51,7 @@ impl Default for CargoFeatures {
48 all_features: true, 51 all_features: true,
49 features: Vec::new(), 52 features: Vec::new(),
50 load_out_dirs_from_check: false, 53 load_out_dirs_from_check: false,
54 out_dir_overrides: FxHashMap::default(),
51 } 55 }
52 } 56 }
53} 57}
@@ -191,6 +195,10 @@ impl CargoWorkspace {
191 if cargo_features.load_out_dirs_from_check { 195 if cargo_features.load_out_dirs_from_check {
192 out_dir_by_id = load_out_dirs(cargo_toml, cargo_features); 196 out_dir_by_id = load_out_dirs(cargo_toml, cargo_features);
193 } 197 }
198 // We explicitly extend afterwards to allow overriding the value returned by cargo
199 out_dir_by_id.extend(
200 cargo_features.out_dir_overrides.iter().map(|(id, path)| (id.clone(), path.clone())),
201 );
194 202
195 let mut pkg_by_id = FxHashMap::default(); 203 let mut pkg_by_id = FxHashMap::default();
196 let mut packages = Arena::default(); 204 let mut packages = Arena::default();
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 43f834253..b2c3e576d 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -177,7 +177,6 @@ impl ProjectWorkspace {
177 pub fn to_crate_graph( 177 pub fn to_crate_graph(
178 &self, 178 &self,
179 default_cfg_options: &CfgOptions, 179 default_cfg_options: &CfgOptions,
180 additional_out_dirs: &FxHashMap<String, PathBuf>,
181 extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>, 180 extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>,
182 load: &mut dyn FnMut(&Path) -> Option<FileId>, 181 load: &mut dyn FnMut(&Path) -> Option<FileId>,
183 ) -> CrateGraph { 182 ) -> CrateGraph {
@@ -251,15 +250,8 @@ impl ProjectWorkspace {
251 opts 250 opts
252 }; 251 };
253 252
254 let mut env = Env::default(); 253 let env = Env::default();
255 let mut extern_source = ExternSource::default(); 254 let extern_source = ExternSource::default();
256 if let Some(path) = additional_out_dirs.get(krate.name(&sysroot)) {
257 env.set("OUT_DIR", path.to_string_lossy().to_string());
258 if let Some(extern_source_id) = extern_source_roots.get(path) {
259 extern_source.set_extern_path(&path, *extern_source_id);
260 }
261 }
262
263 let crate_id = crate_graph.add_crate_root( 255 let crate_id = crate_graph.add_crate_root(
264 file_id, 256 file_id,
265 Edition::Edition2018, 257 Edition::Edition2018,
@@ -310,19 +302,11 @@ impl ProjectWorkspace {
310 }; 302 };
311 let mut env = Env::default(); 303 let mut env = Env::default();
312 let mut extern_source = ExternSource::default(); 304 let mut extern_source = ExternSource::default();
313 if let Some(out_dir) = dbg!(pkg.out_dir(cargo)) { 305 if let Some(out_dir) = pkg.out_dir(cargo) {
306 // FIXME: We probably mangle non UTF-8 paths here, figure out a better solution
314 env.set("OUT_DIR", out_dir.to_string_lossy().to_string()); 307 env.set("OUT_DIR", out_dir.to_string_lossy().to_string());
315 if let Some(extern_source_id) = 308 if let Some(&extern_source_id) = extern_source_roots.get(out_dir) {
316 dbg!(dbg!(&extern_source_roots).get(out_dir)) 309 extern_source.set_extern_path(&out_dir, extern_source_id);
317 {
318 extern_source.set_extern_path(&out_dir, *extern_source_id);
319 }
320 } else {
321 if let Some(path) = additional_out_dirs.get(pkg.name(&cargo)) {
322 env.set("OUT_DIR", path.to_string_lossy().to_string());
323 if let Some(extern_source_id) = extern_source_roots.get(path) {
324 extern_source.set_extern_path(&path, *extern_source_id);
325 }
326 } 310 }
327 } 311 }
328 let crate_id = crate_graph.add_crate_root( 312 let crate_id = crate_graph.add_crate_root(