@@ -7,6 +7,17 @@ use std::fs;
77use std:: path:: { Path , PathBuf } ;
88use std:: time:: SystemTime ;
99
10+ type CompileAsset = (
11+ PathBuf ,
12+ SystemTime ,
13+ String ,
14+ String ,
15+ PathBuf ,
16+ bool ,
17+ packages:: Namespace ,
18+ bool ,
19+ ) ;
20+
1021pub fn read ( build_state : & mut BuildCommandState ) -> anyhow:: Result < CompileAssetsState > {
1122 let mut ast_modules: AHashMap < PathBuf , AstModule > = AHashMap :: new ( ) ;
1223 let mut cmi_modules: AHashMap < String , SystemTime > = AHashMap :: new ( ) ;
@@ -45,53 +56,12 @@ pub fn read(build_state: &mut BuildCommandState) -> anyhow::Result<CompileAssets
4556 . packages
4657 . par_iter ( )
4758 . map ( |( _, package) | {
48- let read_dir = fs:: read_dir ( package. get_ocaml_build_path ( ) ) . unwrap ( ) ;
49- read_dir
50- . filter_map ( |entry| match entry {
51- Ok ( entry) => {
52- let path = entry. path ( ) ;
53- let extension = path. extension ( ) . and_then ( |e| e. to_str ( ) ) ;
54- match extension {
55- Some ( ext) => match ext {
56- "iast" | "ast" | "cmi" | "cmt" => Some ( (
57- path. to_owned ( ) ,
58- entry. metadata ( ) . unwrap ( ) . modified ( ) . unwrap ( ) ,
59- ext. to_owned ( ) ,
60- package. name . to_owned ( ) ,
61- package. path . to_owned ( ) ,
62- package. config . is_multi_entry_enabled ( ) ,
63- package. namespace . to_owned ( ) ,
64- package. is_root ,
65- ) ) ,
66- _ => None ,
67- } ,
68- None => None ,
69- }
70- }
71- Err ( _) => None ,
72- } )
73- . collect :: < Vec < (
74- PathBuf ,
75- SystemTime ,
76- String ,
77- String ,
78- PathBuf ,
79- bool ,
80- packages:: Namespace ,
81- bool ,
82- ) > > ( )
59+ let mut package_assets = Vec :: new ( ) ;
60+ collect_compile_assets ( package, & package. get_ocaml_build_path ( ) , & mut package_assets) ;
61+ package_assets
8362 } )
8463 . flatten ( )
85- . collect :: < Vec < (
86- PathBuf ,
87- SystemTime ,
88- String ,
89- String ,
90- PathBuf ,
91- bool ,
92- packages:: Namespace ,
93- bool ,
94- ) > > ( ) ;
64+ . collect :: < Vec < CompileAsset > > ( ) ;
9565
9666 let root_config = build_state. get_root_config ( ) ;
9767
@@ -183,3 +153,40 @@ fn get_res_path_from_ast(ast_file: &Path) -> Option<PathBuf> {
183153 }
184154 None
185155}
156+
157+ fn collect_compile_assets ( package : & packages:: Package , dir : & Path , assets : & mut Vec < CompileAsset > ) {
158+ let Ok ( read_dir) = fs:: read_dir ( dir) else {
159+ return ;
160+ } ;
161+
162+ for entry in read_dir. flatten ( ) {
163+ let path = entry. path ( ) ;
164+ let Ok ( metadata) = entry. metadata ( ) else {
165+ continue ;
166+ } ;
167+
168+ if metadata. is_dir ( ) {
169+ collect_compile_assets ( package, & path, assets) ;
170+ continue ;
171+ }
172+
173+ let Some ( extension) = path. extension ( ) . and_then ( |extension| extension. to_str ( ) ) else {
174+ continue ;
175+ } ;
176+ let extension = extension. to_owned ( ) ;
177+
178+ match extension. as_str ( ) {
179+ "iast" | "ast" | "cmi" | "cmt" => assets. push ( (
180+ path,
181+ metadata. modified ( ) . unwrap ( ) ,
182+ extension,
183+ package. name . to_owned ( ) ,
184+ package. path . to_owned ( ) ,
185+ package. config . is_multi_entry_enabled ( ) ,
186+ package. namespace . to_owned ( ) ,
187+ package. is_root ,
188+ ) ) ,
189+ _ => { }
190+ }
191+ }
192+ }
0 commit comments