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,12 +46,13 @@ 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
- pub fn tmp_path < P : AsRef < Path > > ( path : P ) -> PathBuf {
54
- tmp_dir ( ) . join ( path. as_ref ( ) )
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 ( ) )
55
56
}
56
57
57
58
/// `TARGET`
@@ -77,7 +78,7 @@ pub fn is_darwin() -> bool {
77
78
/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
78
79
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
79
80
pub fn static_lib ( name : & str ) -> PathBuf {
80
- tmp_path ( static_lib_name ( name) )
81
+ rmake_out_path ( static_lib_name ( name) )
81
82
}
82
83
83
84
pub fn python_command ( ) -> Command {
@@ -122,7 +123,7 @@ pub fn static_lib_name(name: &str) -> String {
122
123
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
123
124
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
124
125
pub fn dynamic_lib ( name : & str ) -> PathBuf {
125
- tmp_path ( dynamic_lib_name ( name) )
126
+ rmake_out_path ( dynamic_lib_name ( name) )
126
127
}
127
128
128
129
/// Construct the dynamic library name based on the platform.
@@ -165,7 +166,7 @@ pub fn dynamic_lib_extension() -> &'static str {
165
166
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
166
167
/// path with `$TMPDIR` joined with the library name.
167
168
pub fn rust_lib ( name : & str ) -> PathBuf {
168
- tmp_path ( rust_lib_name ( name) )
169
+ rmake_out_path ( rust_lib_name ( name) )
169
170
}
170
171
171
172
/// Generate the name a rust library (rlib) would have. If you want the complete path, use
@@ -244,15 +245,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
244
245
fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
245
246
let dst = dst. as_ref ( ) ;
246
247
if !dst. is_dir ( ) {
247
- fs:: create_dir_all ( & dst) ?;
248
+ std :: fs:: create_dir_all ( & dst) ?;
248
249
}
249
- for entry in fs:: read_dir ( src) ? {
250
+ for entry in std :: fs:: read_dir ( src) ? {
250
251
let entry = entry?;
251
252
let ty = entry. file_type ( ) ?;
252
253
if ty. is_dir ( ) {
253
254
copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
254
255
} else {
255
- fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
256
+ std :: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
256
257
}
257
258
}
258
259
Ok ( ( ) )
@@ -271,22 +272,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
271
272
272
273
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
273
274
pub fn recursive_diff ( dir1 : impl AsRef < Path > , dir2 : impl AsRef < Path > ) {
274
- fn read_file ( path : & Path ) -> Vec < u8 > {
275
- match fs:: read ( path) {
276
- Ok ( c) => c,
277
- Err ( e) => panic ! ( "Failed to read `{}`: {:?}" , path. display( ) , e) ,
278
- }
279
- }
280
-
281
275
let dir2 = dir2. as_ref ( ) ;
282
276
read_dir ( dir1, |entry_path| {
283
277
let entry_name = entry_path. file_name ( ) . unwrap ( ) ;
284
278
if entry_path. is_dir ( ) {
285
279
recursive_diff ( & entry_path, & dir2. join ( entry_name) ) ;
286
280
} else {
287
281
let path2 = dir2. join ( entry_name) ;
288
- let file1 = read_file ( & entry_path) ;
289
- let file2 = read_file ( & path2) ;
282
+ let file1 = fs_wrapper :: read ( & entry_path) ;
283
+ let file2 = fs_wrapper :: read ( & path2) ;
290
284
291
285
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
292
286
// Why not using String? Because there might be minified files or even potentially
@@ -302,7 +296,7 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
302
296
}
303
297
304
298
pub fn read_dir < F : Fn ( & Path ) > ( dir : impl AsRef < Path > , callback : F ) {
305
- for entry in fs :: read_dir ( dir) . unwrap ( ) {
299
+ for entry in fs_wrapper :: read_dir ( dir) {
306
300
callback ( & entry. unwrap ( ) . path ( ) ) ;
307
301
}
308
302
}
0 commit comments