@@ -7,9 +7,10 @@ use anyhow::Result;
7
7
use console:: style;
8
8
use rayon:: prelude:: * ;
9
9
use std:: io:: Write ;
10
+ use std:: path:: { Path , PathBuf } ;
10
11
use std:: time:: Instant ;
11
12
12
- fn remove_ast ( package : & packages:: Package , source_file : & str ) {
13
+ fn remove_ast ( package : & packages:: Package , source_file : & Path ) {
13
14
let _ = std:: fs:: remove_file ( helpers:: get_compiler_asset (
14
15
package,
15
16
& packages:: Namespace :: NoNamespace ,
@@ -18,7 +19,7 @@ fn remove_ast(package: &packages::Package, source_file: &str) {
18
19
) ) ;
19
20
}
20
21
21
- fn remove_iast ( package : & packages:: Package , source_file : & str ) {
22
+ fn remove_iast ( package : & packages:: Package , source_file : & Path ) {
22
23
let _ = std:: fs:: remove_file ( helpers:: get_compiler_asset (
23
24
package,
24
25
& packages:: Namespace :: NoNamespace ,
@@ -27,15 +28,15 @@ fn remove_iast(package: &packages::Package, source_file: &str) {
27
28
) ) ;
28
29
}
29
30
30
- fn remove_mjs_file ( source_file : & str , suffix : & String ) {
31
+ fn remove_mjs_file ( source_file : & Path , suffix : & String ) {
31
32
let _ = std:: fs:: remove_file ( helpers:: change_extension (
32
33
source_file,
33
34
// suffix.to_string includes the ., so we need to remove it
34
35
& suffix. to_string ( ) [ 1 ..] ,
35
36
) ) ;
36
37
}
37
38
38
- fn remove_compile_asset ( package : & packages:: Package , source_file : & str , extension : & str ) {
39
+ fn remove_compile_asset ( package : & packages:: Package , source_file : & Path , extension : & str ) {
39
40
let _ = std:: fs:: remove_file ( helpers:: get_compiler_asset (
40
41
package,
41
42
& package. namespace ,
@@ -50,7 +51,7 @@ fn remove_compile_asset(package: &packages::Package, source_file: &str, extensio
50
51
) ) ;
51
52
}
52
53
53
- pub fn remove_compile_assets ( package : & packages:: Package , source_file : & str ) {
54
+ pub fn remove_compile_assets ( package : & packages:: Package , source_file : & Path ) {
54
55
// optimization
55
56
// only issue cmti if there is an interfacce file
56
57
for extension in & [ "cmj" , "cmi" , "cmt" , "cmti" ] {
@@ -79,23 +80,20 @@ pub fn clean_mjs_files(build_state: &BuildState) {
79
80
. filter_map ( |spec| {
80
81
if spec. in_source {
81
82
Some ( (
82
- std:: path:: PathBuf :: from ( package. path . to_string ( ) )
83
- . join ( & source_file. implementation . path )
84
- . to_string_lossy ( )
85
- . to_string ( ) ,
83
+ package. path . join ( & source_file. implementation . path ) ,
86
84
root_package. config . get_suffix ( spec) ,
87
85
) )
88
86
} else {
89
87
None
90
88
}
91
89
} )
92
- . collect :: < Vec < ( String , String ) > > ( ) ,
90
+ . collect :: < Vec < ( PathBuf , String ) > > ( ) ,
93
91
)
94
92
}
95
93
_ => None ,
96
94
} )
97
95
. flatten ( )
98
- . collect :: < Vec < ( String , String ) > > ( ) ;
96
+ . collect :: < Vec < ( PathBuf , String ) > > ( ) ;
99
97
100
98
rescript_file_locations
101
99
. par_iter ( )
@@ -118,7 +116,7 @@ pub fn cleanup_previous_build(
118
116
let diff = compile_assets_state
119
117
. ast_rescript_file_locations
120
118
. difference ( & compile_assets_state. rescript_file_locations )
121
- . collect :: < Vec < & String > > ( ) ;
119
+ . collect :: < Vec < & PathBuf > > ( ) ;
122
120
123
121
let diff_len = diff. len ( ) ;
124
122
@@ -133,7 +131,7 @@ pub fn cleanup_previous_build(
133
131
..
134
132
} = compile_assets_state
135
133
. ast_modules
136
- . get ( & res_file_location. to_string ( ) )
134
+ . get ( * res_file_location)
137
135
. expect ( "Could not find module name for ast file" ) ;
138
136
139
137
let package = build_state
@@ -338,7 +336,12 @@ pub fn cleanup_after_build(build_state: &BuildState) {
338
336
} ) ;
339
337
}
340
338
341
- pub fn clean ( path : & str , show_progress : bool , bsc_path : Option < String > , build_dev_deps : bool ) -> Result < ( ) > {
339
+ pub fn clean (
340
+ path : & Path ,
341
+ show_progress : bool ,
342
+ bsc_path : & Option < PathBuf > ,
343
+ build_dev_deps : bool ,
344
+ ) -> Result < ( ) > {
342
345
let project_root = helpers:: get_abs_path ( path) ;
343
346
let workspace_root = helpers:: get_workspace_root ( & project_root) ;
344
347
let packages = packages:: make (
@@ -352,7 +355,7 @@ pub fn clean(path: &str, show_progress: bool, bsc_path: Option<String>, build_de
352
355
let root_config_name = packages:: read_package_name ( & project_root) ?;
353
356
let bsc_path = match bsc_path {
354
357
Some ( bsc_path) => helpers:: get_abs_path ( & bsc_path) ,
355
- None => helpers:: get_bsc ( & project_root, workspace_root. to_owned ( ) ) ,
358
+ None => helpers:: get_bsc ( & project_root, & workspace_root) ,
356
359
} ;
357
360
358
361
let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
0 commit comments