@@ -4,11 +4,11 @@ use crate::helpers;
44use ahash:: { AHashMap , AHashSet } ;
55use rayon:: prelude:: * ;
66use std:: fs;
7- use std:: path:: PathBuf ;
7+ use std:: path:: { Path , PathBuf } ;
88use std:: time:: SystemTime ;
99
1010pub fn read ( build_state : & mut BuildState ) -> CompileAssetsState {
11- let mut ast_modules: AHashMap < String , AstModule > = AHashMap :: new ( ) ;
11+ let mut ast_modules: AHashMap < PathBuf , AstModule > = AHashMap :: new ( ) ;
1212 let mut cmi_modules: AHashMap < String , SystemTime > = AHashMap :: new ( ) ;
1313 let mut cmt_modules: AHashMap < String , SystemTime > = AHashMap :: new ( ) ;
1414 let mut ast_rescript_file_locations = AHashSet :: new ( ) ;
@@ -20,31 +20,24 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
2020 SourceType :: SourceFile ( source_file) => {
2121 let package = build_state. packages . get ( & module. package_name ) . unwrap ( ) ;
2222
23- Some (
24- PathBuf :: from ( & package. path )
25- . join ( & source_file. implementation . path )
26- . to_string_lossy ( )
27- . to_string ( ) ,
28- )
23+ Some ( PathBuf :: from ( & package. path ) . join ( & source_file. implementation . path ) )
2924 }
3025 _ => None ,
3126 } )
32- . collect :: < AHashSet < String > > ( ) ;
27+ . collect :: < AHashSet < PathBuf > > ( ) ;
3328
3429 rescript_file_locations. extend (
3530 build_state
3631 . modules
3732 . values ( )
3833 . filter_map ( |module| {
3934 let package = build_state. packages . get ( & module. package_name ) . unwrap ( ) ;
40- module. get_interface ( ) . as_ref ( ) . map ( |interface| {
41- PathBuf :: from ( & package. path )
42- . join ( & interface. path )
43- . to_string_lossy ( )
44- . to_string ( )
45- } )
35+ module
36+ . get_interface ( )
37+ . as_ref ( )
38+ . map ( |interface| PathBuf :: from ( & package. path ) . join ( & interface. path ) )
4639 } )
47- . collect :: < AHashSet < String > > ( ) ,
40+ . collect :: < AHashSet < PathBuf > > ( ) ,
4841 ) ;
4942
5043 // scan all ast files in all packages
@@ -84,18 +77,18 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
8477 |( path, last_modified, extension, package_name, package_namespace, package_is_root) | {
8578 match extension. as_str ( ) {
8679 "iast" | "ast" => {
87- let module_name =
88- helpers:: file_path_to_module_name ( path. to_str ( ) . unwrap ( ) , package_namespace) ;
80+ let module_name = helpers:: file_path_to_module_name ( path, package_namespace) ;
8981
90- let ast_file_path = path. to_str ( ) . unwrap ( ) . to_owned ( ) ;
91- let res_file_path = get_res_path_from_ast ( & ast_file_path ) ;
82+ let ast_file_path = path. to_path_buf ( ) ;
83+ let res_file_path = get_res_path_from_ast ( & path ) ;
9284 let root_package = build_state
9385 . packages
9486 . get ( & build_state. root_config_name )
9587 . expect ( "Could not find root package" ) ;
9688 if let Some ( res_file_path) = res_file_path {
89+ let res_file_path_buf = PathBuf :: from ( res_file_path) ;
9790 let _ = ast_modules. insert (
98- res_file_path . to_owned ( ) ,
91+ res_file_path_buf . clone ( ) ,
9992 AstModule {
10093 module_name,
10194 package_name : package_name. to_owned ( ) ,
@@ -108,12 +101,12 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
108101 . get_suffix ( root_package. config . get_package_specs ( ) . first ( ) . unwrap ( ) ) ,
109102 } ,
110103 ) ;
111- let _ = ast_rescript_file_locations. insert ( res_file_path ) ;
104+ let _ = ast_rescript_file_locations. insert ( res_file_path_buf ) ;
112105 }
113106 }
114107 "cmi" => {
115108 let module_name = helpers:: file_path_to_module_name (
116- path. to_str ( ) . unwrap ( ) ,
109+ path,
117110 // we don't want to include a namespace here because the CMI file
118111 // already includes a namespace
119112 & packages:: Namespace :: NoNamespace ,
@@ -122,7 +115,7 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
122115 }
123116 "cmt" => {
124117 let module_name = helpers:: file_path_to_module_name (
125- path. to_str ( ) . unwrap ( ) ,
118+ path,
126119 // we don't want to include a namespace here because the CMI file
127120 // already includes a namespace
128121 & packages:: Namespace :: NoNamespace ,
@@ -145,8 +138,8 @@ pub fn read(build_state: &mut BuildState) -> CompileAssetsState {
145138 }
146139}
147140
148- fn get_res_path_from_ast ( ast_file : & str ) -> Option < String > {
149- if let Ok ( lines) = helpers:: read_lines ( ast_file. to_string ( ) ) {
141+ fn get_res_path_from_ast ( ast_file : & Path ) -> Option < String > {
142+ if let Ok ( lines) = helpers:: read_lines ( ast_file) {
150143 // we skip the first line with is some null characters
151144 // the following lines in the AST are the dependency modules
152145 // we stop when we hit a line that starts with a "/", this is the path of the file.
0 commit comments