@@ -7,9 +7,10 @@ use anyhow::Result;
77use console:: style;
88use rayon:: prelude:: * ;
99use std:: io:: Write ;
10+ use std:: path:: { Path , PathBuf } ;
1011use std:: time:: Instant ;
1112
12- fn remove_ast ( package : & packages:: Package , source_file : & str ) {
13+ fn remove_ast ( package : & packages:: Package , source_file : & Path ) {
1314 let _ = std:: fs:: remove_file ( helpers:: get_compiler_asset (
1415 package,
1516 & packages:: Namespace :: NoNamespace ,
@@ -18,7 +19,7 @@ fn remove_ast(package: &packages::Package, source_file: &str) {
1819 ) ) ;
1920}
2021
21- fn remove_iast ( package : & packages:: Package , source_file : & str ) {
22+ fn remove_iast ( package : & packages:: Package , source_file : & Path ) {
2223 let _ = std:: fs:: remove_file ( helpers:: get_compiler_asset (
2324 package,
2425 & packages:: Namespace :: NoNamespace ,
@@ -27,15 +28,14 @@ fn remove_iast(package: &packages::Package, source_file: &str) {
2728 ) ) ;
2829}
2930
30- fn remove_mjs_file ( source_file : & str , suffix : & String ) {
31- let _ = std:: fs:: remove_file ( helpers:: change_extension (
32- source_file,
31+ fn remove_mjs_file ( source_file : & Path , suffix : & String ) {
32+ let _ = std:: fs:: remove_file ( source_file. with_extension (
3333 // suffix.to_string includes the ., so we need to remove it
3434 & suffix. to_string ( ) [ 1 ..] ,
3535 ) ) ;
3636}
3737
38- fn remove_compile_asset ( package : & packages:: Package , source_file : & str , extension : & str ) {
38+ fn remove_compile_asset ( package : & packages:: Package , source_file : & Path , extension : & str ) {
3939 let _ = std:: fs:: remove_file ( helpers:: get_compiler_asset (
4040 package,
4141 & package. namespace ,
@@ -50,7 +50,7 @@ fn remove_compile_asset(package: &packages::Package, source_file: &str, extensio
5050 ) ) ;
5151}
5252
53- pub fn remove_compile_assets ( package : & packages:: Package , source_file : & str ) {
53+ pub fn remove_compile_assets ( package : & packages:: Package , source_file : & Path ) {
5454 // optimization
5555 // only issue cmti if there is an interfacce file
5656 for extension in & [ "cmj" , "cmi" , "cmt" , "cmti" ] {
@@ -79,23 +79,20 @@ pub fn clean_mjs_files(build_state: &BuildState) {
7979 . filter_map ( |spec| {
8080 if spec. in_source {
8181 Some ( (
82- std:: path:: PathBuf :: from ( package. path . to_string ( ) )
83- . join ( & source_file. implementation . path )
84- . to_string_lossy ( )
85- . to_string ( ) ,
82+ package. path . join ( & source_file. implementation . path ) ,
8683 root_package. config . get_suffix ( spec) ,
8784 ) )
8885 } else {
8986 None
9087 }
9188 } )
92- . collect :: < Vec < ( String , String ) > > ( ) ,
89+ . collect :: < Vec < ( PathBuf , String ) > > ( ) ,
9390 )
9491 }
9592 _ => None ,
9693 } )
9794 . flatten ( )
98- . collect :: < Vec < ( String , String ) > > ( ) ;
95+ . collect :: < Vec < ( PathBuf , String ) > > ( ) ;
9996
10097 rescript_file_locations
10198 . par_iter ( )
@@ -118,7 +115,7 @@ pub fn cleanup_previous_build(
118115 let diff = compile_assets_state
119116 . ast_rescript_file_locations
120117 . difference ( & compile_assets_state. rescript_file_locations )
121- . collect :: < Vec < & String > > ( ) ;
118+ . collect :: < Vec < & PathBuf > > ( ) ;
122119
123120 let diff_len = diff. len ( ) ;
124121
@@ -133,7 +130,7 @@ pub fn cleanup_previous_build(
133130 ..
134131 } = compile_assets_state
135132 . ast_modules
136- . get ( & res_file_location. to_string ( ) )
133+ . get ( * res_file_location)
137134 . expect ( "Could not find module name for ast file" ) ;
138135
139136 let package = build_state
@@ -338,7 +335,12 @@ pub fn cleanup_after_build(build_state: &BuildState) {
338335 } ) ;
339336}
340337
341- pub fn clean ( path : & str , show_progress : bool , bsc_path : Option < String > , build_dev_deps : bool ) -> Result < ( ) > {
338+ pub fn clean (
339+ path : & Path ,
340+ show_progress : bool ,
341+ bsc_path : & Option < PathBuf > ,
342+ build_dev_deps : bool ,
343+ ) -> Result < ( ) > {
342344 let project_root = helpers:: get_abs_path ( path) ;
343345 let workspace_root = helpers:: get_workspace_root ( & project_root) ;
344346 let packages = packages:: make (
@@ -352,7 +354,7 @@ pub fn clean(path: &str, show_progress: bool, bsc_path: Option<String>, build_de
352354 let root_config_name = packages:: read_package_name ( & project_root) ?;
353355 let bsc_path = match bsc_path {
354356 Some ( bsc_path) => helpers:: get_abs_path ( & bsc_path) ,
355- None => helpers:: get_bsc ( & project_root, workspace_root. to_owned ( ) ) ,
357+ None => helpers:: get_bsc ( & project_root, & workspace_root) ,
356358 } ;
357359
358360 let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
0 commit comments