88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11-
1211use std:: fs:: File ;
1312use std:: path:: { Path , PathBuf } ;
1413use std:: process:: { Command , Stdio } ;
15- use std:: { fs, env} ;
1614use std:: time:: { SystemTime , UNIX_EPOCH } ;
15+ use std:: { env, fs} ;
1716
1817/// A helper macro to `unwrap` a result except also print out details like:
1918///
@@ -25,10 +24,12 @@ use std::time::{SystemTime, UNIX_EPOCH};
2524/// using a `Result` with `try!`, but this may change one day...
2625#[ macro_export]
2726macro_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+ } ;
3233}
3334
3435pub fn run ( cmd : & mut Command ) {
@@ -45,14 +46,17 @@ pub fn run_silent(cmd: &mut Command) {
4546pub fn try_run_silent ( cmd : & mut Command ) -> bool {
4647 let status = match cmd. status ( ) {
4748 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+ ) ) ,
5053 } ;
5154 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+ ) ;
5660 }
5761 status. success ( )
5862}
@@ -66,18 +70,22 @@ pub fn run_suppressed(cmd: &mut Command) {
6670pub fn try_run_suppressed ( cmd : & mut Command ) -> bool {
6771 let output = match cmd. output ( ) {
6872 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+ ) ) ,
7177 } ;
7278 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+ ) ;
8189 }
8290 output. status . success ( )
8391}
@@ -93,9 +101,9 @@ pub fn gnu_target(target: &str) -> String {
93101}
94102
95103pub 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+ {
99107 PathBuf :: from ( "gmake" )
100108 } else {
101109 PathBuf :: from ( "make" )
@@ -105,23 +113,27 @@ pub fn make(host: &str) -> PathBuf {
105113pub fn output ( cmd : & mut Command ) -> String {
106114 let output = match cmd. stderr ( Stdio :: inherit ( ) ) . output ( ) {
107115 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+ ) ) ,
110120 } ;
111121 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+ ) ;
116127 }
117128 String :: from_utf8 ( output. stdout ) . unwrap ( )
118129}
119130
120131pub 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 < _ > > ( ) ;
125137 while let Some ( entry) = stack. pop ( ) {
126138 let path = entry. path ( ) ;
127139 if entry. file_type ( ) . unwrap ( ) . is_dir ( ) {
@@ -134,7 +146,9 @@ pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
134146
135147/// Returns the last-modified time for `path`, or zero if it doesn't exist.
136148pub 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 )
138152}
139153
140154/// Returns whether `dst` is up to date given that the file or files in `src`
@@ -175,11 +189,12 @@ impl Drop for NativeLibBoilerplate {
175189// If Err is returned, then everything is up-to-date and further build actions can be skipped.
176190// Timestamps are created automatically when the result of `native_lib_boilerplate` goes out
177191// 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 , ( ) > {
183198 let current_dir = PathBuf :: from ( env:: var ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ) ;
184199 let src_dir = current_dir. join ( ".." ) . join ( src_name) ;
185200 rerun_if_changed_anything_in_dir ( & src_dir) ;
@@ -192,11 +207,17 @@ pub fn native_lib_boilerplate(src_name: &str,
192207 } else {
193208 println ! ( "cargo:rustc-link-lib=static={}" , link_name) ;
194209 }
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+ ) ;
196214
197215 let timestamp = out_dir. join ( "rustbuild.timestamp" ) ;
198216 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+ } )
200221 } else {
201222 Err ( ( ) )
202223 }
@@ -214,10 +235,12 @@ pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result<NativeLibBoiler
214235 ) ,
215236 _ => return Err ( ( ) ) ,
216237 } ;
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+ )
221244}
222245
223246fn dir_up_to_date ( src : & Path , threshold : SystemTime ) -> bool {
0 commit comments