8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
-
12
11
use std:: fs:: File ;
13
12
use std:: path:: { Path , PathBuf } ;
14
13
use std:: process:: { Command , Stdio } ;
15
- use std:: { fs, env} ;
16
14
use std:: time:: { SystemTime , UNIX_EPOCH } ;
15
+ use std:: { env, fs} ;
17
16
18
17
/// A helper macro to `unwrap` a result except also print out details like:
19
18
///
@@ -25,10 +24,12 @@ use std::time::{SystemTime, UNIX_EPOCH};
25
24
/// using a `Result` with `try!`, but this may change one day...
26
25
#[ macro_export]
27
26
macro_rules! t {
28
- ( $e: expr) => ( match $e {
29
- Ok ( e) => e,
30
- Err ( e) => panic!( "{} failed with {}" , stringify!( $e) , e) ,
31
- } )
27
+ ( $e: expr) => {
28
+ match $e {
29
+ Ok ( e) => e,
30
+ Err ( e) => panic!( "{} failed with {}" , stringify!( $e) , e) ,
31
+ }
32
+ } ;
32
33
}
33
34
34
35
pub fn run ( cmd : & mut Command ) {
@@ -45,14 +46,17 @@ pub fn run_silent(cmd: &mut Command) {
45
46
pub fn try_run_silent ( cmd : & mut Command ) -> bool {
46
47
let status = match cmd. status ( ) {
47
48
Ok ( status) => status,
48
- Err ( e) => fail ( & format ! ( "failed to execute command: {:?}\n error: {}" ,
49
- cmd, e) ) ,
49
+ Err ( e) => fail ( & format ! (
50
+ "failed to execute command: {:?}\n error: {}" ,
51
+ cmd, e
52
+ ) ) ,
50
53
} ;
51
54
if !status. success ( ) {
52
- println ! ( "\n \n command did not execute successfully: {:?}\n \
53
- expected success, got: {}\n \n ",
54
- cmd,
55
- status) ;
55
+ println ! (
56
+ "\n \n command did not execute successfully: {:?}\n \
57
+ expected success, got: {}\n \n ",
58
+ cmd, status
59
+ ) ;
56
60
}
57
61
status. success ( )
58
62
}
@@ -66,18 +70,22 @@ pub fn run_suppressed(cmd: &mut Command) {
66
70
pub fn try_run_suppressed ( cmd : & mut Command ) -> bool {
67
71
let output = match cmd. output ( ) {
68
72
Ok ( status) => status,
69
- Err ( e) => fail ( & format ! ( "failed to execute command: {:?}\n error: {}" ,
70
- cmd, e) ) ,
73
+ Err ( e) => fail ( & format ! (
74
+ "failed to execute command: {:?}\n error: {}" ,
75
+ cmd, e
76
+ ) ) ,
71
77
} ;
72
78
if !output. status . success ( ) {
73
- println ! ( "\n \n command did not execute successfully: {:?}\n \
74
- expected success, got: {}\n \n \
75
- stdout ----\n {}\n \
76
- stderr ----\n {}\n \n ",
77
- cmd,
78
- output. status,
79
- String :: from_utf8_lossy( & output. stdout) ,
80
- String :: from_utf8_lossy( & output. stderr) ) ;
79
+ println ! (
80
+ "\n \n command did not execute successfully: {:?}\n \
81
+ expected success, got: {}\n \n \
82
+ stdout ----\n {}\n \
83
+ stderr ----\n {}\n \n ",
84
+ cmd,
85
+ output. status,
86
+ String :: from_utf8_lossy( & output. stdout) ,
87
+ String :: from_utf8_lossy( & output. stderr)
88
+ ) ;
81
89
}
82
90
output. status . success ( )
83
91
}
@@ -93,9 +101,9 @@ pub fn gnu_target(target: &str) -> String {
93
101
}
94
102
95
103
pub fn make ( host : & str ) -> PathBuf {
96
- if host. contains ( "bitrig" ) || host. contains ( "dragonfly" ) ||
97
- host. contains ( "freebsd " ) || host. contains ( "netbsd" ) ||
98
- host . contains ( "openbsd" ) {
104
+ if host. contains ( "bitrig" ) || host. contains ( "dragonfly" ) || host . contains ( "freebsd" )
105
+ || host. contains ( "netbsd " ) || host. contains ( "openbsd" )
106
+ {
99
107
PathBuf :: from ( "gmake" )
100
108
} else {
101
109
PathBuf :: from ( "make" )
@@ -105,23 +113,27 @@ pub fn make(host: &str) -> PathBuf {
105
113
pub fn output ( cmd : & mut Command ) -> String {
106
114
let output = match cmd. stderr ( Stdio :: inherit ( ) ) . output ( ) {
107
115
Ok ( status) => status,
108
- Err ( e) => fail ( & format ! ( "failed to execute command: {:?}\n error: {}" ,
109
- cmd, e) ) ,
116
+ Err ( e) => fail ( & format ! (
117
+ "failed to execute command: {:?}\n error: {}" ,
118
+ cmd, e
119
+ ) ) ,
110
120
} ;
111
121
if !output. status . success ( ) {
112
- panic ! ( "command did not execute successfully: {:?}\n \
113
- expected success, got: {}",
114
- cmd,
115
- output. status) ;
122
+ panic ! (
123
+ "command did not execute successfully: {:?}\n \
124
+ expected success, got: {}",
125
+ cmd, output. status
126
+ ) ;
116
127
}
117
128
String :: from_utf8 ( output. stdout ) . unwrap ( )
118
129
}
119
130
120
131
pub fn rerun_if_changed_anything_in_dir ( dir : & Path ) {
121
- let mut stack = dir. read_dir ( ) . unwrap ( )
122
- . map ( |e| e. unwrap ( ) )
123
- . filter ( |e| & * e. file_name ( ) != ".git" )
124
- . collect :: < Vec < _ > > ( ) ;
132
+ let mut stack = dir. read_dir ( )
133
+ . unwrap ( )
134
+ . map ( |e| e. unwrap ( ) )
135
+ . filter ( |e| & * e. file_name ( ) != ".git" )
136
+ . collect :: < Vec < _ > > ( ) ;
125
137
while let Some ( entry) = stack. pop ( ) {
126
138
let path = entry. path ( ) ;
127
139
if entry. file_type ( ) . unwrap ( ) . is_dir ( ) {
@@ -134,7 +146,9 @@ pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
134
146
135
147
/// Returns the last-modified time for `path`, or zero if it doesn't exist.
136
148
pub fn mtime ( path : & Path ) -> SystemTime {
137
- fs:: metadata ( path) . and_then ( |f| f. modified ( ) ) . unwrap_or ( UNIX_EPOCH )
149
+ fs:: metadata ( path)
150
+ . and_then ( |f| f. modified ( ) )
151
+ . unwrap_or ( UNIX_EPOCH )
138
152
}
139
153
140
154
/// Returns whether `dst` is up to date given that the file or files in `src`
@@ -175,11 +189,12 @@ impl Drop for NativeLibBoilerplate {
175
189
// If Err is returned, then everything is up-to-date and further build actions can be skipped.
176
190
// Timestamps are created automatically when the result of `native_lib_boilerplate` goes out
177
191
// of scope, so all the build actions should be completed until then.
178
- pub fn native_lib_boilerplate ( src_name : & str ,
179
- out_name : & str ,
180
- link_name : & str ,
181
- search_subdir : & str )
182
- -> Result < NativeLibBoilerplate , ( ) > {
192
+ pub fn native_lib_boilerplate (
193
+ src_name : & str ,
194
+ out_name : & str ,
195
+ link_name : & str ,
196
+ search_subdir : & str ,
197
+ ) -> Result < NativeLibBoilerplate , ( ) > {
183
198
let current_dir = PathBuf :: from ( env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
184
199
let src_dir = current_dir. join ( ".." ) . join ( src_name) ;
185
200
rerun_if_changed_anything_in_dir ( & src_dir) ;
@@ -192,11 +207,17 @@ pub fn native_lib_boilerplate(src_name: &str,
192
207
} else {
193
208
println ! ( "cargo:rustc-link-lib=static={}" , link_name) ;
194
209
}
195
- println ! ( "cargo:rustc-link-search=native={}" , out_dir. join( search_subdir) . display( ) ) ;
210
+ println ! (
211
+ "cargo:rustc-link-search=native={}" ,
212
+ out_dir. join( search_subdir) . display( )
213
+ ) ;
196
214
197
215
let timestamp = out_dir. join ( "rustbuild.timestamp" ) ;
198
216
if !up_to_date ( Path :: new ( "build.rs" ) , & timestamp) || !up_to_date ( & src_dir, & timestamp) {
199
- Ok ( NativeLibBoilerplate { src_dir : src_dir, out_dir : out_dir } )
217
+ Ok ( NativeLibBoilerplate {
218
+ src_dir : src_dir,
219
+ out_dir : out_dir,
220
+ } )
200
221
} else {
201
222
Err ( ( ) )
202
223
}
@@ -214,10 +235,12 @@ pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result<NativeLibBoiler
214
235
) ,
215
236
_ => return Err ( ( ) ) ,
216
237
} ;
217
- native_lib_boilerplate ( "libcompiler_builtins/compiler-rt" ,
218
- sanitizer_name,
219
- & link_name,
220
- search_path)
238
+ native_lib_boilerplate (
239
+ "libcompiler_builtins/compiler-rt" ,
240
+ sanitizer_name,
241
+ & link_name,
242
+ search_path,
243
+ )
221
244
}
222
245
223
246
fn dir_up_to_date ( src : & Path , threshold : SystemTime ) -> bool {
0 commit comments