Skip to content

Commit 341883d

Browse files
committed
Auto merge of #95502 - jyn514:doc-rustc, r=Mark-Simulacrum
Fix `x doc compiler/rustc` This also has a few cleanups to `doc.rs`. The last two commits I don't care about, but the first commit I'd like to keep - it will be very useful for #44293. Fixes #95447.
2 parents f7b4824 + 7231591 commit 341883d

File tree

4 files changed

+30
-68
lines changed

4 files changed

+30
-68
lines changed

src/bootstrap/doc.rs

+16-37
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//! Everything here is basically just a shim around calling either `rustbook` or
88
//! `rustdoc`.
99
10-
use std::collections::HashSet;
1110
use std::fs;
1211
use std::io;
1312
use std::path::{Path, PathBuf};
@@ -554,13 +553,9 @@ impl Step for Rustc {
554553
let paths = builder
555554
.paths
556555
.iter()
557-
.map(components_simplified)
558-
.filter_map(|path| {
559-
if path.get(0) == Some(&"compiler") {
560-
path.get(1).map(|p| p.to_owned())
561-
} else {
562-
None
563-
}
556+
.filter(|path| {
557+
let components = components_simplified(path);
558+
components.len() >= 2 && components[0] == "compiler"
564559
})
565560
.collect::<Vec<_>>();
566561

@@ -608,38 +603,22 @@ impl Step for Rustc {
608603
cargo.rustdocflag("--extern-html-root-url");
609604
cargo.rustdocflag("ena=https://docs.rs/ena/latest/");
610605

611-
let mut compiler_crates = HashSet::new();
612-
613-
if paths.is_empty() {
614-
// Find dependencies for top level crates.
615-
for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] {
616-
compiler_crates.extend(
617-
builder
618-
.in_tree_crates(root_crate, Some(target))
619-
.into_iter()
620-
.map(|krate| krate.name),
621-
);
622-
}
606+
let root_crates = if paths.is_empty() {
607+
vec![
608+
INTERNER.intern_str("rustc_driver"),
609+
INTERNER.intern_str("rustc_codegen_llvm"),
610+
INTERNER.intern_str("rustc_codegen_ssa"),
611+
]
623612
} else {
624-
for root_crate in paths {
625-
if !builder.src.join("compiler").join(&root_crate).exists() {
626-
builder.info(&format!(
627-
"\tskipping - compiler/{} (unknown compiler crate)",
628-
root_crate
629-
));
630-
} else {
631-
compiler_crates.extend(
632-
builder
633-
.in_tree_crates(root_crate, Some(target))
634-
.into_iter()
635-
.map(|krate| krate.name),
636-
);
637-
}
638-
}
639-
}
613+
paths.into_iter().map(|p| builder.crate_paths[p]).collect()
614+
};
615+
// Find dependencies for top level crates.
616+
let compiler_crates = root_crates.iter().flat_map(|krate| {
617+
builder.in_tree_crates(krate, Some(target)).into_iter().map(|krate| krate.name)
618+
});
640619

641620
let mut to_open = None;
642-
for krate in &compiler_crates {
621+
for krate in compiler_crates {
643622
// Create all crate output directories first to make sure rustdoc uses
644623
// relative links.
645624
// FIXME: Cargo should probably do this itself.

src/bootstrap/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ pub struct Build {
302302
ar: HashMap<TargetSelection, PathBuf>,
303303
ranlib: HashMap<TargetSelection, PathBuf>,
304304
// Miscellaneous
305+
// allow bidirectional lookups: both name -> path and path -> name
305306
crates: HashMap<Interned<String>, Crate>,
307+
crate_paths: HashMap<PathBuf, Interned<String>>,
306308
is_sudo: bool,
307309
ci_env: CiEnv,
308310
delayed_failures: RefCell<Vec<String>>,
@@ -492,6 +494,7 @@ impl Build {
492494
ar: HashMap::new(),
493495
ranlib: HashMap::new(),
494496
crates: HashMap::new(),
497+
crate_paths: HashMap::new(),
495498
is_sudo,
496499
ci_env: CiEnv::current(),
497500
delayed_failures: RefCell::new(Vec::new()),

src/bootstrap/metadata.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ pub fn build(build: &mut Build) {
4949
.filter(|dep| dep.source.is_none())
5050
.map(|dep| INTERNER.intern_string(dep.name))
5151
.collect();
52-
build.crates.insert(name, Crate { name, deps, path });
52+
let krate = Crate { name, deps, path };
53+
let relative_path = krate.local_path(build);
54+
build.crates.insert(name, krate);
55+
let existing_path = build.crate_paths.insert(relative_path, name);
56+
assert!(existing_path.is_none(), "multiple crates with the same path");
5357
}
5458
}
5559
}

src/bootstrap/test.rs

+6-30
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::native;
2121
use crate::tool::{self, SourceType, Tool};
2222
use crate::toolstate::ToolState;
2323
use crate::util::{self, add_link_lib_path, dylib_path, dylib_path_var, output, t};
24-
use crate::Crate as CargoCrate;
2524
use crate::{envify, CLang, DocTests, GitRepo, Mode};
2625

2726
const ADB_TEST_DIR: &str = "/data/tmp/work";
@@ -1901,19 +1900,10 @@ impl Step for CrateLibrustc {
19011900
fn make_run(run: RunConfig<'_>) {
19021901
let builder = run.builder;
19031902
let compiler = builder.compiler(builder.top_stage, run.build_triple());
1903+
let krate = builder.crate_paths[&run.path];
1904+
let test_kind = builder.kind.into();
19041905

1905-
for krate in builder.in_tree_crates("rustc-main", Some(run.target)) {
1906-
if krate.path.ends_with(&run.path) {
1907-
let test_kind = builder.kind.into();
1908-
1909-
builder.ensure(CrateLibrustc {
1910-
compiler,
1911-
target: run.target,
1912-
test_kind,
1913-
krate: krate.name,
1914-
});
1915-
}
1916-
}
1906+
builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, krate });
19171907
}
19181908

19191909
fn run(self, builder: &Builder<'_>) {
@@ -1947,24 +1937,10 @@ impl Step for Crate {
19471937
fn make_run(run: RunConfig<'_>) {
19481938
let builder = run.builder;
19491939
let compiler = builder.compiler(builder.top_stage, run.build_triple());
1940+
let test_kind = builder.kind.into();
1941+
let krate = builder.crate_paths[&run.path];
19501942

1951-
let make = |mode: Mode, krate: &CargoCrate| {
1952-
let test_kind = builder.kind.into();
1953-
1954-
builder.ensure(Crate {
1955-
compiler,
1956-
target: run.target,
1957-
mode,
1958-
test_kind,
1959-
krate: krate.name,
1960-
});
1961-
};
1962-
1963-
for krate in builder.in_tree_crates("test", Some(run.target)) {
1964-
if krate.path.ends_with(&run.path) {
1965-
make(Mode::Std, krate);
1966-
}
1967-
}
1943+
builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, krate });
19681944
}
19691945

19701946
/// Runs all unit tests plus documentation tests for a given crate defined

0 commit comments

Comments
 (0)