61
61
#[ cfg( feature = "parallel" ) ]
62
62
extern crate rayon;
63
63
64
+ use std:: collections:: HashMap ;
64
65
use std:: env;
65
66
use std:: ffi:: { OsStr , OsString } ;
66
67
use std:: fs;
68
+ use std:: io:: { self , BufRead , BufReader , Read , Write } ;
67
69
use std:: path:: { Path , PathBuf } ;
68
70
use std:: process:: { Child , Command , Stdio } ;
69
- use std:: io:: { self , BufRead , BufReader , Read , Write } ;
70
- use std:: thread:: { self , JoinHandle } ;
71
- use std:: collections:: HashMap ;
72
71
use std:: sync:: { Arc , Mutex } ;
72
+ use std:: thread:: { self , JoinHandle } ;
73
73
74
74
// These modules are all glue to support reading the MSVC version from
75
75
// the registry and from COM interfaces
@@ -891,7 +891,7 @@ impl Build {
891
891
return Err ( Error :: new (
892
892
ErrorKind :: IOError ,
893
893
"Getting object file details failed." ,
894
- ) )
894
+ ) ) ;
895
895
}
896
896
} ;
897
897
@@ -1119,12 +1119,18 @@ impl Build {
1119
1119
// CFLAGS/CXXFLAGS, since those variables presumably already contain
1120
1120
// the desired set of warnings flags.
1121
1121
1122
- if self . warnings . unwrap_or ( if self . has_flags ( ) { false } else { true } ) {
1122
+ if self
1123
+ . warnings
1124
+ . unwrap_or ( if self . has_flags ( ) { false } else { true } )
1125
+ {
1123
1126
let wflags = cmd. family . warnings_flags ( ) . into ( ) ;
1124
1127
cmd. push_cc_arg ( wflags) ;
1125
1128
}
1126
1129
1127
- if self . extra_warnings . unwrap_or ( if self . has_flags ( ) { false } else { true } ) {
1130
+ if self
1131
+ . extra_warnings
1132
+ . unwrap_or ( if self . has_flags ( ) { false } else { true } )
1133
+ {
1128
1134
if let Some ( wflags) = cmd. family . extra_warnings_flags ( ) {
1129
1135
cmd. push_cc_arg ( wflags. into ( ) ) ;
1130
1136
}
@@ -1161,7 +1167,12 @@ impl Build {
1161
1167
Ok ( cmd)
1162
1168
}
1163
1169
1164
- fn add_default_flags ( & self , cmd : & mut Tool , target : & str , opt_level : & str ) -> Result < ( ) , Error > {
1170
+ fn add_default_flags (
1171
+ & self ,
1172
+ cmd : & mut Tool ,
1173
+ target : & str ,
1174
+ opt_level : & str ,
1175
+ ) -> Result < ( ) , Error > {
1165
1176
// Non-target flags
1166
1177
// If the flag is not conditioned on target variable, it belongs here :)
1167
1178
match cmd. family {
@@ -1175,8 +1186,9 @@ impl Build {
1175
1186
Some ( true ) => "/MT" ,
1176
1187
Some ( false ) => "/MD" ,
1177
1188
None => {
1178
- let features =
1179
- self . getenv ( "CARGO_CFG_TARGET_FEATURE" ) . unwrap_or ( String :: new ( ) ) ;
1189
+ let features = self
1190
+ . getenv ( "CARGO_CFG_TARGET_FEATURE" )
1191
+ . unwrap_or ( String :: new ( ) ) ;
1180
1192
if features. contains ( "crt-static" ) {
1181
1193
"/MT"
1182
1194
} else {
@@ -1258,7 +1270,8 @@ impl Build {
1258
1270
// the SDK, but for all released versions of the
1259
1271
// Windows SDK it is required.
1260
1272
if target. contains ( "arm" ) || target. contains ( "thumb" ) {
1261
- cmd. args . push ( "/D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1" . into ( ) ) ;
1273
+ cmd. args
1274
+ . push ( "/D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1" . into ( ) ) ;
1262
1275
}
1263
1276
}
1264
1277
ToolFamily :: Gnu => {
@@ -1271,14 +1284,18 @@ impl Build {
1271
1284
}
1272
1285
1273
1286
if self . static_flag . is_none ( ) {
1274
- let features = self . getenv ( "CARGO_CFG_TARGET_FEATURE" ) . unwrap_or ( String :: new ( ) ) ;
1287
+ let features = self
1288
+ . getenv ( "CARGO_CFG_TARGET_FEATURE" )
1289
+ . unwrap_or ( String :: new ( ) ) ;
1275
1290
if features. contains ( "crt-static" ) {
1276
1291
cmd. args . push ( "-static" . into ( ) ) ;
1277
1292
}
1278
1293
}
1279
1294
1280
1295
// armv7 targets get to use armv7 instructions
1281
- if ( target. starts_with ( "armv7" ) || target. starts_with ( "thumbv7" ) ) && target. contains ( "-linux-" ) {
1296
+ if ( target. starts_with ( "armv7" ) || target. starts_with ( "thumbv7" ) )
1297
+ && target. contains ( "-linux-" )
1298
+ {
1282
1299
cmd. args . push ( "-march=armv7-a" . into ( ) ) ;
1283
1300
}
1284
1301
@@ -1443,7 +1460,11 @@ impl Build {
1443
1460
fn has_flags ( & self ) -> bool {
1444
1461
let flags_env_var_name = if self . cpp { "CXXFLAGS" } else { "CFLAGS" } ;
1445
1462
let flags_env_var_value = self . get_var ( flags_env_var_name) ;
1446
- if let Ok ( _) = flags_env_var_value { true } else { false }
1463
+ if let Ok ( _) = flags_env_var_value {
1464
+ true
1465
+ } else {
1466
+ false
1467
+ }
1447
1468
}
1448
1469
1449
1470
fn msvc_macro_assembler ( & self ) -> Result < ( Command , String ) , Error > {
@@ -1548,7 +1569,7 @@ impl Build {
1548
1569
return Err ( Error :: new (
1549
1570
ErrorKind :: IOError ,
1550
1571
"Could not copy or create a hard-link to the generated lib file." ,
1551
- ) )
1572
+ ) ) ;
1552
1573
}
1553
1574
} ;
1554
1575
} else {
@@ -1585,7 +1606,7 @@ impl Build {
1585
1606
return Err ( Error :: new (
1586
1607
ErrorKind :: ArchitectureInvalid ,
1587
1608
"Unknown architecture for iOS target." ,
1588
- ) )
1609
+ ) ) ;
1589
1610
}
1590
1611
} ;
1591
1612
@@ -1604,7 +1625,8 @@ impl Build {
1604
1625
} ;
1605
1626
1606
1627
self . print ( & format ! ( "Detecting iOS SDK path for {}" , sdk) ) ;
1607
- let sdk_path = self . cmd ( "xcrun" )
1628
+ let sdk_path = self
1629
+ . cmd ( "xcrun" )
1608
1630
. arg ( "--show-sdk-path" )
1609
1631
. arg ( "--sdk" )
1610
1632
. arg ( sdk)
@@ -1618,7 +1640,7 @@ impl Build {
1618
1640
return Err ( Error :: new (
1619
1641
ErrorKind :: IOError ,
1620
1642
"Unable to determine iOS SDK path." ,
1621
- ) )
1643
+ ) ) ;
1622
1644
}
1623
1645
} ;
1624
1646
@@ -1669,7 +1691,8 @@ impl Build {
1669
1691
1670
1692
let cl_exe = windows_registry:: find_tool ( & target, "cl.exe" ) ;
1671
1693
1672
- let tool_opt: Option < Tool > = self . env_tool ( env)
1694
+ let tool_opt: Option < Tool > = self
1695
+ . env_tool ( env)
1673
1696
. map ( |( tool, cc, args) | {
1674
1697
// chop off leading/trailing whitespace to work around
1675
1698
// semi-buggy build scripts which are shared in
@@ -1831,9 +1854,9 @@ impl Build {
1831
1854
// configure for invocations like `clang-cl` we still get a "works out
1832
1855
// of the box" experience.
1833
1856
if let Some ( cl_exe) = cl_exe {
1834
- if tool. family == ( ToolFamily :: Msvc { clang_cl : true } ) &&
1835
- tool. env . len ( ) == 0 &&
1836
- target. contains ( "msvc" )
1857
+ if tool. family == ( ToolFamily :: Msvc { clang_cl : true } )
1858
+ && tool. env . len ( ) == 0
1859
+ && target. contains ( "msvc" )
1837
1860
{
1838
1861
for & ( ref k, ref v) in cl_exe. env . iter ( ) {
1839
1862
tool. env . push ( ( k. to_owned ( ) , v. to_owned ( ) ) ) ;
@@ -1849,7 +1872,8 @@ impl Build {
1849
1872
let host = self . get_host ( ) ?;
1850
1873
let kind = if host == target { "HOST" } else { "TARGET" } ;
1851
1874
let target_u = target. replace ( "-" , "_" ) ;
1852
- let res = self . getenv ( & format ! ( "{}_{}" , var_base, target) )
1875
+ let res = self
1876
+ . getenv ( & format ! ( "{}_{}" , var_base, target) )
1853
1877
. or_else ( || self . getenv ( & format ! ( "{}_{}" , var_base, target_u) ) )
1854
1878
. or_else ( || self . getenv ( & format ! ( "{}_{}" , kind, var_base) ) )
1855
1879
. or_else ( || self . getenv ( var_base) ) ;
@@ -2040,7 +2064,7 @@ impl Build {
2040
2064
fn getenv ( & self , v : & str ) -> Option < String > {
2041
2065
let mut cache = self . env_cache . lock ( ) . unwrap ( ) ;
2042
2066
if let Some ( val) = cache. get ( v) {
2043
- return val. clone ( )
2067
+ return val. clone ( ) ;
2044
2068
}
2045
2069
let r = env:: var ( v) . ok ( ) ;
2046
2070
self . print ( & format ! ( "{} = {:?}" , v, r) ) ;
@@ -2081,10 +2105,11 @@ impl Tool {
2081
2105
let family = if let Some ( fname) = path. file_name ( ) . and_then ( |p| p. to_str ( ) ) {
2082
2106
if fname. contains ( "clang-cl" ) {
2083
2107
ToolFamily :: Msvc { clang_cl : true }
2084
- } else if fname. contains ( "cl" ) &&
2085
- !fname. contains ( "cloudabi" ) &&
2086
- !fname. contains ( "uclibc" ) &&
2087
- !fname. contains ( "clang" ) {
2108
+ } else if fname. contains ( "cl" )
2109
+ && !fname. contains ( "cloudabi" )
2110
+ && !fname. contains ( "uclibc" )
2111
+ && !fname. contains ( "clang" )
2112
+ {
2088
2113
ToolFamily :: Msvc { clang_cl : false }
2089
2114
} else if fname. contains ( "clang" ) {
2090
2115
ToolFamily :: Clang
@@ -2140,9 +2165,10 @@ impl Tool {
2140
2165
2141
2166
// Check for existing optimization flags (-O, /O)
2142
2167
if chars. next ( ) == Some ( 'O' ) {
2143
- return self . args ( ) . iter ( ) . any ( |ref a|
2144
- a. to_str ( ) . unwrap_or ( "" ) . chars ( ) . nth ( 1 ) == Some ( 'O' )
2145
- ) ;
2168
+ return self
2169
+ . args ( )
2170
+ . iter ( )
2171
+ . any ( |ref a| a. to_str ( ) . unwrap_or ( "" ) . chars ( ) . nth ( 1 ) == Some ( 'O' ) ) ;
2146
2172
}
2147
2173
2148
2174
// TODO Check for existing -m..., -m...=..., /arch:... flags
@@ -2174,7 +2200,11 @@ impl Tool {
2174
2200
} ;
2175
2201
cmd. args ( & self . cc_wrapper_args ) ;
2176
2202
2177
- let value = self . args . iter ( ) . filter ( |a| !self . removed_args . contains ( a) ) . collect :: < Vec < _ > > ( ) ;
2203
+ let value = self
2204
+ . args
2205
+ . iter ( )
2206
+ . filter ( |a| !self . removed_args . contains ( a) )
2207
+ . collect :: < Vec < _ > > ( ) ;
2178
2208
cmd. args ( & value) ;
2179
2209
2180
2210
for & ( ref k, ref v) in self . env . iter ( ) {
@@ -2269,7 +2299,7 @@ fn run(cmd: &mut Command, program: &str) -> Result<(), Error> {
2269
2299
"Failed to wait on spawned child process, command {:?} with args {:?}." ,
2270
2300
cmd, program
2271
2301
) ,
2272
- ) )
2302
+ ) ) ;
2273
2303
}
2274
2304
} ;
2275
2305
print. join ( ) . unwrap ( ) ;
@@ -2307,7 +2337,7 @@ fn run_output(cmd: &mut Command, program: &str) -> Result<Vec<u8>, Error> {
2307
2337
"Failed to wait on spawned child process, command {:?} with args {:?}." ,
2308
2338
cmd, program
2309
2339
) ,
2310
- ) )
2340
+ ) ) ;
2311
2341
}
2312
2342
} ;
2313
2343
print. join ( ) . unwrap ( ) ;
0 commit comments