Skip to content

Commit

Permalink
Rollup merge of #108394 - ferrocene:pa-open, r=ozkanonur
Browse files Browse the repository at this point in the history
Make `x doc --open` work on every book

Before this PR, the `--open` flag had to be configured explicitly for every book, and most of them didn't configure it, resulting in the flag silently failing in all but two books.

In this PR, the code to check for the `--open` flag is in the underlying `RustbookSrc` step rather than all the individual steps. This is done by passing the parent step as a field of `RustbookSrc`, so that we can check for the correct step in `maybe_open_in_browser`.

This was part of a larger change that in the end wasn't worth it. Still, I think it could be useful as-is.
  • Loading branch information
Dylan-DPC committed Mar 1, 2023
2 parents f03e534 + 317be61 commit 38461f8
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ macro_rules! book {
target: self.target,
name: INTERNER.intern_str($book_name),
src: INTERNER.intern_path(builder.src.join($path)),
parent: Some(self),
})
}
}
Expand Down Expand Up @@ -119,18 +120,20 @@ impl Step for UnstableBook {
target: self.target,
name: INTERNER.intern_str("unstable-book"),
src: INTERNER.intern_path(builder.md_doc_out(self.target).join("unstable-book")),
parent: Some(self),
})
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct RustbookSrc {
struct RustbookSrc<P: Step> {
target: TargetSelection,
name: Interned<String>,
src: Interned<PathBuf>,
parent: Option<P>,
}

impl Step for RustbookSrc {
impl<P: Step> Step for RustbookSrc<P> {
type Output = ();

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand All @@ -152,13 +155,18 @@ impl Step for RustbookSrc {
let index = out.join("index.html");
let rustbook = builder.tool_exe(Tool::Rustbook);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
if builder.config.dry_run() || up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
return;

if !builder.config.dry_run() && !(up_to_date(&src, &index) || up_to_date(&rustbook, &index))
{
builder.info(&format!("Rustbook ({}) - {}", target, name));
let _ = fs::remove_dir_all(&out);

builder.run(rustbook_cmd.arg("build").arg(&src).arg("-d").arg(out));
}
builder.info(&format!("Rustbook ({}) - {}", target, name));
let _ = fs::remove_dir_all(&out);

builder.run(rustbook_cmd.arg("build").arg(&src).arg("-d").arg(out));
if self.parent.is_some() {
builder.maybe_open_in_browser::<P>(index)
}
}
}

Expand Down Expand Up @@ -205,6 +213,7 @@ impl Step for TheBook {
target,
name: INTERNER.intern_str("book"),
src: INTERNER.intern_path(builder.src.join(&relative_path)),
parent: Some(self),
});

// building older edition redirects
Expand All @@ -213,6 +222,9 @@ impl Step for TheBook {
target,
name: INTERNER.intern_string(format!("book/{}", edition)),
src: INTERNER.intern_path(builder.src.join(&relative_path).join(edition)),
// There should only be one book that is marked as the parent for each target, so
// treat the other editions as not having a parent.
parent: Option::<Self>::None,
});
}

Expand All @@ -228,10 +240,6 @@ impl Step for TheBook {

invoke_rustdoc(builder, compiler, &shared_assets, target, path);
}

let out = builder.doc_out(target);
let index = out.join("book").join("index.html");
builder.maybe_open_in_browser::<Self>(index);
}
}

Expand Down Expand Up @@ -1032,10 +1040,7 @@ impl Step for RustcBook {
target: self.target,
name: INTERNER.intern_str("rustc"),
src: INTERNER.intern_path(out_base),
parent: Some(self),
});

let out = builder.doc_out(self.target);
let index = out.join("rustc").join("index.html");
builder.maybe_open_in_browser::<Self>(index);
}
}

0 comments on commit 38461f8

Please sign in to comment.