@@ -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 {
@@ -80,6 +75,28 @@ pub fn source_path() -> PathBuf {
80
75
std:: env:: var ( "S" ) . expect ( "S variable does not exist" ) . into ( )
81
76
}
82
77
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
+
83
100
/// Construct the static library name based on the platform.
84
101
pub fn static_lib_name ( name : & str ) -> String {
85
102
// See tools.mk (irrelevant lines omitted):
@@ -107,7 +124,7 @@ pub fn static_lib_name(name: &str) -> String {
107
124
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
108
125
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
109
126
pub fn dynamic_lib ( name : & str ) -> PathBuf {
110
- tmp_path ( dynamic_lib_name ( name) )
127
+ tmp_dir ( ) . join ( dynamic_lib_name ( name) )
111
128
}
112
129
113
130
/// Construct the dynamic library name based on the platform.
@@ -139,7 +156,7 @@ pub fn dynamic_lib_name(name: &str) -> String {
139
156
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
140
157
/// path with `$TMPDIR` joined with the library name.
141
158
pub fn rust_lib ( name : & str ) -> PathBuf {
142
- tmp_path ( format ! ( "lib{name}.rlib" ) )
159
+ tmp_dir ( ) . join ( format ! ( "lib{name}.rlib" ) )
143
160
}
144
161
145
162
/// Construct the binary name based on platform.
@@ -212,15 +229,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
212
229
fn copy_dir_all_inner ( src : impl AsRef < Path > , dst : impl AsRef < Path > ) -> io:: Result < ( ) > {
213
230
let dst = dst. as_ref ( ) ;
214
231
if !dst. is_dir ( ) {
215
- fs:: create_dir_all ( & dst) ?;
232
+ std :: fs:: create_dir_all ( & dst) ?;
216
233
}
217
- for entry in fs:: read_dir ( src) ? {
234
+ for entry in std :: fs:: read_dir ( src) ? {
218
235
let entry = entry?;
219
236
let ty = entry. file_type ( ) ?;
220
237
if ty. is_dir ( ) {
221
238
copy_dir_all_inner ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
222
239
} else {
223
- fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
240
+ std :: fs:: copy ( entry. path ( ) , dst. join ( entry. file_name ( ) ) ) ?;
224
241
}
225
242
}
226
243
Ok ( ( ) )
@@ -239,15 +256,8 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
239
256
240
257
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
241
258
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
259
let dir2 = dir2. as_ref ( ) ;
250
- for entry in fs:: read_dir ( dir1) . unwrap ( ) {
260
+ for entry in fs:: read_dir ( dir1) {
251
261
let entry = entry. unwrap ( ) ;
252
262
let entry_name = entry. file_name ( ) ;
253
263
let path = entry. path ( ) ;
@@ -256,8 +266,8 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
256
266
recursive_diff ( & path, & dir2. join ( entry_name) ) ;
257
267
} else {
258
268
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) ;
261
271
262
272
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
263
273
// 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>) {
272
282
}
273
283
}
274
284
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
-
286
285
/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
287
286
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
288
287
///
@@ -366,7 +365,7 @@ macro_rules! impl_common_helpers {
366
365
self
367
366
}
368
367
369
- /// Inspect what the underlying [`Command`] is up to the
368
+ /// Inspect what the underlying [`Command`][::std::process::Command] is up to the
370
369
/// current construction.
371
370
pub fn inspect<I >( & mut self , inspector: I ) -> & mut Self
372
371
where
0 commit comments