@@ -12,7 +12,6 @@ pub mod rustc;
1212pub mod rustdoc;
1313
1414use std:: env;
15- use std:: fs;
1615use std:: io;
1716use std:: path:: { Path , PathBuf } ;
1817use std:: process:: { Command , Output } ;
@@ -35,10 +34,6 @@ pub fn tmp_dir() -> PathBuf {
3534 env:: var_os ( "TMPDIR" ) . unwrap ( ) . into ( )
3635}
3736
38- pub fn tmp_path < P : AsRef < Path > > ( path : P ) -> PathBuf {
39- tmp_dir ( ) . join ( path. as_ref ( ) )
40- }
41-
4237/// `TARGET`
4338pub fn target ( ) -> String {
4439 env:: var ( "TARGET" ) . unwrap ( )
@@ -62,7 +57,7 @@ pub fn is_darwin() -> bool {
6257/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
6358/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
6459pub fn static_lib ( name : & str ) -> PathBuf {
65- tmp_path ( static_lib_name ( name) )
60+ tmp_dir ( ) . join ( static_lib_name ( name) )
6661}
6762
6863pub fn python_command ( ) -> Command {
@@ -107,7 +102,7 @@ pub fn static_lib_name(name: &str) -> String {
107102/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
108103/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
109104pub fn dynamic_lib ( name : & str ) -> PathBuf {
110- tmp_path ( dynamic_lib_name ( name) )
105+ tmp_dir ( ) . join ( dynamic_lib_name ( name) )
111106}
112107
113108/// Construct the dynamic library name based on the platform.
@@ -139,7 +134,13 @@ pub fn dynamic_lib_name(name: &str) -> String {
139134/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
140135/// path with `$TMPDIR` joined with the library name.
141136pub 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" )
143144}
144145
145146/// Construct the binary name based on platform.
@@ -212,15 +213,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
212213 fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
213214 let dst = dst. as_ref ( ) ;
214215 if !dst. is_dir ( ) {
215- fs:: create_dir_all ( & dst) ?;
216+ std :: fs:: create_dir_all ( & dst) ?;
216217 }
217- for entry in fs:: read_dir ( src) ? {
218+ for entry in std :: fs:: read_dir ( src) ? {
218219 let entry = entry?;
219220 let ty = entry. file_type ( ) ?;
220221 if ty. is_dir ( ) {
221222 copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
222223 } else {
223- fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
224+ std :: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
224225 }
225226 }
226227 Ok ( ( ) )
@@ -239,15 +240,8 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
239240
240241/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
241242pub 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-
249243 let dir2 = dir2. as_ref ( ) ;
250- for entry in fs:: read_dir ( dir1) . unwrap ( ) {
244+ for entry in fs:: read_dir ( dir1) {
251245 let entry = entry. unwrap ( ) ;
252246 let entry_name = entry. file_name ( ) ;
253247 let path = entry. path ( ) ;
@@ -256,8 +250,8 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
256250 recursive_diff ( & path, & dir2. join ( entry_name) ) ;
257251 } else {
258252 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) ;
261255
262256 // We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
263257 // Why not using String? Because there might be minified files or even potentially
0 commit comments