Skip to content

Commit

Permalink
Auto merge of #95502 - jyn514:doc-rustc, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Apr 10, 2022
2 parents f7b4824 + 7231591 commit 341883d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 68 deletions.
53 changes: 16 additions & 37 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<Vec<_>>();

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ pub struct Build {
ar: HashMap<TargetSelection, PathBuf>,
ranlib: HashMap<TargetSelection, PathBuf>,
// Miscellaneous
// allow bidirectional lookups: both name -> path and path -> name
crates: HashMap<Interned<String>, Crate>,
crate_paths: HashMap<PathBuf, Interned<String>>,
is_sudo: bool,
ci_env: CiEnv,
delayed_failures: RefCell<Vec<String>>,
Expand Down Expand Up @@ -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()),
Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
36 changes: 6 additions & 30 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<'_>) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 341883d

Please sign in to comment.