Skip to content

Commit 04006d8

Browse files
committed
Auto merge of #89182 - GuillaumeGomez:boostrap-explicit-request, r=Mark-Simulacrum
Simplify explicit request check and allow to run "doc src/librustdoc" even without config set Originally I wanted to allow the command `doc src/librustdoc` to work when passed explicitly but then `@Mark-Simulacrum` recommended me to generalize it, so here we are! r? `@Mark-Simulacrum`
2 parents c81c3ea + 10bef56 commit 04006d8

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Diff for: src/bootstrap/builder.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,22 @@ impl<'a> Builder<'a> {
16171617
// Only execute if it's supposed to run as default
16181618
if desc.default && should_run.is_really_default() { self.ensure(step) } else { None }
16191619
}
1620+
1621+
/// Checks if any of the "should_run" paths is in the `Builder` paths.
1622+
pub(crate) fn was_invoked_explicitly<S: Step>(&'a self) -> bool {
1623+
let desc = StepDescription::from::<S>();
1624+
let should_run = (desc.should_run)(ShouldRun::new(self));
1625+
1626+
for path in &self.paths {
1627+
if should_run.paths.iter().any(|s| s.has(path))
1628+
&& !desc.is_excluded(self, &PathSet::Suite(path.clone()))
1629+
{
1630+
return true;
1631+
}
1632+
}
1633+
1634+
false
1635+
}
16201636
}
16211637

16221638
#[cfg(test)]

Diff for: src/bootstrap/doc.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,10 @@ fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
102102
// Used for deciding whether a particular step is one requested by the user on
103103
// the `x.py doc` command line, which determines whether `--open` will open that
104104
// page.
105-
fn components_simplified(path: &PathBuf) -> Vec<&str> {
105+
pub(crate) fn components_simplified(path: &PathBuf) -> Vec<&str> {
106106
path.iter().map(|component| component.to_str().unwrap_or("???")).collect()
107107
}
108108

109-
fn is_explicit_request(builder: &Builder<'_>, path: &str) -> bool {
110-
builder
111-
.paths
112-
.iter()
113-
.map(components_simplified)
114-
.any(|requested| requested.iter().copied().eq(path.split('/')))
115-
}
116-
117109
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
118110
pub struct UnstableBook {
119111
target: TargetSelection,
@@ -248,7 +240,7 @@ impl Step for TheBook {
248240
invoke_rustdoc(builder, compiler, target, path);
249241
}
250242

251-
if is_explicit_request(builder, "src/doc/book") {
243+
if builder.was_invoked_explicitly::<Self>() {
252244
let out = builder.doc_out(target);
253245
let index = out.join("book").join("index.html");
254246
open(builder, &index);
@@ -408,7 +400,7 @@ impl Step for Standalone {
408400

409401
// We open doc/index.html as the default if invoked as `x.py doc --open`
410402
// with no particular explicit doc requested (e.g. library/core).
411-
if builder.paths.is_empty() || is_explicit_request(builder, "src/doc") {
403+
if builder.paths.is_empty() || builder.was_invoked_explicitly::<Self>() {
412404
let index = out.join("index.html");
413405
open(builder, &index);
414406
}
@@ -553,7 +545,6 @@ impl Step for Rustc {
553545
fn run(self, builder: &Builder<'_>) {
554546
let stage = self.stage;
555547
let target = self.target;
556-
let mut is_explicit_request = false;
557548
builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
558549

559550
let paths = builder
@@ -562,15 +553,14 @@ impl Step for Rustc {
562553
.map(components_simplified)
563554
.filter_map(|path| {
564555
if path.get(0) == Some(&"compiler") {
565-
is_explicit_request = true;
566556
path.get(1).map(|p| p.to_owned())
567557
} else {
568558
None
569559
}
570560
})
571561
.collect::<Vec<_>>();
572562

573-
if !builder.config.compiler_docs && !is_explicit_request {
563+
if !builder.config.compiler_docs && !builder.was_invoked_explicitly::<Self>() {
574564
builder.info("\tskipping - compiler/librustdoc docs disabled");
575565
return;
576566
}
@@ -700,15 +690,22 @@ macro_rules! tool_doc {
700690
fn run(self, builder: &Builder<'_>) {
701691
let stage = self.stage;
702692
let target = self.target;
703-
builder.info(&format!("Documenting stage{} {} ({})", stage, stringify!($tool).to_lowercase(), target));
693+
builder.info(
694+
&format!(
695+
"Documenting stage{} {} ({})",
696+
stage,
697+
stringify!($tool).to_lowercase(),
698+
target,
699+
),
700+
);
704701

705702
// This is the intended out directory for compiler documentation.
706703
let out = builder.compiler_doc_out(target);
707704
t!(fs::create_dir_all(&out));
708705

709706
let compiler = builder.compiler(stage, builder.config.build);
710707

711-
if !builder.config.compiler_docs {
708+
if !builder.config.compiler_docs && !builder.was_invoked_explicitly::<Self>() {
712709
builder.info("\tskipping - compiler/tool docs disabled");
713710
return;
714711
}
@@ -913,7 +910,7 @@ impl Step for RustcBook {
913910
name: INTERNER.intern_str("rustc"),
914911
src: INTERNER.intern_path(out_base),
915912
});
916-
if is_explicit_request(builder, "src/doc/rustc") {
913+
if builder.was_invoked_explicitly::<Self>() {
917914
let out = builder.doc_out(self.target);
918915
let index = out.join("rustc").join("index.html");
919916
open(builder, &index);

0 commit comments

Comments
 (0)