@@ -12,7 +12,7 @@ use std::fs;
1212use std:: io;
1313use std:: path:: { Path , PathBuf } ;
1414
15- use crate :: builder:: { Builder , Compiler , Kind , RunConfig , ShouldRun , Step } ;
15+ use crate :: builder:: { Builder , Compiler , RunConfig , ShouldRun , Step } ;
1616use crate :: cache:: { Interned , INTERNER } ;
1717use crate :: compile;
1818use crate :: config:: { Config , TargetSelection } ;
@@ -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
@@ -384,10 +370,7 @@ impl Step for Standalone {
384370
385371 // We open doc/index.html as the default if invoked as `x.py doc --open`
386372 // with no particular explicit doc requested (e.g. library/core).
387- if builder. paths . is_empty ( ) || builder. was_invoked_explicitly :: < Self > ( Kind :: Doc ) {
388- let index = out. join ( "index.html" ) ;
389- open ( builder, & index) ;
390- }
373+ builder. maybe_open_in_browser :: < Self > ( out. join ( "index.html" ) ) ;
391374 }
392375}
393376
@@ -507,7 +490,7 @@ impl Step for Std {
507490 for requested_crate in requested_crates {
508491 if STD_PUBLIC_CRATES . iter ( ) . any ( |k| * k == requested_crate. as_str ( ) ) {
509492 let index = out. join ( requested_crate) . join ( "index.html" ) ;
510- open ( builder, & index) ;
493+ builder. open_in_browser ( index) ;
511494 }
512495 }
513496 }
@@ -759,7 +742,7 @@ impl Step for Rustc {
759742 // Let's open the first crate documentation page:
760743 if let Some ( krate) = to_open {
761744 let index = out. join ( krate) . join ( "index.html" ) ;
762- open ( builder, & index) ;
745+ builder. open_in_browser ( index) ;
763746 }
764747 }
765748}
@@ -1019,10 +1002,9 @@ impl Step for RustcBook {
10191002 name : INTERNER . intern_str ( "rustc" ) ,
10201003 src : INTERNER . intern_path ( out_base) ,
10211004 } ) ;
1022- if builder. was_invoked_explicitly :: < Self > ( Kind :: Doc ) {
1023- let out = builder. doc_out ( self . target ) ;
1024- let index = out. join ( "rustc" ) . join ( "index.html" ) ;
1025- open ( builder, & index) ;
1026- }
1005+
1006+ let out = builder. doc_out ( self . target ) ;
1007+ let index = out. join ( "rustc" ) . join ( "index.html" ) ;
1008+ builder. maybe_open_in_browser :: < Self > ( index) ;
10271009 }
10281010}
0 commit comments