6
6
pub mod cc;
7
7
pub mod clang;
8
8
pub mod diff;
9
+ pub mod fs_wrapper;
9
10
pub mod llvm_readobj;
10
11
pub mod run;
11
12
pub mod rustc;
12
13
pub mod rustdoc;
13
14
14
15
use std:: env;
15
16
use std:: ffi:: OsString ;
16
- use std:: fs;
17
17
use std:: io;
18
18
use std:: path:: { Path , PathBuf } ;
19
19
use std:: process:: { Command , Output } ;
@@ -46,10 +46,15 @@ pub fn env_var_os(name: &str) -> OsString {
46
46
}
47
47
48
48
/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`).
49
- pub fn tmp_dir ( ) -> PathBuf {
49
+ pub fn rmake_out_dir ( ) -> PathBuf {
50
50
env_var_os ( "TMPDIR" ) . into ( )
51
51
}
52
52
53
+ /// Returns the directory TMPDIR/name.
54
+ pub fn rmake_out_path < P : AsRef < Path > > ( name : P ) -> PathBuf {
55
+ rmake_out_dir ( ) . join ( name. as_ref ( ) )
56
+ }
57
+
53
58
/// `TARGET`
54
59
pub fn target ( ) -> String {
55
60
env_var ( "TARGET" )
@@ -73,7 +78,7 @@ pub fn is_darwin() -> bool {
73
78
/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
74
79
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
75
80
pub fn static_lib ( name : & str ) -> PathBuf {
76
- tmp_dir ( ) . join ( static_lib_name ( name) )
81
+ rmake_out_path ( static_lib_name ( name) )
77
82
}
78
83
79
84
pub fn python_command ( ) -> Command {
@@ -118,7 +123,7 @@ pub fn static_lib_name(name: &str) -> String {
118
123
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
119
124
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
120
125
pub fn dynamic_lib ( name : & str ) -> PathBuf {
121
- tmp_dir ( ) . join ( dynamic_lib_name ( name) )
126
+ rmake_out_path ( dynamic_lib_name ( name) )
122
127
}
123
128
124
129
/// Construct the dynamic library name based on the platform.
@@ -161,7 +166,7 @@ pub fn dynamic_lib_extension() -> &'static str {
161
166
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
162
167
/// path with `$TMPDIR` joined with the library name.
163
168
pub fn rust_lib ( name : & str ) -> PathBuf {
164
- tmp_dir ( ) . join ( rust_lib_name ( name) )
169
+ rmake_out_path ( rust_lib_name ( name) )
165
170
}
166
171
167
172
/// Generate the name a rust library (rlib) would have. If you want the complete path, use
@@ -240,15 +245,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
240
245
fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
241
246
let dst = dst. as_ref ( ) ;
242
247
if !dst. is_dir ( ) {
243
- fs:: create_dir_all ( & dst) ?;
248
+ std :: fs:: create_dir_all ( & dst) ?;
244
249
}
245
- for entry in fs:: read_dir ( src) ? {
250
+ for entry in std :: fs:: read_dir ( src) ? {
246
251
let entry = entry?;
247
252
let ty = entry. file_type ( ) ?;
248
253
if ty. is_dir ( ) {
249
254
copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
250
255
} else {
251
- fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
256
+ std :: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
252
257
}
253
258
}
254
259
Ok ( ( ) )
@@ -267,22 +272,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
267
272
268
273
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
269
274
pub fn recursive_diff ( dir1 : impl AsRef < Path > , dir2 : impl AsRef < Path > ) {
270
- fn read_file ( path : & Path ) -> Vec < u8 > {
271
- match fs:: read ( path) {
272
- Ok ( c) => c,
273
- Err ( e) => panic ! ( "Failed to read `{}`: {:?}" , path. display( ) , e) ,
274
- }
275
- }
276
-
277
275
let dir2 = dir2. as_ref ( ) ;
278
276
read_dir ( dir1, |entry_path| {
279
277
let entry_name = entry_path. file_name ( ) . unwrap ( ) ;
280
278
if entry_path. is_dir ( ) {
281
279
recursive_diff ( & entry_path, & dir2. join ( entry_name) ) ;
282
280
} else {
283
281
let path2 = dir2. join ( entry_name) ;
284
- let file1 = read_file ( & entry_path) ;
285
- let file2 = read_file ( & path2) ;
282
+ let file1 = fs_wrapper :: read ( & entry_path) ;
283
+ let file2 = fs_wrapper :: read ( & path2) ;
286
284
287
285
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
288
286
// Why not using String? Because there might be minified files or even potentially
@@ -298,7 +296,7 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
298
296
}
299
297
300
298
pub fn read_dir < F : Fn ( & Path ) > ( dir : impl AsRef < Path > , callback : F ) {
301
- for entry in fs :: read_dir ( dir) . unwrap ( ) {
299
+ for entry in fs_wrapper :: read_dir ( dir) {
302
300
callback ( & entry. unwrap ( ) . path ( ) ) ;
303
301
}
304
302
}
0 commit comments