diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 5f16716a0fdaf..077a86af50b2e 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -7,7 +7,6 @@ //! Everything here is basically just a shim around calling either `rustbook` or //! `rustdoc`. -use std::collections::HashSet; use std::fs; use std::io; use std::path::{Path, PathBuf}; @@ -554,13 +553,9 @@ impl Step for Rustc { let paths = builder .paths .iter() - .map(components_simplified) - .filter_map(|path| { - if path.get(0) == Some(&"compiler") { - path.get(1).map(|p| p.to_owned()) - } else { - None - } + .filter(|path| { + let components = components_simplified(path); + components.len() >= 2 && components[0] == "compiler" }) .collect::>(); @@ -608,38 +603,22 @@ impl Step for Rustc { cargo.rustdocflag("--extern-html-root-url"); cargo.rustdocflag("ena=https://docs.rs/ena/latest/"); - let mut compiler_crates = HashSet::new(); - - if paths.is_empty() { - // Find dependencies for top level crates. - for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] { - compiler_crates.extend( - builder - .in_tree_crates(root_crate, Some(target)) - .into_iter() - .map(|krate| krate.name), - ); - } + let root_crates = if paths.is_empty() { + vec![ + INTERNER.intern_str("rustc_driver"), + INTERNER.intern_str("rustc_codegen_llvm"), + INTERNER.intern_str("rustc_codegen_ssa"), + ] } else { - for root_crate in paths { - if !builder.src.join("compiler").join(&root_crate).exists() { - builder.info(&format!( - "\tskipping - compiler/{} (unknown compiler crate)", - root_crate - )); - } else { - compiler_crates.extend( - builder - .in_tree_crates(root_crate, Some(target)) - .into_iter() - .map(|krate| krate.name), - ); - } - } - } + paths.into_iter().map(|p| builder.crate_paths[p]).collect() + }; + // Find dependencies for top level crates. + let compiler_crates = root_crates.iter().flat_map(|krate| { + builder.in_tree_crates(krate, Some(target)).into_iter().map(|krate| krate.name) + }); let mut to_open = None; - for krate in &compiler_crates { + for krate in compiler_crates { // Create all crate output directories first to make sure rustdoc uses // relative links. // FIXME: Cargo should probably do this itself. diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 570a61742bcf3..b93fc791820f4 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -302,7 +302,9 @@ pub struct Build { ar: HashMap, ranlib: HashMap, // Miscellaneous + // allow bidirectional lookups: both name -> path and path -> name crates: HashMap, Crate>, + crate_paths: HashMap>, is_sudo: bool, ci_env: CiEnv, delayed_failures: RefCell>, @@ -492,6 +494,7 @@ impl Build { ar: HashMap::new(), ranlib: HashMap::new(), crates: HashMap::new(), + crate_paths: HashMap::new(), is_sudo, ci_env: CiEnv::current(), delayed_failures: RefCell::new(Vec::new()), diff --git a/src/bootstrap/metadata.rs b/src/bootstrap/metadata.rs index 59dc50be47f06..e193e70a0c417 100644 --- a/src/bootstrap/metadata.rs +++ b/src/bootstrap/metadata.rs @@ -49,7 +49,11 @@ pub fn build(build: &mut Build) { .filter(|dep| dep.source.is_none()) .map(|dep| INTERNER.intern_string(dep.name)) .collect(); - build.crates.insert(name, Crate { name, deps, path }); + let krate = Crate { name, deps, path }; + let relative_path = krate.local_path(build); + build.crates.insert(name, krate); + let existing_path = build.crate_paths.insert(relative_path, name); + assert!(existing_path.is_none(), "multiple crates with the same path"); } } } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 81200ba60b026..9d7ea09fc8259 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -21,7 +21,6 @@ use crate::native; use crate::tool::{self, SourceType, Tool}; use crate::toolstate::ToolState; use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t}; -use crate::Crate as CargoCrate; use crate::{envify, CLang, DocTests, GitRepo, Mode}; const ADB_TEST_DIR: &str = "/data/tmp/work"; @@ -1901,19 +1900,10 @@ impl Step for CrateLibrustc { fn make_run(run: RunConfig<'_>) { let builder = run.builder; let compiler = builder.compiler(builder.top_stage, run.build_triple()); + let krate = builder.crate_paths[&run.path]; + let test_kind = builder.kind.into(); - for krate in builder.in_tree_crates("rustc-main", Some(run.target)) { - if krate.path.ends_with(&run.path) { - let test_kind = builder.kind.into(); - - builder.ensure(CrateLibrustc { - compiler, - target: run.target, - test_kind, - krate: krate.name, - }); - } - } + builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, krate }); } fn run(self, builder: &Builder<'_>) { @@ -1947,24 +1937,10 @@ impl Step for Crate { fn make_run(run: RunConfig<'_>) { let builder = run.builder; let compiler = builder.compiler(builder.top_stage, run.build_triple()); + let test_kind = builder.kind.into(); + let krate = builder.crate_paths[&run.path]; - let make = |mode: Mode, krate: &CargoCrate| { - let test_kind = builder.kind.into(); - - builder.ensure(Crate { - compiler, - target: run.target, - mode, - test_kind, - krate: krate.name, - }); - }; - - for krate in builder.in_tree_crates("test", Some(run.target)) { - if krate.path.ends_with(&run.path) { - make(Mode::Std, krate); - } - } + builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, krate }); } /// Runs all unit tests plus documentation tests for a given crate defined