@@ -135,11 +135,16 @@ impl Remapping {
135
135
/// are unified into `@aave` by looking at their common ancestor, the root of this subdirectory
136
136
/// (`@aave`)
137
137
pub fn find_many ( root : impl AsRef < Path > ) -> Vec < Remapping > {
138
- /// prioritize ("a", "1/2") over ("a", "1/2/3")
139
- fn insert_higher_path ( mappings : & mut HashMap < String , PathBuf > , key : String , path : PathBuf ) {
138
+ /// prioritize ("a", "1/2") over ("a", "1/2/3") or if `force` set
139
+ fn insert_higher_path (
140
+ mappings : & mut HashMap < String , PathBuf > ,
141
+ key : String ,
142
+ path : PathBuf ,
143
+ force : bool ,
144
+ ) {
140
145
match mappings. entry ( key) {
141
146
Entry :: Occupied ( mut e) => {
142
- if e. get ( ) . components ( ) . count ( ) > path. components ( ) . count ( ) {
147
+ if force || e. get ( ) . components ( ) . count ( ) > path. components ( ) . count ( ) {
143
148
e. insert ( path) ;
144
149
}
145
150
}
@@ -181,7 +186,27 @@ impl Remapping {
181
186
' outer: for ( name, path) in scan_children ( dir_path) {
182
187
let mut p = path. as_path ( ) ;
183
188
let mut first_parent = true ;
189
+
190
+ // check for dapptools style mappings like `ds-test/` : `lib/ds-test/src`
191
+ if path. ends_with ( DAPPTOOLS_CONTRACTS_DIR ) || path. ends_with ( DAPPTOOLS_LIB_DIR )
192
+ {
193
+ insert_higher_path ( & mut remappings, name, path, true ) ;
194
+ continue
195
+ }
196
+
197
+ // traverse the path back to the current depth 1 root and check if it can be
198
+ // simplified
184
199
while let Some ( parent) = p. parent ( ) {
200
+ // check for dapptools style mappings like `ds-test/` : `lib/ds-test/src`
201
+ if parent. ends_with ( DAPPTOOLS_CONTRACTS_DIR ) ||
202
+ parent. ends_with ( DAPPTOOLS_LIB_DIR )
203
+ {
204
+ // end early since we reached the higher up dapptools style barrier:
205
+ // `name: demo`, `path: guni-lev/lib/ds-test/demo` and `parent:
206
+ // guni-lev/lib/`
207
+ insert_higher_path ( & mut remappings, name, path, false ) ;
208
+ continue ' outer
209
+ }
185
210
if parent == dir_path {
186
211
if !simplified {
187
212
// handle trailing src,lib,contracts dir in cases like
@@ -191,18 +216,12 @@ impl Remapping {
191
216
& mut remappings,
192
217
format ! ( "{}/" , root_name) ,
193
218
path,
219
+ false ,
194
220
) ;
195
221
simplified = true ;
196
222
}
197
223
continue ' outer
198
224
}
199
- if parent. ends_with ( DAPPTOOLS_CONTRACTS_DIR ) ||
200
- parent. ends_with ( DAPPTOOLS_LIB_DIR )
201
- {
202
- // end early
203
- insert_higher_path ( & mut remappings, name, path) ;
204
- continue ' outer
205
- }
206
225
first_parent = false ;
207
226
p = parent;
208
227
}
@@ -261,7 +280,6 @@ fn scan_children(root: &Path) -> HashMap<String, PathBuf> {
261
280
}
262
281
}
263
282
}
264
-
265
283
remappings
266
284
}
267
285
@@ -336,6 +354,10 @@ mod tests {
336
354
"repo1/lib/ds-math/src/contract.sol" ,
337
355
"repo1/lib/ds-math/lib/ds-test/src/" ,
338
356
"repo1/lib/ds-math/lib/ds-test/src/test.sol" ,
357
+ "guni-lev/lib/ds-test/src/" ,
358
+ "guni-lev/lib/ds-test/src/test.sol" ,
359
+ "guni-lev/lib/ds-test/demo/" ,
360
+ "guni-lev/lib/ds-test/demo/demo.sol" ,
339
361
] ;
340
362
mkdir_or_touch ( tmp_dir_path, & paths[ ..] ) ;
341
363
@@ -354,14 +376,12 @@ mod tests {
354
376
} ,
355
377
Remapping {
356
378
name: "ds-test/" . to_string( ) ,
379
+ path: to_str( tmp_dir_path. join( "guni-lev" ) . join( "lib" ) . join( "ds-test" ) . join( "src" ) ) ,
380
+ } ,
381
+ Remapping {
382
+ name: "demo/" . to_string( ) ,
357
383
path: to_str(
358
- tmp_dir_path
359
- . join( "repo1" )
360
- . join( "lib" )
361
- . join( "ds-math" )
362
- . join( "lib" )
363
- . join( "ds-test" )
364
- . join( "src" ) ,
384
+ tmp_dir_path. join( "guni-lev" ) . join( "lib" ) . join( "ds-test" ) . join( "demo" ) ,
365
385
) ,
366
386
} ,
367
387
] ;
@@ -432,7 +452,6 @@ mod tests {
432
452
} ,
433
453
] ;
434
454
expected. sort_unstable ( ) ;
435
-
436
455
assert_eq ! ( remappings, expected) ;
437
456
}
438
457
}
0 commit comments