aboutsummaryrefslogtreecommitdiff
path: root/crates/project_model/src
diff options
context:
space:
mode:
authorXavier Denis <[email protected]>2020-11-11 12:03:44 +0000
committerXavier Denis <[email protected]>2020-11-11 12:04:27 +0000
commit16443760a3f91259b50886c1625127530fed6986 (patch)
tree026f5f7671a5cdb48200fea08612c82a4e0b4825 /crates/project_model/src
parent871608791934f81cdd430797fdd64a8f9da19074 (diff)
Reorder rustc_private loading
Diffstat (limited to 'crates/project_model/src')
-rw-r--r--crates/project_model/src/lib.rs173
1 files changed, 86 insertions, 87 deletions
diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs
index 40eb05f70..8e1cee0d6 100644
--- a/crates/project_model/src/lib.rs
+++ b/crates/project_model/src/lib.rs
@@ -409,69 +409,6 @@ impl ProjectWorkspace {
409 cfg_options.insert_atom("test".into()); 409 cfg_options.insert_atom("test".into());
410 cfg_options.insert_atom("debug_assertions".into()); 410 cfg_options.insert_atom("debug_assertions".into());
411 411
412 let mut rustc_pkg_crates = FxHashMap::default();
413
414 // Add crate roots for rustc_private libs if a path to source is provided
415 if let Some(rustc_workspace) = rustc {
416 for pkg in rustc_workspace.packages() {
417 for &tgt in rustc_workspace[pkg].targets.iter() {
418 if rustc_workspace[tgt].kind != TargetKind::Lib {
419 continue;
420 }
421 // Exclude alloc / core / std
422 if rustc_workspace[tgt]
423 .root
424 .components()
425 .any(|c| c == Component::Normal("library".as_ref()))
426 {
427 continue;
428 }
429
430 if let Some(crate_id) = add_target_crate_root(
431 &mut crate_graph,
432 &rustc_workspace[pkg],
433 &rustc_workspace[tgt],
434 &cfg_options,
435 proc_macro_client,
436 load,
437 ) {
438 pkg_to_lib_crate.insert(pkg, crate_id);
439 // Add dependencies on the core / std / alloc for rustc
440 for (name, krate) in public_deps.iter() {
441 if let Err(_) =
442 crate_graph.add_dep(crate_id, name.clone(), *krate)
443 {
444 log::error!(
445 "cyclic dependency on {} for {}",
446 name,
447 &cargo[pkg].name
448 )
449 }
450 }
451 rustc_pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);
452 }
453 }
454 }
455 // Now add a dep edge from all targets of upstream to the lib
456 // target of downstream.
457 for pkg in rustc_workspace.packages() {
458 for dep in rustc_workspace[pkg].dependencies.iter() {
459 let name = CrateName::new(&dep.name).unwrap();
460 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
461 for &from in rustc_pkg_crates.get(&pkg).into_iter().flatten() {
462 if let Err(_) = crate_graph.add_dep(from, name.clone(), to) {
463 log::error!(
464 "cyclic dependency {} -> {}",
465 &rustc_workspace[pkg].name,
466 &rustc_workspace[dep.pkg].name
467 )
468 }
469 }
470 }
471 }
472 }
473 };
474
475 let mut pkg_crates = FxHashMap::default(); 412 let mut pkg_crates = FxHashMap::default();
476 413
477 // Next, create crates for each package, target pair 414 // Next, create crates for each package, target pair
@@ -535,30 +472,6 @@ impl ProjectWorkspace {
535 } 472 }
536 } 473 }
537 474
538 // If we have access to the rust sources, create dependencies onto rustc_private libraries from all targets
539 // that are members of the current workspace
540 if let Some(rustc_workspace) = rustc {
541 for dep in rustc_workspace.packages() {
542 let name = CrateName::normalize_dashes(&rustc_workspace[dep].name);
543
544 if let Some(&from) = pkg_to_lib_crate.get(&dep) {
545 for pkg in cargo.packages() {
546 if !cargo[pkg].is_member {
547 continue;
548 }
549 for &to in pkg_crates.get(&pkg).into_iter().flatten() {
550 if let Err(_) = crate_graph.add_dep(to, name.clone(), from) {
551 log::error!(
552 "cyclic dependency22 {} -> {}",
553 &cargo[pkg].name,
554 &rustc_workspace[dep].name
555 )
556 }
557 }
558 }
559 }
560 }
561 }
562 // Now add a dep edge from all targets of upstream to the lib 475 // Now add a dep edge from all targets of upstream to the lib
563 // target of downstream. 476 // target of downstream.
564 for pkg in cargo.packages() { 477 for pkg in cargo.packages() {
@@ -577,6 +490,92 @@ impl ProjectWorkspace {
577 } 490 }
578 } 491 }
579 } 492 }
493
494 let mut rustc_pkg_crates = FxHashMap::default();
495
496 // If the user provided a path to rustc sources, we add all the rustc_private crates
497 // and create dependencies on them for the crates in the current workspace
498 if let Some(rustc_workspace) = rustc {
499 for pkg in rustc_workspace.packages() {
500 for &tgt in rustc_workspace[pkg].targets.iter() {
501 if rustc_workspace[tgt].kind != TargetKind::Lib {
502 continue;
503 }
504 // Exclude alloc / core / std
505 if rustc_workspace[tgt]
506 .root
507 .components()
508 .any(|c| c == Component::Normal("library".as_ref()))
509 {
510 continue;
511 }
512
513 if let Some(crate_id) = add_target_crate_root(
514 &mut crate_graph,
515 &rustc_workspace[pkg],
516 &rustc_workspace[tgt],
517 &cfg_options,
518 proc_macro_client,
519 load,
520 ) {
521 pkg_to_lib_crate.insert(pkg, crate_id);
522 // Add dependencies on the core / std / alloc for rustc
523 for (name, krate) in public_deps.iter() {
524 if let Err(_) =
525 crate_graph.add_dep(crate_id, name.clone(), *krate)
526 {
527 log::error!(
528 "cyclic dependency on {} for {}",
529 name,
530 &cargo[pkg].name
531 )
532 }
533 }
534 rustc_pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);
535 }
536 }
537 }
538 // Now add a dep edge from all targets of upstream to the lib
539 // target of downstream.
540 for pkg in rustc_workspace.packages() {
541 for dep in rustc_workspace[pkg].dependencies.iter() {
542 let name = CrateName::new(&dep.name).unwrap();
543 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
544 for &from in rustc_pkg_crates.get(&pkg).into_iter().flatten() {
545 if let Err(_) = crate_graph.add_dep(from, name.clone(), to) {
546 log::error!(
547 "cyclic dependency {} -> {}",
548 &rustc_workspace[pkg].name,
549 &rustc_workspace[dep.pkg].name
550 )
551 }
552 }
553 }
554 }
555 }
556
557 // Add dependencies for all the crates of the current workspace to rustc_private libraries
558 for dep in rustc_workspace.packages() {
559 let name = CrateName::normalize_dashes(&rustc_workspace[dep].name);
560
561 if let Some(&to) = pkg_to_lib_crate.get(&dep) {
562 for pkg in cargo.packages() {
563 if !cargo[pkg].is_member {
564 continue;
565 }
566 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
567 if let Err(_) = crate_graph.add_dep(from, name.clone(), to) {
568 log::error!(
569 "cyclic dependency {} -> {}",
570 &cargo[pkg].name,
571 &rustc_workspace[dep].name
572 )
573 }
574 }
575 }
576 }
577 }
578 }
580 } 579 }
581 } 580 }
582 if crate_graph.patch_cfg_if() { 581 if crate_graph.patch_cfg_if() {