Skip to content

Commit 477b422

Browse files
Update for io::io_error being removed
See rust-lang/rust#11946
1 parent 3fa78bb commit 477b422

File tree

1 file changed

+58
-30
lines changed

1 file changed

+58
-30
lines changed

pkg.rs

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ fn cd(path: &Path) {
5353
fn main() {
5454
let pcre_libdir = match os::getenv("PCRE_LIBDIR") {
5555
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+
};
6465
if !pcre_config_output.status.success() {
6566
fail!("Package script error: `pcre-config --prefix` failed");
6667
}
@@ -79,24 +80,24 @@ fn main() {
7980
// Check the version
8081
let target_build_path = workspace_path.join("build").join(host_triple());
8182
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() {
8384
fail!("Package script error: Failed to create target build directory `{}`", target_build_path.display());
8485
}
8586
}
8687
let out_path = target_build_path.join("pcre");
8788
if !out_path.exists() {
88-
if !io::result(|| mkdir(&out_path, 0x1FF)).is_ok() {
89+
if mkdir(&out_path, 0x1FF).is_err() {
8990
fail!("Package script error: Failed to create output directory `{}`", out_path.display());
9091
}
9192
}
9293

9394
let versioncheck_rs_path = out_path.join("versioncheck.rs");
9495
{
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
9899
};
99-
write!(&mut w as &mut Writer, "\
100+
let contents = format!("\
100101
use std::c_str::\\{CString\\};
101102
use std::libc::\\{c_char, c_int, c_uchar, c_void\\};
102103
use std::ptr;
@@ -152,26 +153,35 @@ fn main () \\{
152153
\\}
153154
\\}
154155
");
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+
});
155159
}
156160

157161
// Compile and run `versioncheck.rs`
158162
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);
164171
}
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);
170180
}
171181
cd(&workspace_path);
172182

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();
175185
let output_str = unsafe { str::raw::from_buf_len(output_ptr, output_len) };
176186
debug!("output_str = `{}`", output_str);
177187

@@ -198,19 +208,37 @@ fn main () \\{
198208
// Create directories `bin` and `lib`
199209
let bin_path = workspace_path.join("bin");
200210
if !bin_path.exists() {
201-
if !io::result(|| mkdir(&bin_path, 0x1FF)).is_ok() {
211+
if mkdir(&bin_path, 0x1FF).is_err() {
202212
fail!("Package script error: Failed to create the `bin` directory");
203213
}
204214
}
205215
let lib_path = workspace_path.join("lib");
206216
if !lib_path.exists() {
207-
if !io::result(|| mkdir(&lib_path, 0x1FF)).is_ok() {
217+
if mkdir(&lib_path, 0x1FF).is_err() {
208218
fail!("Package script error: Failed to create the `lib` directory");
209219
}
210220
}
211221

212222
// 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+
}
214233

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+
}
216244
}

0 commit comments

Comments
 (0)