Merge #4832
4832: Reduce OUT_DIR special casing r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
9251f181de
@ -47,17 +47,21 @@ pub struct PackageRoot {
|
||||
path: PathBuf,
|
||||
/// Is a member of the current workspace
|
||||
is_member: bool,
|
||||
out_dir: Option<PathBuf>,
|
||||
}
|
||||
impl PackageRoot {
|
||||
pub fn new_member(path: PathBuf) -> PackageRoot {
|
||||
Self { path, is_member: true }
|
||||
Self { path, is_member: true, out_dir: None }
|
||||
}
|
||||
pub fn new_non_member(path: PathBuf) -> PackageRoot {
|
||||
Self { path, is_member: false }
|
||||
Self { path, is_member: false, out_dir: None }
|
||||
}
|
||||
pub fn path(&self) -> &Path {
|
||||
&self.path
|
||||
}
|
||||
pub fn out_dir(&self) -> Option<&Path> {
|
||||
self.out_dir.as_deref()
|
||||
}
|
||||
pub fn is_member(&self) -> bool {
|
||||
self.is_member
|
||||
}
|
||||
@ -204,6 +208,7 @@ pub fn to_roots(&self) -> Vec<PackageRoot> {
|
||||
.map(|pkg| PackageRoot {
|
||||
path: cargo[pkg].root().to_path_buf(),
|
||||
is_member: cargo[pkg].is_member,
|
||||
out_dir: cargo[pkg].out_dir.clone(),
|
||||
})
|
||||
.chain(sysroot.crates().map(|krate| {
|
||||
PackageRoot::new_non_member(sysroot[krate].root_dir().to_path_buf())
|
||||
@ -212,17 +217,6 @@ pub fn to_roots(&self) -> Vec<PackageRoot> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn out_dirs(&self) -> Vec<PathBuf> {
|
||||
match self {
|
||||
ProjectWorkspace::Json { project } => {
|
||||
project.crates.iter().filter_map(|krate| krate.out_dir.as_ref()).cloned().collect()
|
||||
}
|
||||
ProjectWorkspace::Cargo { cargo, sysroot: _ } => {
|
||||
cargo.packages().filter_map(|pkg| cargo[pkg].out_dir.as_ref()).cloned().collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn proc_macro_dylib_paths(&self) -> Vec<PathBuf> {
|
||||
match self {
|
||||
ProjectWorkspace::Json { project } => project
|
||||
|
@ -36,28 +36,28 @@ pub fn load_cargo(
|
||||
)?;
|
||||
|
||||
let mut extern_dirs = FxHashSet::default();
|
||||
extern_dirs.extend(ws.out_dirs());
|
||||
|
||||
let mut project_roots = ws.to_roots();
|
||||
project_roots.extend(extern_dirs.iter().cloned().map(PackageRoot::new_non_member));
|
||||
|
||||
let (sender, receiver) = unbounded();
|
||||
let sender = Box::new(move |t| sender.send(t).unwrap());
|
||||
let (mut vfs, roots) = Vfs::new(
|
||||
project_roots
|
||||
.iter()
|
||||
.map(|pkg_root| {
|
||||
RootEntry::new(
|
||||
pkg_root.path().to_owned(),
|
||||
RustPackageFilterBuilder::default()
|
||||
.set_member(pkg_root.is_member())
|
||||
.into_vfs_filter(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
sender,
|
||||
Watch(false),
|
||||
);
|
||||
|
||||
let mut roots = Vec::new();
|
||||
let project_roots = ws.to_roots();
|
||||
for root in &project_roots {
|
||||
roots.push(RootEntry::new(
|
||||
root.path().to_owned(),
|
||||
RustPackageFilterBuilder::default().set_member(root.is_member()).into_vfs_filter(),
|
||||
));
|
||||
|
||||
if let Some(out_dir) = root.out_dir() {
|
||||
extern_dirs.insert(out_dir.to_path_buf());
|
||||
roots.push(RootEntry::new(
|
||||
out_dir.to_owned(),
|
||||
RustPackageFilterBuilder::default().set_member(root.is_member()).into_vfs_filter(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
let (mut vfs, roots) = Vfs::new(roots, sender, Watch(false));
|
||||
|
||||
let source_roots = roots
|
||||
.into_iter()
|
||||
|
@ -89,8 +89,7 @@ pub fn new(
|
||||
) -> GlobalState {
|
||||
let mut change = AnalysisChange::new();
|
||||
|
||||
let extern_dirs: FxHashSet<_> =
|
||||
workspaces.iter().flat_map(ProjectWorkspace::out_dirs).collect();
|
||||
let mut extern_dirs: FxHashSet<PathBuf> = FxHashSet::default();
|
||||
|
||||
let mut local_roots = Vec::new();
|
||||
let roots: Vec<_> = {
|
||||
@ -100,22 +99,22 @@ pub fn new(
|
||||
.exclude(exclude_globs.iter().cloned())
|
||||
.into_vfs_filter()
|
||||
};
|
||||
workspaces
|
||||
.iter()
|
||||
.flat_map(ProjectWorkspace::to_roots)
|
||||
.map(|pkg_root| {
|
||||
let path = pkg_root.path().to_owned();
|
||||
if pkg_root.is_member() {
|
||||
local_roots.push(path.clone());
|
||||
}
|
||||
RootEntry::new(path, create_filter(pkg_root.is_member()))
|
||||
})
|
||||
.chain(
|
||||
extern_dirs
|
||||
.iter()
|
||||
.map(|path| RootEntry::new(path.to_owned(), create_filter(false))),
|
||||
)
|
||||
.collect()
|
||||
let mut roots = Vec::new();
|
||||
for root in workspaces.iter().flat_map(ProjectWorkspace::to_roots) {
|
||||
let path = root.path().to_owned();
|
||||
if root.is_member() {
|
||||
local_roots.push(path.clone());
|
||||
}
|
||||
roots.push(RootEntry::new(path, create_filter(root.is_member())));
|
||||
if let Some(out_dir) = root.out_dir() {
|
||||
extern_dirs.insert(out_dir.to_path_buf());
|
||||
roots.push(RootEntry::new(
|
||||
out_dir.to_path_buf(),
|
||||
create_filter(root.is_member()),
|
||||
))
|
||||
}
|
||||
}
|
||||
roots
|
||||
};
|
||||
|
||||
let (task_sender, task_receiver) = unbounded();
|
||||
|
Loading…
Reference in New Issue
Block a user