@@ -123,12 +123,23 @@ pub fn dynamic_lib_name(name: &str) -> String {
123
123
// ```
124
124
assert ! ( !name. contains( char :: is_whitespace) , "dynamic library name cannot contain whitespace" ) ;
125
125
126
+ let extension = dynamic_lib_extension ( ) ;
126
127
if is_darwin ( ) {
127
- format ! ( "lib{name}.dylib " )
128
+ format ! ( "lib{name}.{extension} " )
128
129
} else if is_windows ( ) {
129
- format ! ( "{name}.dll " )
130
+ format ! ( "{name}.{extension} " )
130
131
} else {
131
- format ! ( "lib{name}.so" )
132
+ format ! ( "lib{name}.{extension}" )
133
+ }
134
+ }
135
+
136
+ pub fn dynamic_lib_extension ( ) -> & ' static str {
137
+ if is_darwin ( ) {
138
+ "dylib"
139
+ } else if is_windows ( ) {
140
+ "dll"
141
+ } else {
142
+ "so"
132
143
}
133
144
}
134
145
@@ -249,16 +260,13 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
249
260
}
250
261
251
262
let dir2 = dir2. as_ref ( ) ;
252
- for entry in fs:: read_dir ( dir1) . unwrap ( ) {
253
- let entry = entry. unwrap ( ) ;
254
- let entry_name = entry. file_name ( ) ;
255
- let path = entry. path ( ) ;
256
-
257
- if path. is_dir ( ) {
258
- recursive_diff ( & path, & dir2. join ( entry_name) ) ;
263
+ read_dir ( dir1, |entry_path| {
264
+ let entry_name = entry_path. file_name ( ) . unwrap ( ) ;
265
+ if entry_path. is_dir ( ) {
266
+ recursive_diff ( & entry_path, & dir2. join ( entry_name) ) ;
259
267
} else {
260
268
let path2 = dir2. join ( entry_name) ;
261
- let file1 = read_file ( & path ) ;
269
+ let file1 = read_file ( & entry_path ) ;
262
270
let file2 = read_file ( & path2) ;
263
271
264
272
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
@@ -267,10 +275,16 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
267
275
assert ! (
268
276
file1 == file2,
269
277
"`{}` and `{}` have different content" ,
270
- path . display( ) ,
278
+ entry_path . display( ) ,
271
279
path2. display( ) ,
272
280
) ;
273
281
}
282
+ } ) ;
283
+ }
284
+
285
+ pub fn read_dir < F : Fn ( & Path ) > ( dir : impl AsRef < Path > , callback : F ) {
286
+ for entry in fs:: read_dir ( dir) . unwrap ( ) {
287
+ callback ( & entry. unwrap ( ) . path ( ) ) ;
274
288
}
275
289
}
276
290
0 commit comments