diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-11-05 18:06:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-05 18:06:06 +0100 |
| commit | 305cb7133f7e68e9ecad6319363909dc371b6fa9 (patch) | |
| tree | e8e9d585ad9f290f0c8658db641283469b0cb35a | |
| parent | 3eac639e1e1c6e4f0762d81521939ca8555ea77a (diff) | |
| parent | 5e4618ff1433e92009c7478933874f5f23b34e29 (diff) | |
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.
| -rw-r--r-- | src/bootstrap/builder.rs | 18 | ||||
| -rw-r--r-- | src/bootstrap/doc.rs | 35 |
2 files changed, 28 insertions, 25 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 6de37463633..406bae02d84 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -2207,6 +2207,24 @@ impl<'a> Builder<'a> { false } + + pub(crate) fn maybe_open_in_browser<S: Step>(&self, path: impl AsRef<Path>) { + if self.was_invoked_explicitly::<S>(Kind::Doc) { + self.open_in_browser(path); + } + } + + pub(crate) fn open_in_browser(&self, path: impl AsRef<Path>) { + if self.config.dry_run || !self.config.cmd.open() { + return; + } + + let path = path.as_ref(); + self.info(&format!("Opening doc {}", path.display())); + if let Err(err) = opener::open(path) { + self.info(&format!("{}\n", err)); + } + } } #[cfg(test)] diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 5d265b9ad0c..1357718b84e 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -85,18 +85,6 @@ book!( StyleGuide, "src/doc/style-guide", "style-guide"; ); -fn open(builder: &Builder<'_>, path: impl AsRef<Path>) { - if builder.config.dry_run || !builder.config.cmd.open() { - return; - } - - let path = path.as_ref(); - builder.info(&format!("Opening doc {}", path.display())); - if let Err(err) = opener::open(path) { - builder.info(&format!("{}\n", err)); - } -} - // "library/std" -> ["library", "std"] // // Used for deciding whether a particular step is one requested by the user on @@ -240,11 +228,9 @@ impl Step for TheBook { invoke_rustdoc(builder, compiler, &shared_assets, target, path); } - if builder.was_invoked_explicitly::<Self>(Kind::Doc) { - let out = builder.doc_out(target); - let index = out.join("book").join("index.html"); - open(builder, &index); - } + let out = builder.doc_out(target); + let index = out.join("book").join("index.html"); + builder.maybe_open_in_browser::<Self>(index); } } @@ -386,7 +372,7 @@ impl Step for Standalone { // with no particular explicit doc requested (e.g. library/core). if builder.paths.is_empty() || builder.was_invoked_explicitly::<Self>(Kind::Doc) { let index = out.join("index.html"); - open(builder, &index); + builder.open_in_browser(&index); } } } @@ -507,7 +493,7 @@ impl Step for Std { for requested_crate in requested_crates { if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) { let index = out.join(requested_crate).join("index.html"); - open(builder, &index); + builder.open_in_browser(index); } } } @@ -759,7 +745,7 @@ impl Step for Rustc { // Let's open the first crate documentation page: if let Some(krate) = to_open { let index = out.join(krate).join("index.html"); - open(builder, &index); + builder.open_in_browser(index); } } } @@ -1019,10 +1005,9 @@ impl Step for RustcBook { name: INTERNER.intern_str("rustc"), src: INTERNER.intern_path(out_base), }); - if builder.was_invoked_explicitly::<Self>(Kind::Doc) { - let out = builder.doc_out(self.target); - let index = out.join("rustc").join("index.html"); - open(builder, &index); - } + + let out = builder.doc_out(self.target); + let index = out.join("rustc").join("index.html"); + builder.maybe_open_in_browser::<Self>(index); } } |
