From f5a2fcf8f59eda3498bbdcb87568e5ba6b4db8b7 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Mon, 16 Mar 2020 14:10:13 +0100 Subject: Change existing OUT_DIR override config to make use of new infrastructure --- crates/ra_project_model/src/cargo_workspace.rs | 8 ++++++++ crates/ra_project_model/src/lib.rs | 28 ++++++-------------------- 2 files changed, 14 insertions(+), 22 deletions(-) (limited to 'crates/ra_project_model') 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 { /// Runs cargo check on launch to figure out the correct values of OUT_DIR pub load_out_dirs_from_check: bool, + + /// Fine grained controls for additional `OUT_DIR` env variables + pub out_dir_overrides: FxHashMap, } impl Default for CargoFeatures { @@ -48,6 +51,7 @@ impl Default for CargoFeatures { all_features: true, features: Vec::new(), load_out_dirs_from_check: false, + out_dir_overrides: FxHashMap::default(), } } } @@ -191,6 +195,10 @@ impl CargoWorkspace { if cargo_features.load_out_dirs_from_check { out_dir_by_id = load_out_dirs(cargo_toml, cargo_features); } + // We explicitly extend afterwards to allow overriding the value returned by cargo + out_dir_by_id.extend( + cargo_features.out_dir_overrides.iter().map(|(id, path)| (id.clone(), path.clone())), + ); let mut pkg_by_id = FxHashMap::default(); 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 { pub fn to_crate_graph( &self, default_cfg_options: &CfgOptions, - additional_out_dirs: &FxHashMap, extern_source_roots: &FxHashMap, load: &mut dyn FnMut(&Path) -> Option, ) -> CrateGraph { @@ -251,15 +250,8 @@ impl ProjectWorkspace { opts }; - let mut env = Env::default(); - let mut extern_source = ExternSource::default(); - if let Some(path) = additional_out_dirs.get(krate.name(&sysroot)) { - env.set("OUT_DIR", path.to_string_lossy().to_string()); - if let Some(extern_source_id) = extern_source_roots.get(path) { - extern_source.set_extern_path(&path, *extern_source_id); - } - } - + let env = Env::default(); + let extern_source = ExternSource::default(); let crate_id = crate_graph.add_crate_root( file_id, Edition::Edition2018, @@ -310,19 +302,11 @@ impl ProjectWorkspace { }; let mut env = Env::default(); let mut extern_source = ExternSource::default(); - if let Some(out_dir) = dbg!(pkg.out_dir(cargo)) { + if let Some(out_dir) = pkg.out_dir(cargo) { + // FIXME: We probably mangle non UTF-8 paths here, figure out a better solution env.set("OUT_DIR", out_dir.to_string_lossy().to_string()); - if let Some(extern_source_id) = - dbg!(dbg!(&extern_source_roots).get(out_dir)) - { - extern_source.set_extern_path(&out_dir, *extern_source_id); - } - } else { - if let Some(path) = additional_out_dirs.get(pkg.name(&cargo)) { - env.set("OUT_DIR", path.to_string_lossy().to_string()); - if let Some(extern_source_id) = extern_source_roots.get(path) { - extern_source.set_extern_path(&path, *extern_source_id); - } + if let Some(&extern_source_id) = extern_source_roots.get(out_dir) { + extern_source.set_extern_path(&out_dir, extern_source_id); } } let crate_id = crate_graph.add_crate_root( -- cgit v1.2.3