@@ -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 {
@@ -80,6 +75,28 @@ pub fn source_path() -> PathBuf {
8075 std:: env:: var ( "S" ) . expect ( "S variable does not exist" ) . into ( )
8176}
8277
78+ /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
79+ #[ cfg( target_family = "windows" ) ]
80+ pub fn create_symlink < P : AsRef < Path > , Q : AsRef < Path > > ( original : P , link : Q ) {
81+ use std:: os:: windows:: fs;
82+ fs:: symlink_file ( original. as_ref ( ) , link. as_ref ( ) ) . expect ( & format ! (
83+ "failed to create symlink {:?} for {:?}" ,
84+ link. as_ref( ) . display( ) ,
85+ original. as_ref( ) . display( ) ,
86+ ) ) ;
87+ }
88+
89+ /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
90+ #[ cfg( target_family = "unix" ) ]
91+ pub fn create_symlink < P : AsRef < Path > , Q : AsRef < Path > > ( original : P , link : Q ) {
92+ use std:: os:: unix:: fs;
93+ fs:: symlink ( original. as_ref ( ) , link. as_ref ( ) ) . expect ( & format ! (
94+ "failed to create symlink {:?} for {:?}" ,
95+ link. as_ref( ) . display( ) ,
96+ original. as_ref( ) . display( ) ,
97+ ) ) ;
98+ }
99+
83100/// Construct the static library name based on the platform.
84101pub fn static_lib_name ( name : & str ) -> String {
85102 // See tools.mk (irrelevant lines omitted):
@@ -107,7 +124,7 @@ pub fn static_lib_name(name: &str) -> String {
107124/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
108125/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
109126pub fn dynamic_lib ( name : & str ) -> PathBuf {
110- tmp_path ( dynamic_lib_name ( name) )
127+ tmp_dir ( ) . join ( dynamic_lib_name ( name) )
111128}
112129
113130/// Construct the dynamic library name based on the platform.
@@ -139,7 +156,7 @@ pub fn dynamic_lib_name(name: &str) -> String {
139156/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
140157/// path with `$TMPDIR` joined with the library name.
141158pub fn rust_lib ( name : & str ) -> PathBuf {
142- tmp_path ( format ! ( "lib{name}.rlib" ) )
159+ tmp_dir ( ) . join ( format ! ( "lib{name}.rlib" ) )
143160}
144161
145162/// Construct the binary name based on platform.
@@ -212,15 +229,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
212229 fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
213230 let dst = dst. as_ref ( ) ;
214231 if !dst. is_dir ( ) {
215- fs:: create_dir_all ( & dst) ?;
232+ std :: fs:: create_dir_all ( & dst) ?;
216233 }
217- for entry in fs:: read_dir ( src) ? {
234+ for entry in std :: fs:: read_dir ( src) ? {
218235 let entry = entry?;
219236 let ty = entry. file_type ( ) ?;
220237 if ty. is_dir ( ) {
221238 copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
222239 } else {
223- fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
240+ std :: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
224241 }
225242 }
226243 Ok ( ( ) )
@@ -239,15 +256,8 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
239256
240257/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
241258pub 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-
249259 let dir2 = dir2. as_ref ( ) ;
250- for entry in fs:: read_dir ( dir1) . unwrap ( ) {
260+ for entry in fs:: read_dir ( dir1) {
251261 let entry = entry. unwrap ( ) ;
252262 let entry_name = entry. file_name ( ) ;
253263 let path = entry. path ( ) ;
@@ -256,8 +266,8 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
256266 recursive_diff ( & path, & dir2. join ( entry_name) ) ;
257267 } else {
258268 let path2 = dir2. join ( entry_name) ;
259- let file1 = read_file ( & path) ;
260- let file2 = read_file ( & path2) ;
269+ let file1 = fs :: read ( & path) ;
270+ let file2 = fs :: read ( & path2) ;
261271
262272 // We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
263273 // Why not using String? Because there might be minified files or even potentially
@@ -272,17 +282,6 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
272282 }
273283}
274284
275- /// Check that `haystack` does not contain `needle`. Panic otherwise.
276- pub fn assert_not_contains ( haystack : & str , needle : & str ) {
277- if haystack. contains ( needle) {
278- eprintln ! ( "=== HAYSTACK ===" ) ;
279- eprintln ! ( "{}" , haystack) ;
280- eprintln ! ( "=== NEEDLE ===" ) ;
281- eprintln ! ( "{}" , needle) ;
282- panic ! ( "needle was unexpectedly found in haystack" ) ;
283- }
284- }
285-
286285/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
287286/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
288287///
@@ -366,7 +365,7 @@ macro_rules! impl_common_helpers {
366365 self
367366 }
368367
369- /// Inspect what the underlying [`Command`] is up to the
368+ /// Inspect what the underlying [`Command`][::std::process::Command] is up to the
370369 /// current construction.
371370 pub fn inspect<I >( & mut self , inspector: I ) -> & mut Self
372371 where
0 commit comments