This commit is contained in:
Aleksey Kladov 2020-11-17 12:17:24 +01:00
parent 66bcdcbb36
commit 0d19ee1d70
2 changed files with 15 additions and 17 deletions

View file

@ -200,23 +200,19 @@ impl ProjectWorkspace {
let mut crate_graph = CrateGraph::default(); let mut crate_graph = CrateGraph::default();
match self { match self {
ProjectWorkspace::Json { project, sysroot } => { ProjectWorkspace::Json { project, sysroot } => {
let sysroot_dps = sysroot let sysroot_deps = sysroot
.as_ref() .as_ref()
.map(|sysroot| sysroot_to_crate_graph(&mut crate_graph, sysroot, target, load)); .map(|sysroot| sysroot_to_crate_graph(&mut crate_graph, sysroot, target, load));
let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default(); let mut cfg_cache: FxHashMap<Option<&str>, Vec<CfgFlag>> = FxHashMap::default();
let crates: FxHashMap<_, _> = project let crates: FxHashMap<CrateId, CrateId> = project
.crates() .crates()
.filter_map(|(crate_id, krate)| { .filter_map(|(crate_id, krate)| {
let file_path = &krate.root_module; let file_path = &krate.root_module;
let file_id = match load(&file_path) { let file_id = load(&file_path)?;
Some(id) => id, Some((crate_id, krate, file_id))
None => { })
log::error!("failed to load crate root {}", file_path.display()); .map(|(crate_id, krate, file_id)| {
return None;
}
};
let env = krate.env.clone().into_iter().collect(); let env = krate.env.clone().into_iter().collect();
let proc_macro = krate let proc_macro = krate
.proc_macro_dylib_path .proc_macro_dylib_path
@ -230,8 +226,7 @@ impl ProjectWorkspace {
let mut cfg_options = CfgOptions::default(); let mut cfg_options = CfgOptions::default();
cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned()); cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned());
(
Some((
crate_id, crate_id,
crate_graph.add_crate_root( crate_graph.add_crate_root(
file_id, file_id,
@ -241,21 +236,20 @@ impl ProjectWorkspace {
env, env,
proc_macro.unwrap_or_default(), proc_macro.unwrap_or_default(),
), ),
)) )
}) })
.collect(); .collect();
for (from, krate) in project.crates() { for (from, krate) in project.crates() {
if let Some(&from) = crates.get(&from) { if let Some(&from) = crates.get(&from) {
if let Some((public_deps, _proc_macro)) = &sysroot_dps { if let Some((public_deps, _proc_macro)) = &sysroot_deps {
for (name, to) in public_deps.iter() { for (name, to) in public_deps.iter() {
add_dep(&mut crate_graph, from, name.clone(), *to) add_dep(&mut crate_graph, from, name.clone(), *to)
} }
} }
for dep in &krate.deps { for dep in &krate.deps {
let to_crate_id = dep.crate_id; if let Some(&to) = crates.get(&dep.crate_id) {
if let Some(&to) = crates.get(&to_crate_id) {
add_dep(&mut crate_graph, from, dep.name.clone(), to) add_dep(&mut crate_graph, from, dep.name.clone(), to)
} }
} }

View file

@ -203,7 +203,11 @@ impl GlobalState {
let contents = loader.handle.load_sync(path); let contents = loader.handle.load_sync(path);
vfs.set_file_contents(vfs_path.clone(), contents); vfs.set_file_contents(vfs_path.clone(), contents);
} }
vfs.file_id(&vfs_path) let res = vfs.file_id(&vfs_path);
if res.is_none() {
log::error!("failed to load {}", path.display())
}
res
}; };
for ws in workspaces.iter() { for ws in workspaces.iter() {
crate_graph.extend(ws.to_crate_graph( crate_graph.extend(ws.to_crate_graph(