Skip to content

Commit 08af805

Browse files
authored
Rollup merge of #103920 - ferrocene:pa-maybe-open-in-browser, r=jyn514
Move browser opening logic in `Builder` This allows `open()` to be called from other places in bootstrap (I need this for Ferrocene, as we keep our custom steps in `src/bootstrap/ferrocene`), and it simplifies the callers by moving the `was_invoked_explicitly` check into the function.
2 parents 8fd875d + 5e4618f commit 08af805

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/bootstrap/builder.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,24 @@ impl<'a> Builder<'a> {
22072207

22082208
false
22092209
}
2210+
2211+
pub(crate) fn maybe_open_in_browser<S: Step>(&self, path: impl AsRef<Path>) {
2212+
if self.was_invoked_explicitly::<S>(Kind::Doc) {
2213+
self.open_in_browser(path);
2214+
}
2215+
}
2216+
2217+
pub(crate) fn open_in_browser(&self, path: impl AsRef<Path>) {
2218+
if self.config.dry_run || !self.config.cmd.open() {
2219+
return;
2220+
}
2221+
2222+
let path = path.as_ref();
2223+
self.info(&format!("Opening doc {}", path.display()));
2224+
if let Err(err) = opener::open(path) {
2225+
self.info(&format!("{}\n", err));
2226+
}
2227+
}
22102228
}
22112229

22122230
#[cfg(test)]

src/bootstrap/doc.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,6 @@ book!(
8585
StyleGuide, "src/doc/style-guide", "style-guide";
8686
);
8787

88-
fn open(builder: &Builder<'_>, path: impl AsRef<Path>) {
89-
if builder.config.dry_run || !builder.config.cmd.open() {
90-
return;
91-
}
92-
93-
let path = path.as_ref();
94-
builder.info(&format!("Opening doc {}", path.display()));
95-
if let Err(err) = opener::open(path) {
96-
builder.info(&format!("{}\n", err));
97-
}
98-
}
99-
10088
// "library/std" -> ["library", "std"]
10189
//
10290
// Used for deciding whether a particular step is one requested by the user on
@@ -240,11 +228,9 @@ impl Step for TheBook {
240228
invoke_rustdoc(builder, compiler, &shared_assets, target, path);
241229
}
242230

243-
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
244-
let out = builder.doc_out(target);
245-
let index = out.join("book").join("index.html");
246-
open(builder, &index);
247-
}
231+
let out = builder.doc_out(target);
232+
let index = out.join("book").join("index.html");
233+
builder.maybe_open_in_browser::<Self>(index);
248234
}
249235
}
250236

@@ -386,7 +372,7 @@ impl Step for Standalone {
386372
// with no particular explicit doc requested (e.g. library/core).
387373
if builder.paths.is_empty() || builder.was_invoked_explicitly::<Self>(Kind::Doc) {
388374
let index = out.join("index.html");
389-
open(builder, &index);
375+
builder.open_in_browser(&index);
390376
}
391377
}
392378
}
@@ -516,7 +502,7 @@ impl Step for Std {
516502
for requested_crate in requested_crates {
517503
if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) {
518504
let index = out.join(requested_crate).join("index.html");
519-
open(builder, &index);
505+
builder.open_in_browser(index);
520506
}
521507
}
522508
}
@@ -736,7 +722,7 @@ impl Step for Rustc {
736722
// Let's open the first crate documentation page:
737723
if let Some(krate) = to_open {
738724
let index = out.join(krate).join("index.html");
739-
open(builder, &index);
725+
builder.open_in_browser(index);
740726
}
741727
}
742728
}
@@ -996,10 +982,9 @@ impl Step for RustcBook {
996982
name: INTERNER.intern_str("rustc"),
997983
src: INTERNER.intern_path(out_base),
998984
});
999-
if builder.was_invoked_explicitly::<Self>(Kind::Doc) {
1000-
let out = builder.doc_out(self.target);
1001-
let index = out.join("rustc").join("index.html");
1002-
open(builder, &index);
1003-
}
985+
986+
let out = builder.doc_out(self.target);
987+
let index = out.join("rustc").join("index.html");
988+
builder.maybe_open_in_browser::<Self>(index);
1004989
}
1005990
}

0 commit comments

Comments
 (0)