@@ -29,7 +29,12 @@ pub fn generate_asts(
2929 match & module. source_type {
3030 SourceType :: MlMap ( _mlmap) => {
3131 let path = package. get_mlmap_path ( ) ;
32- ( module_name. to_owned ( ) , Ok ( ( path, None ) ) , Ok ( None ) , false )
32+ (
33+ module_name. to_owned ( ) ,
34+ Ok ( ( Path :: new ( & path) . to_path_buf ( ) , None ) ) ,
35+ Ok ( None ) ,
36+ false ,
37+ )
3338 }
3439
3540 SourceType :: SourceFile ( source_file) => {
@@ -69,13 +74,20 @@ pub fn generate_asts(
6974 } else {
7075 (
7176 Ok ( (
72- helpers:: get_basename ( & source_file. implementation . path ) . to_string ( ) + ".ast" ,
77+ Path :: new (
78+ & ( helpers:: get_basename ( & source_file. implementation . path ) . to_string ( )
79+ + ".ast" ) ,
80+ )
81+ . to_path_buf ( ) ,
7382 None ,
7483 ) ) ,
75- Ok ( source_file
76- . interface
77- . as_ref ( )
78- . map ( |i| ( helpers:: get_basename ( & i. path ) . to_string ( ) + ".iast" , None ) ) ) ,
84+ Ok ( source_file. interface . as_ref ( ) . map ( |i| {
85+ (
86+ Path :: new ( & ( helpers:: get_basename ( & i. path ) . to_string ( ) + ".iast" ) )
87+ . to_path_buf ( ) ,
88+ None ,
89+ )
90+ } ) ) ,
7991 false ,
8092 )
8193 } ;
@@ -86,8 +98,8 @@ pub fn generate_asts(
8698 } )
8799 . collect :: < Vec < (
88100 String ,
89- Result < ( String , Option < helpers:: StdErr > ) , String > ,
90- Result < Option < ( String , Option < helpers:: StdErr > ) > , String > ,
101+ Result < ( PathBuf , Option < helpers:: StdErr > ) , String > ,
102+ Result < Option < ( PathBuf , Option < helpers:: StdErr > ) > , String > ,
91103 bool ,
92104 ) > > ( )
93105 . into_iter ( )
@@ -250,11 +262,14 @@ pub fn parser_args(
250262 workspace_root : & Option < String > ,
251263 root_path : & str ,
252264 contents : & str ,
253- ) -> ( String , Vec < String > ) {
265+ ) -> ( PathBuf , Vec < String > ) {
254266 let file = & filename. to_string ( ) ;
255- let path = PathBuf :: from ( filename) ;
256- let ast_extension = path_to_ast_extension ( & path) ;
257- let ast_path = ( helpers:: get_basename ( & file. to_string ( ) ) . to_owned ( ) ) + ast_extension;
267+ // let path = PathBuf::from(filename);
268+ // let ast_extension = path_to_ast_extension(&path);
269+ // let ast_path = (helpers::get_basename(&file.to_string()).to_owned()) + ast_extension;
270+ let ast_path = helpers:: get_ast_path ( file) ;
271+ // make the dir of the ast_path if it doesn't exist yet:
272+
258273 let ppx_flags = config:: flatten_ppx_flags (
259274 & if let Some ( workspace_root) = workspace_root {
260275 format ! ( "{}/node_modules" , & workspace_root)
@@ -272,7 +287,7 @@ pub fn parser_args(
272287
273288 let file = "../../" . to_string ( ) + file;
274289 (
275- ast_path. to_string ( ) ,
290+ ast_path. to_owned ( ) ,
276291 [
277292 vec ! [ "-bs-v" . to_string( ) , format!( "{}" , version) ] ,
278293 ppx_flags,
@@ -285,7 +300,7 @@ pub fn parser_args(
285300 "-absname" . to_string( ) ,
286301 "-bs-ast" . to_string( ) ,
287302 "-o" . to_string( ) ,
288- ast_path. to_string( ) ,
303+ ast_path. to_string_lossy ( ) . to_string( ) ,
289304 file,
290305 ] ,
291306 ]
@@ -300,7 +315,7 @@ fn generate_ast(
300315 version : & str ,
301316 bsc_path : & str ,
302317 workspace_root : & Option < String > ,
303- ) -> Result < ( String , Option < helpers:: StdErr > ) , String > {
318+ ) -> Result < ( PathBuf , Option < helpers:: StdErr > ) , String > {
304319 let file_path = PathBuf :: from ( & package. path ) . join ( filename) ;
305320 let contents = helpers:: read_file ( & file_path) . expect ( "Error reading file" ) ;
306321
@@ -315,6 +330,11 @@ fn generate_ast(
315330 & contents,
316331 ) ;
317332
333+ // generate the dir of the ast_path (it mirrors the source file dir)
334+ helpers:: create_build_path (
335+ & ( package. get_build_path ( ) + "/" + & ast_path. parent ( ) . unwrap ( ) . to_string_lossy ( ) ) ,
336+ ) ;
337+
318338 /* Create .ast */
319339 let result = if let Some ( res_to_ast) = Some (
320340 Command :: new ( bsc_path)
@@ -342,26 +362,15 @@ fn generate_ast(
342362 ) )
343363 } ;
344364 if let Ok ( ( ast_path, _) ) = & result {
345- let dir = std:: path:: Path :: new ( filename) . parent ( ) . unwrap ( ) ;
365+ // let dir = std::path::Path::new(filename).parent().unwrap();
346366 let _ = std:: fs:: copy (
347- build_path_abs. to_string ( ) + "/" + ast_path,
348- std:: path:: Path :: new ( & package. get_bs_build_path ( ) )
349- . join ( dir)
350- . join ( ast_path) ,
367+ Path :: new ( & build_path_abs) . join ( & ast_path) ,
368+ std:: path:: Path :: new ( & package. get_build_path ( ) ) . join ( ast_path. file_name ( ) . unwrap ( ) ) ,
351369 ) ;
352370 }
353371 result
354372}
355373
356- fn path_to_ast_extension ( path : & Path ) -> & str {
357- let extension = path. extension ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
358- if helpers:: is_interface_ast_file ( extension) {
359- ".iast"
360- } else {
361- ".ast"
362- }
363- }
364-
365374fn include_ppx ( flag : & str , contents : & str ) -> bool {
366375 if flag. contains ( "bisect" ) {
367376 return std:: env:: var ( "BISECT_ENABLE" ) . is_ok ( ) ;
0 commit comments