@@ -77,7 +77,7 @@ pub fn extract_zip(archive_path: &Path) -> Result<()> {
7777}
7878
7979#[ instrument( level = "trace" , skip_all) ]
80- pub fn compile_runtime ( path : & Path , release : bool , is_simulation_mode : bool ) -> Result < ( ) > {
80+ fn compile_runtime ( path : & Path , release : bool , is_simulation_mode : bool ) -> Result < ( ) > {
8181 info ! ( "Compiling Hyperdrive..." ) ;
8282
8383 // build the packages
@@ -174,10 +174,7 @@ pub fn get_platform_runtime_name(is_simulation_mode: bool) -> Result<String> {
174174}
175175
176176#[ instrument( level = "trace" , skip_all) ]
177- pub async fn get_runtime_binary (
178- version : & str ,
179- is_simulation_mode : bool ,
180- ) -> Result < ( PathBuf , String ) > {
177+ async fn get_runtime_binary ( version : & str , is_simulation_mode : bool ) -> Result < PathBuf > {
181178 let zip_name = get_platform_runtime_name ( is_simulation_mode) ?;
182179
183180 let version = if version != "latest" {
@@ -214,7 +211,36 @@ pub async fn get_runtime_binary(
214211 get_runtime_binary_inner ( & version, & zip_name, & runtime_dir) . await ?;
215212 }
216213
217- Ok ( ( runtime_path, version) )
214+ Ok ( runtime_path)
215+ }
216+
217+ #[ instrument( level = "trace" , skip_all) ]
218+ pub async fn get_or_build_runtime_binary (
219+ version : & str ,
220+ is_simulation_mode : bool ,
221+ runtime_path : Option < PathBuf > ,
222+ is_release : bool ,
223+ ) -> Result < PathBuf > {
224+ let runtime_path = match runtime_path {
225+ None => get_runtime_binary ( & version, is_simulation_mode) . await ?,
226+ Some ( runtime_path) => {
227+ if !runtime_path. exists ( ) {
228+ return Err ( eyre ! ( "--runtime-path {:?} does not exist." , runtime_path) ) ;
229+ }
230+ let runtime_path = if runtime_path. is_dir ( ) {
231+ // Compile the runtime binary
232+ compile_runtime ( & runtime_path, is_release, is_simulation_mode) ?;
233+ runtime_path
234+ . join ( "target" )
235+ . join ( if is_release { "release" } else { "debug" } )
236+ . join ( "hyperdrive" )
237+ } else {
238+ runtime_path
239+ } ;
240+ runtime_path
241+ }
242+ } ;
243+ Ok ( runtime_path)
218244}
219245
220246#[ instrument( level = "trace" , skip_all) ]
@@ -425,46 +451,8 @@ pub async fn execute(
425451 verbosity : u8 ,
426452 mut args : Vec < String > ,
427453) -> Result < ( ) > {
428- println ! ( "a" ) ;
429454 let detached = false ; // TODO: to argument?
430- // TODO: factor out with run_tests?
431- let ( runtime_path, version) = match runtime_path {
432- None => get_runtime_binary ( & version, true ) . await ?,
433- Some ( runtime_path) => {
434- println ! ( "b" ) ;
435- if !runtime_path. exists ( ) {
436- return Err ( eyre ! ( "--runtime-path {:?} does not exist." , runtime_path) ) ;
437- }
438- let runtime_path = if runtime_path. is_dir ( ) {
439- // Compile the runtime binary
440- compile_runtime ( & runtime_path, release, true ) ?;
441- runtime_path
442- . join ( "target" )
443- . join ( if release { "release" } else { "debug" } )
444- . join ( "hyperdrive" )
445- } else {
446- runtime_path
447- } ;
448- let Some ( ( output, _) ) = build:: run_command (
449- Command :: new ( "bash" ) . args ( [ "-c" , & format ! ( "{} --version" , runtime_path. display( ) ) ] ) ,
450- false ,
451- ) ?
452- else {
453- return Err ( eyre ! ( "couldn't get Hyperdrive version" ) ) ;
454- } ;
455- let version = output
456- . split ( '\n' )
457- . nth ( 0 )
458- //.rev()
459- //.nth(1)
460- . unwrap ( )
461- . split ( ' ' )
462- . last ( )
463- . unwrap ( ) ;
464- ( runtime_path, version. to_string ( ) )
465- }
466- } ;
467- let version = version. strip_prefix ( "v" ) . unwrap_or_else ( || & version) ;
455+ let runtime_path = get_or_build_runtime_binary ( & version, true , runtime_path, release) . await ?;
468456
469457 let mut task_handles = Vec :: new ( ) ;
470458
@@ -495,18 +483,12 @@ pub async fn execute(
495483 let _cleanup_context = CleanupContext :: new ( send_to_cleanup_for_cleanup) ;
496484
497485 if !fake_node_name. contains ( "." ) {
498- fake_node_name. push_str ( ".dev " ) ;
486+ fake_node_name. push_str ( ".os " ) ;
499487 }
500488
501489 // boot fakechain
502- let version = version. parse ( ) ?;
503- let anvil_process = chain:: start_chain (
504- fakechain_port,
505- recv_kill_in_start_chain,
506- Some ( version) ,
507- false ,
508- )
509- . await ?;
490+ let anvil_process =
491+ chain:: start_chain ( fakechain_port, recv_kill_in_start_chain, false , false ) . await ?;
510492
511493 if let Some ( rpc) = rpc {
512494 args. extend_from_slice ( & [ "--rpc" . into ( ) , rpc. into ( ) ] ) ;
0 commit comments