From 400f23e04bde1d4dcbc1c935f3768aa6d470d73e Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Mar 2022 17:06:16 -0500 Subject: [PATCH 1/4] Simplify `make_run` for `test::Crate` by introducing `crate_paths` instead of calculating them after the fact --- src/bootstrap/lib.rs | 3 +++ src/bootstrap/metadata.rs | 6 +++++- src/bootstrap/test.rs | 36 ++++++------------------------------ 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 8f076ad914d9a..3a256bb50f215 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -301,7 +301,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>, @@ -491,6 +493,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 c8b76809abad7..83561ffdb36a0 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 From 50d1ee90e786c04e3751f7603dc581598c230f03 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Mar 2022 17:16:17 -0500 Subject: [PATCH 2/4] Fix `x doc compiler/rustc` This works by mapping the local path to a crate name before trying to fetch crates it depends on. --- src/bootstrap/doc.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 5f16716a0fdaf..1bb71e734f19f 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -554,13 +554,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::>(); @@ -621,16 +617,17 @@ impl Step for Rustc { ); } } else { - for root_crate in paths { - if !builder.src.join("compiler").join(&root_crate).exists() { + for root_crate_path in paths { + if !root_crate_path.exists() { builder.info(&format!( - "\tskipping - compiler/{} (unknown compiler crate)", - root_crate + "\tskipping - {} (unknown compiler crate)", + root_crate_path.display() )); } else { + let root_crate = builder.crate_paths[root_crate_path]; compiler_crates.extend( builder - .in_tree_crates(root_crate, Some(target)) + .in_tree_crates(&root_crate, Some(target)) .into_iter() .map(|krate| krate.name), ); From 43c16acc275df22c5bb66da5220a3d774d34db66 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Mar 2022 17:17:31 -0500 Subject: [PATCH 3/4] Remove dead code in `doc.rs` `run` is never called for invalid paths; they get filtered out by `should_run`. --- src/bootstrap/doc.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 1bb71e734f19f..7e40bdc4a3942 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -618,20 +618,13 @@ impl Step for Rustc { } } else { for root_crate_path in paths { - if !root_crate_path.exists() { - builder.info(&format!( - "\tskipping - {} (unknown compiler crate)", - root_crate_path.display() - )); - } else { - let root_crate = builder.crate_paths[root_crate_path]; - compiler_crates.extend( - builder - .in_tree_crates(&root_crate, Some(target)) - .into_iter() - .map(|krate| krate.name), - ); - } + let root_crate = builder.crate_paths[root_crate_path]; + compiler_crates.extend( + builder + .in_tree_crates(&root_crate, Some(target)) + .into_iter() + .map(|krate| krate.name), + ); } } From 72315919e66b10c1996497f780142df7b1ec0692 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Mar 2022 17:23:22 -0500 Subject: [PATCH 4/4] Reduce duplication in `impl Step for doc::Rustc` This should have no user-visible change. --- src/bootstrap/doc.rs | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 7e40bdc4a3942..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}; @@ -604,32 +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_path in paths { - let root_crate = builder.crate_paths[root_crate_path]; - 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.