@@ -50,43 +50,68 @@ fn main() {
50
50
let test = std:: env:: args ( ) . nth ( 2 ) . map_or ( false , |text| text == "test" ) ;
51
51
let skip = if test { 3 } else { 2 } ;
52
52
53
- let manifest_path_arg = std:: env:: args ( ) . skip ( skip) . find ( |val| val. starts_with ( "--manifest-path=" ) ) ;
54
-
55
- let mut metadata = if let Ok ( metadata) = cargo_metadata:: metadata ( manifest_path_arg. as_ref ( ) . map ( AsRef :: as_ref) ) {
53
+ let manifest_path_arg = std:: env:: args ( ) . skip ( skip) . find ( |val| {
54
+ val. starts_with ( "--manifest-path=" )
55
+ } ) ;
56
+
57
+ let mut metadata = if let Ok ( metadata) = cargo_metadata:: metadata (
58
+ manifest_path_arg. as_ref ( ) . map ( AsRef :: as_ref) ,
59
+ )
60
+ {
56
61
metadata
57
62
} else {
58
- let _ = std:: io:: stderr ( ) . write_fmt ( format_args ! ( "error: Could not obtain cargo metadata." ) ) ;
63
+ let _ = std:: io:: stderr ( ) . write_fmt ( format_args ! (
64
+ "error: Could not obtain cargo metadata."
65
+ ) ) ;
59
66
std:: process:: exit ( 101 ) ;
60
67
} ;
61
68
62
- let manifest_path = manifest_path_arg. map ( |arg| PathBuf :: from ( Path :: new ( & arg[ "--manifest-path=" . len ( ) ..] ) ) ) ;
69
+ let manifest_path = manifest_path_arg. map ( |arg| {
70
+ PathBuf :: from ( Path :: new ( & arg[ "--manifest-path=" . len ( ) ..] ) )
71
+ } ) ;
63
72
64
73
let current_dir = std:: env:: current_dir ( ) ;
65
74
66
- let package_index = metadata. packages
75
+ let package_index = metadata
76
+ . packages
67
77
. iter ( )
68
78
. position ( |package| {
69
79
let package_manifest_path = Path :: new ( & package. manifest_path ) ;
70
80
if let Some ( ref manifest_path) = manifest_path {
71
81
package_manifest_path == manifest_path
72
82
} else {
73
- let current_dir = current_dir. as_ref ( ) . expect ( "could not read current directory" ) ;
74
- let package_manifest_directory = package_manifest_path. parent ( )
75
- . expect ( "could not find parent directory of package manifest" ) ;
83
+ let current_dir = current_dir. as_ref ( ) . expect (
84
+ "could not read current directory" ,
85
+ ) ;
86
+ let package_manifest_directory = package_manifest_path. parent ( ) . expect (
87
+ "could not find parent directory of package manifest" ,
88
+ ) ;
76
89
package_manifest_directory == current_dir
77
90
}
78
91
} )
79
92
. expect ( "could not find matching package" ) ;
80
93
let package = metadata. packages . remove ( package_index) ;
81
94
for target in package. targets {
82
95
let args = std:: env:: args ( ) . skip ( skip) ;
83
- let kind = target. kind . get ( 0 ) . expect ( "badly formatted cargo metadata: target::kind is an empty array" ) ;
96
+ let kind = target. kind . get ( 0 ) . expect (
97
+ "badly formatted cargo metadata: target::kind is an empty array" ,
98
+ ) ;
84
99
if test && kind == "test" {
85
- if let Err ( code) = process ( vec ! [ "--test" . to_string( ) , target. name] . into_iter ( ) . chain ( args) ) {
100
+ if let Err ( code) = process (
101
+ vec ! [ "--test" . to_string( ) , target. name] . into_iter ( ) . chain (
102
+ args,
103
+ ) ,
104
+ )
105
+ {
86
106
std:: process:: exit ( code) ;
87
107
}
88
108
} else if !test && kind == "bin" {
89
- if let Err ( code) = process ( vec ! [ "--bin" . to_string( ) , target. name] . into_iter ( ) . chain ( args) ) {
109
+ if let Err ( code) = process (
110
+ vec ! [ "--bin" . to_string( ) , target. name] . into_iter ( ) . chain (
111
+ args,
112
+ ) ,
113
+ )
114
+ {
90
115
std:: process:: exit ( code) ;
91
116
}
92
117
}
@@ -118,7 +143,11 @@ fn main() {
118
143
let mut args: Vec < String > = if std:: env:: args ( ) . any ( |s| s == "--sysroot" ) {
119
144
std:: env:: args ( ) . skip ( 1 ) . collect ( )
120
145
} else {
121
- std:: env:: args ( ) . skip ( 1 ) . chain ( Some ( "--sysroot" . to_owned ( ) ) ) . chain ( Some ( sys_root) ) . collect ( )
146
+ std:: env:: args ( )
147
+ . skip ( 1 )
148
+ . chain ( Some ( "--sysroot" . to_owned ( ) ) )
149
+ . chain ( Some ( sys_root) )
150
+ . collect ( )
122
151
} ;
123
152
124
153
// this check ensures that dependencies are built but not interpreted and the final crate is
@@ -137,17 +166,20 @@ fn main() {
137
166
args. extend_from_slice ( & [ "--cfg" . to_owned ( ) , r#"feature="cargo-miri""# . to_owned ( ) ] ) ;
138
167
139
168
match command. args ( & args) . status ( ) {
140
- Ok ( exit) => if !exit. success ( ) {
141
- std:: process:: exit ( exit. code ( ) . unwrap_or ( 42 ) ) ;
142
- } ,
169
+ Ok ( exit) => {
170
+ if !exit. success ( ) {
171
+ std:: process:: exit ( exit. code ( ) . unwrap_or ( 42 ) ) ;
172
+ }
173
+ }
143
174
Err ( ref e) if miri_enabled => panic ! ( "error during miri run: {:?}" , e) ,
144
175
Err ( ref e) => panic ! ( "error during rustc call: {:?}" , e) ,
145
176
}
146
177
}
147
178
}
148
179
149
180
fn process < I > ( old_args : I ) -> Result < ( ) , i32 >
150
- where I : Iterator < Item = String >
181
+ where
182
+ I : Iterator < Item = String > ,
151
183
{
152
184
let mut args = vec ! [ "rustc" . to_owned( ) ] ;
153
185
0 commit comments