@@ -12,7 +12,6 @@ pub mod rustc;
12
12
pub mod rustdoc;
13
13
14
14
use std:: env;
15
- use std:: fs;
16
15
use std:: io;
17
16
use std:: path:: { Path , PathBuf } ;
18
17
use std:: process:: { Command , Output } ;
@@ -35,10 +34,6 @@ pub fn tmp_dir() -> PathBuf {
35
34
env:: var_os ( "TMPDIR" ) . unwrap ( ) . into ( )
36
35
}
37
36
38
- pub fn tmp_path < P : AsRef < Path > > ( path : P ) -> PathBuf {
39
- tmp_dir ( ) . join ( path. as_ref ( ) )
40
- }
41
-
42
37
/// `TARGET`
43
38
pub fn target ( ) -> String {
44
39
env:: var ( "TARGET" ) . unwrap ( )
@@ -62,7 +57,7 @@ pub fn is_darwin() -> bool {
62
57
/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
63
58
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
64
59
pub fn static_lib ( name : & str ) -> PathBuf {
65
- tmp_path ( static_lib_name ( name) )
60
+ tmp_dir ( ) . join ( static_lib_name ( name) )
66
61
}
67
62
68
63
pub fn python_command ( ) -> Command {
@@ -107,7 +102,7 @@ pub fn static_lib_name(name: &str) -> String {
107
102
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
108
103
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
109
104
pub fn dynamic_lib ( name : & str ) -> PathBuf {
110
- tmp_path ( dynamic_lib_name ( name) )
105
+ tmp_dir ( ) . join ( dynamic_lib_name ( name) )
111
106
}
112
107
113
108
/// Construct the dynamic library name based on the platform.
@@ -139,7 +134,13 @@ pub fn dynamic_lib_name(name: &str) -> String {
139
134
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
140
135
/// path with `$TMPDIR` joined with the library name.
141
136
pub fn rust_lib ( name : & str ) -> PathBuf {
142
- tmp_path ( format ! ( "lib{name}.rlib" ) )
137
+ tmp_path ( rust_lib_name ( name) )
138
+ }
139
+
140
+ /// Generate the name a rust library (rlib) would have. If you want the complete path, use
141
+ /// [`rust_lib`] instead.
142
+ pub fn rust_lib_name ( name : & str ) -> String {
143
+ format ! ( "lib{name}.rlib" )
143
144
}
144
145
145
146
/// Construct the binary name based on platform.
@@ -212,15 +213,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
212
213
fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
213
214
let dst = dst. as_ref ( ) ;
214
215
if !dst. is_dir ( ) {
215
- fs:: create_dir_all ( & dst) ?;
216
+ std :: fs:: create_dir_all ( & dst) ?;
216
217
}
217
- for entry in fs:: read_dir ( src) ? {
218
+ for entry in std :: fs:: read_dir ( src) ? {
218
219
let entry = entry?;
219
220
let ty = entry. file_type ( ) ?;
220
221
if ty. is_dir ( ) {
221
222
copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
222
223
} else {
223
- fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
224
+ std :: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
224
225
}
225
226
}
226
227
Ok ( ( ) )
@@ -239,15 +240,8 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
239
240
240
241
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
241
242
pub fn recursive_diff ( dir1 : impl AsRef < Path > , dir2 : impl AsRef < Path > ) {
242
- fn read_file ( path : & Path ) -> Vec < u8 > {
243
- match fs:: read ( path) {
244
- Ok ( c) => c,
245
- Err ( e) => panic ! ( "Failed to read `{}`: {:?}" , path. display( ) , e) ,
246
- }
247
- }
248
-
249
243
let dir2 = dir2. as_ref ( ) ;
250
- for entry in fs:: read_dir ( dir1) . unwrap ( ) {
244
+ for entry in fs:: read_dir ( dir1) {
251
245
let entry = entry. unwrap ( ) ;
252
246
let entry_name = entry. file_name ( ) ;
253
247
let path = entry. path ( ) ;
@@ -256,8 +250,8 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
256
250
recursive_diff ( & path, & dir2. join ( entry_name) ) ;
257
251
} else {
258
252
let path2 = dir2. join ( entry_name) ;
259
- let file1 = read_file ( & path) ;
260
- let file2 = read_file ( & path2) ;
253
+ let file1 = fs :: read ( & path) ;
254
+ let file2 = fs :: read ( & path2) ;
261
255
262
256
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
263
257
// Why not using String? Because there might be minified files or even potentially
0 commit comments