1- use std:: collections:: HashMap ;
2-
31use anyhow:: * ;
2+ use std:: collections:: HashMap ;
3+ use std:: path:: PathBuf ;
44use tracing:: { trace, trace_span} ;
55
66use crate :: native:: glob:: build_glob_set;
77use crate :: native:: types:: FileData ;
8+ use crate :: native:: utils:: path:: get_relative_path;
89
910pub fn hash_project_files (
11+ workspace_root : & String ,
1012 project_name : & str ,
1113 project_root : & str ,
1214 file_sets : & [ String ] ,
1315 project_file_map : & HashMap < String , Vec < FileData > > ,
1416) -> Result < String > {
1517 let _span = trace_span ! ( "hash_project_files" , project_name) . entered ( ) ;
16- let collected_files =
17- collect_project_files ( project_name, project_root, file_sets, project_file_map) ?;
18+ let collected_files = collect_project_files (
19+ workspace_root,
20+ project_name,
21+ project_root,
22+ file_sets,
23+ project_file_map,
24+ ) ?;
1825 trace ! ( "collected_files: {:?}" , collected_files. len( ) ) ;
1926 let mut hasher = xxhash_rust:: xxh3:: Xxh3 :: new ( ) ;
2027 for file in collected_files {
@@ -26,6 +33,7 @@ pub fn hash_project_files(
2633
2734/// base function that should be testable (to make sure that we're getting the proper files back)
2835pub fn collect_project_files < ' a > (
36+ workspace_root : & String ,
2937 project_name : & str ,
3038 project_root : & str ,
3139 file_sets : & [ String ] ,
@@ -52,7 +60,15 @@ pub fn collect_project_files<'a>(
5260 let now = std:: time:: Instant :: now ( ) ;
5361 let hashes = files
5462 . iter ( )
55- . filter ( |file| glob_set. is_match ( & file. file ) )
63+ . filter ( |file| {
64+ let path = if PathBuf :: from ( & file. file ) . is_absolute ( ) {
65+ & get_relative_path ( workspace_root, & file. file )
66+ } else {
67+ & file. file
68+ } ;
69+ trace ! ( "{} - {}" , path, file. hash) ;
70+ glob_set. is_match ( path)
71+ } )
5672 . collect :: < Vec < _ > > ( ) ;
5773 trace ! ( "hash_files for {}: {:?}" , project_name, now. elapsed( ) ) ;
5874 Ok ( hashes)
@@ -68,6 +84,7 @@ mod tests {
6884
6985 #[ test]
7086 fn test_collect_files ( ) {
87+ let workspace_root = String :: from ( "" ) ;
7188 let proj_name = "test_project" ;
7289 let proj_root = "test/root" ;
7390 let file_sets = & [
@@ -101,11 +118,14 @@ mod tests {
101118 ] ,
102119 ) ;
103120
104- let result = collect_project_files ( proj_name, proj_root, file_sets, & file_map) . unwrap ( ) ;
121+ let result =
122+ collect_project_files ( & workspace_root, proj_name, proj_root, file_sets, & file_map)
123+ . unwrap ( ) ;
105124
106125 assert_eq ! ( result, vec![ & tsfile_1, & tsfile_2] ) ;
107126
108127 let result = collect_project_files (
128+ & workspace_root,
109129 proj_name,
110130 proj_root,
111131 & [ "!{projectRoot}/**/*.spec.ts" . into ( ) ] ,
@@ -124,6 +144,7 @@ mod tests {
124144
125145 #[ test]
126146 fn should_hash_deterministically ( ) {
147+ let workspace_root = String :: from ( "" ) ;
127148 let proj_name = "test_project" ;
128149 let proj_root = "test/root" ;
129150 let file_sets = & [
@@ -156,7 +177,9 @@ mod tests {
156177 file_data4. clone( ) ,
157178 ] ,
158179 ) ;
159- let hash_result = hash_project_files ( proj_name, proj_root, file_sets, & file_map) . unwrap ( ) ;
180+ let hash_result =
181+ hash_project_files ( & workspace_root, proj_name, proj_root, file_sets, & file_map)
182+ . unwrap ( ) ;
160183 assert_eq ! (
161184 hash_result,
162185 hash(
@@ -173,6 +196,7 @@ mod tests {
173196
174197 #[ test]
175198 fn should_hash_projects_with_root_as_dot ( ) {
199+ let workspace_root = String :: from ( "" ) ;
176200 let proj_name = "test_project" ;
177201 // having "." as the project root means that this would be a standalone project
178202 let proj_root = "." ;
@@ -206,7 +230,9 @@ mod tests {
206230 file_data4. clone( ) ,
207231 ] ,
208232 ) ;
209- let hash_result = hash_project_files ( proj_name, proj_root, file_sets, & file_map) . unwrap ( ) ;
233+ let hash_result =
234+ hash_project_files ( & workspace_root, proj_name, proj_root, file_sets, & file_map)
235+ . unwrap ( ) ;
210236 assert_eq ! (
211237 hash_result,
212238 hash(
0 commit comments