@@ -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 ( )
@@ -255,11 +267,14 @@ pub fn parser_args(
255267 workspace_root : & Option < String > ,
256268 root_path : & str ,
257269 contents : & str ,
258- ) -> ( String , Vec < String > ) {
270+ ) -> ( PathBuf , Vec < String > ) {
259271 let file = & filename. to_string ( ) ;
260- let path = PathBuf :: from ( filename) ;
261- let ast_extension = path_to_ast_extension ( & path) ;
262- let ast_path = ( helpers:: get_basename ( & file. to_string ( ) ) . to_owned ( ) ) + ast_extension;
272+ // let path = PathBuf::from(filename);
273+ // let ast_extension = path_to_ast_extension(&path);
274+ // let ast_path = (helpers::get_basename(&file.to_string()).to_owned()) + ast_extension;
275+ let ast_path = helpers:: get_ast_path ( file) ;
276+ // make the dir of the ast_path if it doesn't exist yet:
277+
263278 let ppx_flags = config:: flatten_ppx_flags (
264279 & if let Some ( workspace_root) = workspace_root {
265280 format ! ( "{}/node_modules" , & workspace_root)
@@ -277,7 +292,7 @@ pub fn parser_args(
277292
278293 let file = "../../" . to_string ( ) + file;
279294 (
280- ast_path. to_string ( ) ,
295+ ast_path. to_owned ( ) ,
281296 [
282297 vec ! [ "-bs-v" . to_string( ) , format!( "{}" , version) ] ,
283298 ppx_flags,
@@ -290,7 +305,7 @@ pub fn parser_args(
290305 "-absname" . to_string( ) ,
291306 "-bs-ast" . to_string( ) ,
292307 "-o" . to_string( ) ,
293- ast_path. to_string( ) ,
308+ ast_path. to_string_lossy ( ) . to_string( ) ,
294309 file,
295310 ] ,
296311 ]
@@ -305,7 +320,7 @@ fn generate_ast(
305320 version : & str ,
306321 bsc_path : & str ,
307322 workspace_root : & Option < String > ,
308- ) -> Result < ( String , Option < helpers:: StdErr > ) , String > {
323+ ) -> Result < ( PathBuf , Option < helpers:: StdErr > ) , String > {
309324 let file_path = PathBuf :: from ( & package. path ) . join ( filename) ;
310325 let contents = helpers:: read_file ( & file_path) . expect ( "Error reading file" ) ;
311326
@@ -320,6 +335,11 @@ fn generate_ast(
320335 & contents,
321336 ) ;
322337
338+ // generate the dir of the ast_path (it mirrors the source file dir)
339+ helpers:: create_build_path (
340+ & ( package. get_build_path ( ) + "/" + & ast_path. parent ( ) . unwrap ( ) . to_string_lossy ( ) ) ,
341+ ) ;
342+
323343 /* Create .ast */
324344 let result = if let Some ( res_to_ast) = Some (
325345 Command :: new ( bsc_path)
@@ -347,26 +367,15 @@ fn generate_ast(
347367 ) )
348368 } ;
349369 if let Ok ( ( ast_path, _) ) = & result {
350- let dir = std:: path:: Path :: new ( filename) . parent ( ) . unwrap ( ) ;
370+ // let dir = std::path::Path::new(filename).parent().unwrap();
351371 let _ = std:: fs:: copy (
352- build_path_abs. to_string ( ) + "/" + ast_path,
353- std:: path:: Path :: new ( & package. get_bs_build_path ( ) )
354- . join ( dir)
355- . join ( ast_path) ,
372+ Path :: new ( & build_path_abs) . join ( & ast_path) ,
373+ std:: path:: Path :: new ( & package. get_build_path ( ) ) . join ( ast_path. file_name ( ) . unwrap ( ) ) ,
356374 ) ;
357375 }
358376 result
359377}
360378
361- fn path_to_ast_extension ( path : & Path ) -> & str {
362- let extension = path. extension ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
363- if helpers:: is_interface_ast_file ( extension) {
364- ".iast"
365- } else {
366- ".ast"
367- }
368- }
369-
370379fn include_ppx ( flag : & str , contents : & str ) -> bool {
371380 if flag. contains ( "bisect" ) {
372381 return std:: env:: var ( "BISECT_ENABLE" ) . is_ok ( ) ;
0 commit comments