@@ -53,14 +53,15 @@ fn cd(path: &Path) {
53
53
fn main ( ) {
54
54
let pcre_libdir = match os:: getenv ( "PCRE_LIBDIR" ) {
55
55
None => {
56
- let pcre_config_output = io:: io_error:: cond. trap ( |e : io:: IoError | {
57
- match e. kind {
58
- io:: FileNotFound => fail ! ( "Package script error: Could not run `pcre-config` because no such executable is in the executable search PATH. Make sure that you have installed a dev package for libpcre and/or make sure that libpcre's bindir is added to your PATH (currently \" {}\" )." , os:: getenv( "PATH" ) . unwrap_or( ~"") ) ,
59
- _ => fail ! ( "Package script error: Could not run `pcre-config`: {}" , e. to_str( ) )
60
- }
61
- } ) . inside ( || -> run:: ProcessOutput {
62
- run:: process_output ( "pcre-config" , [ ~"--prefix"] ) . expect ( "failed to exec `pcre-config`" )
63
- } ) ;
56
+ let pcre_config_output = match run:: process_output ( "pcre-config" , [ ~"--prefix"] ) {
57
+ Err ( e) => {
58
+ match e. kind {
59
+ io:: FileNotFound => fail ! ( "Package script error: Could not run `pcre-config` because no such executable is in the executable search PATH. Make sure that you have installed a dev package for libpcre and/or make sure that libpcre's bindir is added to your PATH (currently \" {}\" )." , os:: getenv( "PATH" ) . unwrap_or( ~"") ) ,
60
+ _ => fail ! ( "Package script error: Could not run `pcre-config`: {}" , e. to_str( ) )
61
+ }
62
+ } ,
63
+ Ok ( pcre_config_output) => pcre_config_output
64
+ } ;
64
65
if !pcre_config_output. status . success ( ) {
65
66
fail ! ( "Package script error: `pcre-config --prefix` failed" ) ;
66
67
}
@@ -79,24 +80,24 @@ fn main() {
79
80
// Check the version
80
81
let target_build_path = workspace_path. join ( "build" ) . join ( host_triple ( ) ) ;
81
82
if !target_build_path. exists ( ) {
82
- if !io :: result ( || mkdir ( & target_build_path, 0x1FF ) ) . is_ok ( ) {
83
+ if mkdir ( & target_build_path, 0x1FF ) . is_err ( ) {
83
84
fail ! ( "Package script error: Failed to create target build directory `{}`" , target_build_path. display( ) ) ;
84
85
}
85
86
}
86
87
let out_path = target_build_path. join ( "pcre" ) ;
87
88
if !out_path. exists ( ) {
88
- if !io :: result ( || mkdir ( & out_path, 0x1FF ) ) . is_ok ( ) {
89
+ if mkdir ( & out_path, 0x1FF ) . is_err ( ) {
89
90
fail ! ( "Package script error: Failed to create output directory `{}`" , out_path. display( ) ) ;
90
91
}
91
92
}
92
93
93
94
let versioncheck_rs_path = out_path. join ( "versioncheck.rs" ) ;
94
95
{
95
- let mut w = match File :: create ( & versioncheck_rs_path) {
96
- None => fail ! ( "Package script error: Failed to open `{}` for writing" , versioncheck_rs_path. display( ) ) ,
97
- Some ( w ) => w
96
+ let mut f = match File :: create ( & versioncheck_rs_path) {
97
+ Err ( e ) => fail ! ( "Package script error: Failed to open `{}` for writing: {:s} " , versioncheck_rs_path. display( ) , e . to_str ( ) ) ,
98
+ Ok ( f ) => f
98
99
} ;
99
- write ! ( & mut w as & mut Writer , "\
100
+ let contents = format ! ( "\
100
101
use std::c_str::\\ {CString\\ };
101
102
use std::libc::\\ {c_char, c_int, c_uchar, c_void\\ };
102
103
use std::ptr;
@@ -152,26 +153,35 @@ fn main () \\{
152
153
\\ }
153
154
\\ }
154
155
" ) ;
156
+ f. write_str ( contents) . map_err ( |e| -> ( ) {
157
+ fail ! ( "Package script error: Failed to write to `{}`: {:s}" , versioncheck_rs_path. display( ) , e. to_str( ) ) ;
158
+ } ) ;
155
159
}
156
160
157
161
// Compile and run `versioncheck.rs`
158
162
cd ( & out_path) ;
159
- let rustc_run_output = run:: process_output ( "rustc" , [ ~"versioncheck. rs ", ~"-L ", pcre_lib_path. display ( ) . to_str ( ) ] ) . expect ( "failed to exec `rustc`" ) ;
160
- if !rustc_run_output. status . success ( ) {
161
- println ! ( "{}" , str :: from_utf8( rustc_run_output. output) ) ;
162
- println ! ( "{}" , str :: from_utf8( rustc_run_output. error) ) ;
163
- fail ! ( "Package script error: `rustc versioncheck.rs` failed: {}" , rustc_run_output. status) ;
163
+ let rustc_output = match run:: process_output ( "rustc" , [ ~"versioncheck. rs ", ~"-L ", pcre_lib_path. display ( ) . to_str ( ) ] ) {
164
+ Err ( e) => fail ! ( "Package script error: Failed to run `rustc`: {:s}" , e. to_str( ) ) ,
165
+ Ok ( rustc_output) => rustc_output
166
+ } ;
167
+ if !rustc_output. status . success ( ) {
168
+ println ! ( "{}" , str :: from_utf8( rustc_output. output) ) ;
169
+ println ! ( "{}" , str :: from_utf8( rustc_output. error) ) ;
170
+ fail ! ( "Package script error: `rustc versioncheck.rs` failed: {}" , rustc_output. status) ;
164
171
}
165
- let version_check_output = run:: process_output ( "./versioncheck" , [ ] ) . expect ( "failed to exec `./versioncheck`" ) ;
166
- if !version_check_output. status . success ( ) {
167
- println ! ( "{}" , str :: from_utf8( version_check_output. output) ) ;
168
- println ! ( "{}" , str :: from_utf8( version_check_output. error) ) ;
169
- fail ! ( "versioncheck error: {}" , version_check_output. status) ;
172
+ let versioncheck_output = match run:: process_output ( "./versioncheck" , [ ] ) {
173
+ Err ( e) => fail ! ( "Package script error: Failed to run `./versioncheck`: {:s}" , e. to_str( ) ) ,
174
+ Ok ( versioncheck_output) => versioncheck_output
175
+ } ;
176
+ if !versioncheck_output. status . success ( ) {
177
+ println ! ( "{}" , str :: from_utf8( versioncheck_output. output) ) ;
178
+ println ! ( "{}" , str :: from_utf8( versioncheck_output. error) ) ;
179
+ fail ! ( "versioncheck error: {}" , versioncheck_output. status) ;
170
180
}
171
181
cd ( & workspace_path) ;
172
182
173
- let output_ptr = version_check_output . output . as_ptr ( ) ;
174
- let output_len = version_check_output . output . len ( ) ;
183
+ let output_ptr = versioncheck_output . output . as_ptr ( ) ;
184
+ let output_len = versioncheck_output . output . len ( ) ;
175
185
let output_str = unsafe { str:: raw:: from_buf_len ( output_ptr, output_len) } ;
176
186
debug ! ( "output_str = `{}`" , output_str) ;
177
187
@@ -198,19 +208,37 @@ fn main () \\{
198
208
// Create directories `bin` and `lib`
199
209
let bin_path = workspace_path. join ( "bin" ) ;
200
210
if !bin_path. exists ( ) {
201
- if !io :: result ( || mkdir ( & bin_path, 0x1FF ) ) . is_ok ( ) {
211
+ if mkdir ( & bin_path, 0x1FF ) . is_err ( ) {
202
212
fail ! ( "Package script error: Failed to create the `bin` directory" ) ;
203
213
}
204
214
}
205
215
let lib_path = workspace_path. join ( "lib" ) ;
206
216
if !lib_path. exists ( ) {
207
- if !io :: result ( || mkdir ( & lib_path, 0x1FF ) ) . is_ok ( ) {
217
+ if mkdir ( & lib_path, 0x1FF ) . is_err ( ) {
208
218
fail ! ( "Package script error: Failed to create the `lib` directory" ) ;
209
219
}
210
220
}
211
221
212
222
// Compile libpcre-*.rlib
213
- run:: process_output ( "rustc" , [ ~"--out-dir", lib_path. display ( ) . to_str ( ) , ~"src/pcre/mod. rs ", ~"-L ", pcre_lib_path. display ( ) . to_str ( ) ] ) ;
223
+ match run:: process_output ( "rustc" , [ ~"--out-dir", lib_path. display ( ) . to_str ( ) , ~"src/pcre/mod. rs ", ~"-L ", pcre_lib_path. display ( ) . to_str ( ) ] ) {
224
+ Err ( e) => fail ! ( "Package script error: Failed to run `rustc`: {:s}" , e. to_str( ) ) ,
225
+ Ok ( rustc_output) => {
226
+ if !rustc_output. status . success ( ) {
227
+ println ! ( "{}" , str :: from_utf8( rustc_output. output) ) ;
228
+ println ! ( "{}" , str :: from_utf8( rustc_output. error) ) ;
229
+ fail ! ( "Package script error: `rustc src/pcre/mod.rs` failed: {}" , rustc_output. status) ;
230
+ }
231
+ }
232
+ }
214
233
215
- run:: process_output ( "rustc" , [ ~"-o", bin_path. join ( "pcredemo" ) . display ( ) . to_str ( ) , ~"src/pcredemo/main. rs ", ~"-L ", ~"lib", ~"-L ", pcre_lib_path. display ( ) . to_str ( ) ] ) ;
234
+ match run:: process_output ( "rustc" , [ ~"-o", bin_path. join ( "pcredemo" ) . display ( ) . to_str ( ) , ~"src/pcredemo/main. rs ", ~"-L ", ~"lib", ~"-L ", pcre_lib_path. display ( ) . to_str ( ) ] ) {
235
+ Err ( e) => fail ! ( "Package script error: Failed to run `rustc`: {:s}" , e. to_str( ) ) ,
236
+ Ok ( rustc_output) => {
237
+ if !rustc_output. status . success ( ) {
238
+ println ! ( "{}" , str :: from_utf8( rustc_output. output) ) ;
239
+ println ! ( "{}" , str :: from_utf8( rustc_output. error) ) ;
240
+ fail ! ( "Package script error: `rustc src/pcredemo/main.rs` failed: {}" , rustc_output. status) ;
241
+ }
242
+ }
243
+ }
216
244
}
0 commit comments