@@ -862,41 +862,15 @@ pub fn build(
862862
863863 let mut manifest_path = None ;
864864
865- let relative_build_path = std:: process:: Command :: new ( "find" )
866- . args ( [ & mount_path, "-name" , "Cargo.toml" ] )
867- . output ( )
868- . map_err ( |e| {
869- anyhow:: format_err!(
870- "Failed to find Cargo.toml files in root directory: {}" ,
871- e. to_string( )
872- )
873- } )
874- . and_then ( |output| {
875- ensure ! (
876- output. status. success( ) ,
877- "Failed to find Cargo.toml files in root directory:"
878- ) ;
879- for p in String :: from_utf8 ( output. stdout ) ?. split ( "\n " ) {
880- match get_lib_name_from_cargo_toml ( p) {
881- Ok ( name) => {
882- if name == library_name. clone ( ) . unwrap_or_default ( ) {
883- manifest_path = Some ( p. to_string ( ) . replace ( & mount_path, "" ) ) ;
884- return Ok ( p
885- . to_string ( )
886- . replace ( "Cargo.toml" , "" )
887- . replace ( & mount_path, "" ) ) ;
888- }
889- }
890- Err ( _) => {
891- continue ;
892- }
893- }
894- }
895- Err ( anyhow ! (
896- "No valid Cargo.toml files found in the project directory"
897- ) )
898- } )
899- . unwrap_or_else ( |_| "" . to_string ( ) ) ;
865+ let relative_build_path = match library_name. as_deref ( ) {
866+ Some ( library_name) => {
867+ let ( manifest_path_for_library_name, build_path) =
868+ find_relative_manifest_path_and_build_path ( & mount_path, library_name) ?;
869+ manifest_path = Some ( manifest_path_for_library_name) ;
870+ build_path
871+ }
872+ None => "" . into ( ) ,
873+ } ;
900874
901875 let workdir = std:: process:: Command :: new ( "docker" )
902876 . args ( [ "run" , "--rm" , & image, "pwd" ] )
@@ -1504,10 +1478,11 @@ pub fn parse_output(output: Output) -> anyhow::Result<String> {
15041478 output. status,
15051479 string_result
15061480 ) ;
1481+ let output = string_result?;
15071482
1508- let parsed_output = string_result?
1483+ let parsed_output = output
15091484 . strip_suffix ( "\n " )
1510- . ok_or_else ( || anyhow ! ( "Failed to parse output" ) ) ?
1485+ . ok_or_else ( || anyhow ! ( "Failed to parse output: {output} " ) ) ?
15111486 . to_string ( ) ;
15121487 Ok ( parsed_output)
15131488}
@@ -1685,3 +1660,45 @@ async fn export_pda_tx(
16851660
16861661 Ok ( ( ) )
16871662}
1663+
1664+ fn find_relative_manifest_path_and_build_path (
1665+ mount_path : & str ,
1666+ library_name : & str ,
1667+ ) -> anyhow:: Result < ( String , String ) > {
1668+ std:: process:: Command :: new ( "find" )
1669+ . args ( [ mount_path, "-name" , "Cargo.toml" ] )
1670+ . output ( )
1671+ . map_err ( |e| {
1672+ anyhow:: format_err!(
1673+ "Failed to find Cargo.toml files in root directory: {}" ,
1674+ e. to_string( )
1675+ )
1676+ } )
1677+ . and_then ( |output| {
1678+ ensure ! (
1679+ output. status. success( ) ,
1680+ "Failed to find Cargo.toml files in root directory"
1681+ ) ;
1682+ for p in String :: from_utf8 ( output. stdout ) ?. split ( "\n " ) {
1683+ match get_lib_name_from_cargo_toml ( p) {
1684+ Ok ( name) => {
1685+ if name == library_name {
1686+ let manifest_path = p. to_string ( ) . replace ( mount_path, "" ) ;
1687+ let build_path = p
1688+ . to_string ( )
1689+ . replace ( "Cargo.toml" , "" )
1690+ . replace ( mount_path, "" ) ;
1691+
1692+ return Ok ( ( manifest_path, build_path) ) ;
1693+ }
1694+ }
1695+ Err ( _) => {
1696+ continue ;
1697+ }
1698+ }
1699+ }
1700+ Err ( anyhow ! (
1701+ "No valid Cargo.toml file found in the directory for the library-name {library_name}"
1702+ ) )
1703+ } )
1704+ }
0 commit comments