mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Change existing OUT_DIR override config to make use of new infrastructure
This commit is contained in:
parent
33c6c7abc6
commit
f5a2fcf8f5
8 changed files with 26 additions and 57 deletions
|
@ -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<PackageId, PathBuf>,
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
|
@ -177,7 +177,6 @@ impl ProjectWorkspace {
|
|||
pub fn to_crate_graph(
|
||||
&self,
|
||||
default_cfg_options: &CfgOptions,
|
||||
additional_out_dirs: &FxHashMap<String, PathBuf>,
|
||||
extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>,
|
||||
load: &mut dyn FnMut(&Path) -> Option<FileId>,
|
||||
) -> 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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue