66
77use serde_json:: Value ;
88use std:: fs:: read_to_string;
9- use std:: path:: { Path , PathBuf } ;
9+ use std:: path:: Path ;
1010use std:: process:: { Command , Output } ;
1111
1212fn get_available_browser_ui_test_version_inner ( global : bool ) -> Option < String > {
@@ -75,7 +75,6 @@ fn main() {
7575}
7676
7777fn build_books ( out_dir : & Path ) {
78- let exe = build_mdbook ( ) ;
7978 let root = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
8079 let books_dir = root. join ( "tests/gui/books" ) ;
8180 for entry in books_dir. read_dir ( ) . unwrap ( ) {
@@ -85,7 +84,7 @@ fn build_books(out_dir: &Path) {
8584 continue ;
8685 }
8786 println ! ( "Building `{}`" , path. display( ) ) ;
88- let mut cmd = Command :: new ( & exe ) ;
87+ let mut cmd = Command :: new ( env ! ( "CARGO_BIN_EXE_mdbook" ) ) ;
8988 let output = cmd
9089 . arg ( "build" )
9190 . arg ( "--dest-dir" )
@@ -97,28 +96,6 @@ fn build_books(out_dir: &Path) {
9796 }
9897}
9998
100- fn build_mdbook ( ) -> PathBuf {
101- let mut cmd = Command :: new ( "cargo" ) ;
102- let output = cmd
103- . arg ( "build" )
104- . output ( )
105- . expect ( "cargo should be installed" ) ;
106- check_status ( & cmd, & output) ;
107- let target_dir = detect_target_dir ( ) ;
108- target_dir. join ( "debug/mdbook" )
109- }
110-
111- fn detect_target_dir ( ) -> PathBuf {
112- let mut cmd = Command :: new ( "cargo" ) ;
113- let output = cmd
114- . args ( [ "metadata" , "--format-version=1" , "--no-deps" ] )
115- . output ( )
116- . expect ( "cargo should be installed" ) ;
117- check_status ( & cmd, & output) ;
118- let v: serde_json:: Value = serde_json:: from_slice ( & output. stdout ) . expect ( "invalid json" ) ;
119- PathBuf :: from ( v[ "target_directory" ] . as_str ( ) . unwrap ( ) )
120- }
121-
12299fn check_status ( cmd : & Command , output : & Output ) {
123100 if !output. status . success ( ) {
124101 eprintln ! ( "error: `{cmd:?}` failed" ) ;
0 commit comments