Skip to content

Commit 5005483

Browse files
committed
std::run: Use Result instead of condition
Previously `std::run::Process::new()` raised a io_error condition then tried to unwrap `None`, so it caused assertion failure. This fixes the problem by returning Result instead of raising condition. This also fixes rustc ICE on nonexistent `--linker`.
1 parent 1746c02 commit 5005483

File tree

10 files changed

+91
-68
lines changed

10 files changed

+91
-68
lines changed

src/compiletest/procsrv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn run(lib_path: &str,
5555
in_fd: None,
5656
out_fd: None,
5757
err_fd: None
58-
});
58+
}).unwrap();
5959

6060
for input in input.iter() {
6161
process.input().write(input.as_bytes());
@@ -82,7 +82,7 @@ pub fn run_background(lib_path: &str,
8282
in_fd: None,
8383
out_fd: None,
8484
err_fd: None
85-
});
85+
}).unwrap();
8686

8787
for input in input.iter() {
8888
process.input().write(input.as_bytes());

src/librustc/back/link.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,20 @@ pub mod write {
376376
~"-o", object.as_str().unwrap().to_owned(),
377377
assembly.as_str().unwrap().to_owned()];
378378

379-
let prog = run::process_output(cc_prog, cc_args);
380-
381-
if !prog.status.success() {
382-
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
383-
sess.note(format!("{} arguments: {}",
384-
cc_prog, cc_args.connect(" ")));
385-
sess.note(str::from_utf8(prog.error + prog.output));
386-
sess.abort_if_errors();
379+
match run::process_output(cc_prog, cc_args) {
380+
Ok(prog) => {
381+
if !prog.status.success() {
382+
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
383+
sess.note(format!("{} arguments: {}",
384+
cc_prog, cc_args.connect(" ")));
385+
sess.note(str::from_utf8(prog.error + prog.output));
386+
sess.abort_if_errors();
387+
}
388+
}
389+
Err(err) => {
390+
sess.err(format!("linking with `{}` failed: {}", cc_prog, err.desc));
391+
sess.abort_if_errors();
392+
}
387393
}
388394
}
389395

@@ -945,14 +951,20 @@ pub fn link_binary(sess: Session,
945951
}
946952

947953
// We run 'cc' here
948-
let prog = run::process_output(cc_prog, cc_args);
949-
950-
if !prog.status.success() {
951-
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
952-
sess.note(format!("{} arguments: {}",
953-
cc_prog, cc_args.connect(" ")));
954-
sess.note(str::from_utf8(prog.error + prog.output));
955-
sess.abort_if_errors();
954+
match run::process_output(cc_prog, cc_args) {
955+
Ok(prog) => {
956+
if !prog.status.success() {
957+
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
958+
sess.note(format!("{} arguments: {}",
959+
cc_prog, cc_args.connect(" ")));
960+
sess.note(str::from_utf8(prog.error + prog.output));
961+
sess.abort_if_errors();
962+
}
963+
}
964+
Err(err) => {
965+
sess.err(format!("linking with `{}` failed: {}", cc_prog, err.desc));
966+
sess.abort_if_errors();
967+
}
956968
}
957969

958970
// On OSX, debuggers needs this utility to get run to do some munging of the

src/librustpkg/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn build_library_in_workspace(exec: &mut workcache::Exec,
169169

170170
let all_args = flags + absolute_paths + cc_args +
171171
~[~"-o", out_name.as_str().unwrap().to_owned()];
172-
let exit_process = run::process_status(tool, all_args);
172+
let exit_process = run::process_status(tool, all_args).unwrap();
173173
if exit_process.success() {
174174
let out_name_str = out_name.as_str().unwrap().to_owned();
175175
exec.discover_output("binary",

src/librustpkg/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ impl<'self> PkgScript<'self> {
171171
// FIXME #7401 should support commands besides `install`
172172
// FIXME (#9639): This needs to handle non-utf8 paths
173173
let status = run::process_status(exe.as_str().unwrap(),
174-
[sysroot.as_str().unwrap().to_owned(), ~"install"]);
174+
[sysroot.as_str().unwrap().to_owned(),
175+
~"install"]).unwrap();
175176
if !status.success() {
176177
debug!("run_custom: first pkg command failed with {:?}", status);
177178
(~[], status)
@@ -181,7 +182,8 @@ impl<'self> PkgScript<'self> {
181182
exe.display(), sysroot.display(), "configs");
182183
// FIXME (#9639): This needs to handle non-utf8 paths
183184
let output = run::process_output(exe.as_str().unwrap(),
184-
[sysroot.as_str().unwrap().to_owned(), ~"configs"]);
185+
[sysroot.as_str().unwrap().to_owned(),
186+
~"configs"]).unwrap();
185187
debug!("run_custom: second pkg command did {:?}", output.status);
186188
// Run the configs() function to get the configs
187189
let cfgs = str::from_utf8_slice(output.output).word_iter()
@@ -697,7 +699,8 @@ impl CtxMethods for BuildContext {
697699
Some(test_exec) => {
698700
debug!("test: test_exec = {}", test_exec.display());
699701
// FIXME (#9639): This needs to handle non-utf8 paths
700-
let status = run::process_status(test_exec.as_str().unwrap(), [~"--test"]);
702+
let status = run::process_status(test_exec.as_str().unwrap(),
703+
[~"--test"]).unwrap();
701704
if !status.success() {
702705
fail!("Some tests failed");
703706
}

src/librustpkg/source_control.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
3535
// FIXME (#9639): This needs to handle non-utf8 paths
3636
let outp = run::process_output("git", [~"clone",
3737
source.as_str().unwrap().to_owned(),
38-
target.as_str().unwrap().to_owned()]);
38+
target.as_str().unwrap().to_owned()]).unwrap();
3939
if !outp.status.success() {
4040
println(str::from_utf8_owned(outp.output.clone()));
4141
println(str::from_utf8_owned(outp.error));
@@ -51,7 +51,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
5151
let outp = run::process_output("git",
5252
[format!("--work-tree={}", target.as_str().unwrap().to_owned()),
5353
format!("--git-dir={}", git_dir.as_str().unwrap().to_owned()),
54-
~"checkout", format!("{}", *s)]);
54+
~"checkout", format!("{}", *s)]).unwrap();
5555
if !outp.status.success() {
5656
println(str::from_utf8_owned(outp.output.clone()));
5757
println(str::from_utf8_owned(outp.error));
@@ -72,7 +72,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
7272
let args = [format!("--work-tree={}", target.as_str().unwrap().to_owned()),
7373
format!("--git-dir={}", git_dir.as_str().unwrap().to_owned()),
7474
~"pull", ~"--no-edit", source.as_str().unwrap().to_owned()];
75-
let outp = run::process_output("git", args);
75+
let outp = run::process_output("git", args).unwrap();
7676
assert!(outp.status.success());
7777
}
7878
CheckedOutSources
@@ -109,7 +109,7 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
109109

110110
// FIXME (#9639): This needs to handle non-utf8 paths
111111
let outp = run::process_output("git", [~"clone", source.to_owned(),
112-
target.as_str().unwrap().to_owned()]);
112+
target.as_str().unwrap().to_owned()]).unwrap();
113113
if !outp.status.success() {
114114
debug!("{}", str::from_utf8_owned(outp.output.clone()));
115115
debug!("{}", str::from_utf8_owned(outp.error));
@@ -133,7 +133,7 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
133133

134134
fn process_output_in_cwd(prog: &str, args: &[~str], cwd: &Path) -> ProcessOutput {
135135
let mut prog = Process::new(prog, args, ProcessOptions{ dir: Some(cwd)
136-
,..ProcessOptions::new()});
136+
,..ProcessOptions::new()}).unwrap();
137137
prog.finish_with_output()
138138
}
139139

src/librustpkg/tests.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
149149
in_fd: None,
150150
out_fd: None,
151151
err_fd: None
152-
});
152+
}).unwrap();
153153
let rslt = prog.finish_with_output();
154154
if !rslt.status.success() {
155155
fail!("{} [git returned {:?}, output = {}, error = {}]", err_msg,
@@ -286,7 +286,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
286286
in_fd: None,
287287
out_fd: None,
288288
err_fd: None
289-
});
289+
}).unwrap();
290290
let output = prog.finish_with_output();
291291
debug!("Output from command {} with args {:?} was {} \\{{}\\}[{:?}]",
292292
cmd, args, str::from_utf8(output.output),
@@ -504,9 +504,10 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
504504
// should be able to do this w/o a process
505505
// FIXME (#9639): This needs to handle non-utf8 paths
506506
// n.b. Bumps time up by 2 seconds to get around granularity issues
507-
if !run::process_output("touch", [~"--date",
507+
let output = run::process_output("touch", [~"--date",
508508
~"+2 seconds",
509-
p.as_str().unwrap().to_owned()]).status.success() {
509+
p.as_str().unwrap().to_owned()]).unwrap();
510+
if !output.status.success() {
510511
let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path"));
511512
}
512513
}
@@ -523,8 +524,9 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
523524
// should be able to do this w/o a process
524525
// FIXME (#9639): This needs to handle non-utf8 paths
525526
// n.b. Bumps time up by 2 seconds to get around granularity issues
526-
if !run::process_output("touch", [~"-A02",
527-
p.as_str().unwrap().to_owned()]).status.success() {
527+
let output = run::process_output("touch", [~"-A02",
528+
p.as_str().unwrap().to_owned()]).unwrap();
529+
if !output.status.success() {
528530
let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path"));
529531
}
530532
}
@@ -1278,7 +1280,7 @@ fn test_extern_mod() {
12781280
in_fd: None,
12791281
out_fd: None,
12801282
err_fd: None
1281-
});
1283+
}).unwrap();
12821284
let outp = prog.finish_with_output();
12831285
if !outp.status.success() {
12841286
fail!("output was {}, error was {}",
@@ -1333,7 +1335,7 @@ fn test_extern_mod_simpler() {
13331335
in_fd: None,
13341336
out_fd: None,
13351337
err_fd: None
1336-
});
1338+
}).unwrap();
13371339
let outp = prog.finish_with_output();
13381340
if !outp.status.success() {
13391341
fail!("output was {}, error was {}",

src/librustpkg/version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
105105
}
106106
// FIXME (#9639): This needs to handle non-utf8 paths
107107
let outp = run::process_output("git",
108-
["--git-dir=" + git_dir.as_str().unwrap(), ~"tag", ~"-l"]);
108+
["--git-dir=" + git_dir.as_str().unwrap(), ~"tag", ~"-l"]).unwrap();
109109

110110
debug!("git --git-dir={} tag -l ~~~> {:?}", git_dir.display(), outp.status);
111111

@@ -142,7 +142,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
142142
// FIXME (#9639): This needs to handle non-utf8 paths
143143
let outp = run::process_output("git", [~"clone", format!("https://{}",
144144
remote_path.as_str().unwrap()),
145-
tmp_dir.as_str().unwrap().to_owned()]);
145+
tmp_dir.as_str().unwrap().to_owned()]).unwrap();
146146
if outp.status.success() {
147147
debug!("Cloned it... ( {}, {} )",
148148
str::from_utf8(outp.output),
@@ -154,7 +154,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
154154
// FIXME (#9639): This needs to handle non-utf8 paths
155155
let outp = run::process_output("git",
156156
["--git-dir=" + git_dir.as_str().unwrap(),
157-
~"tag", ~"-l"]);
157+
~"tag", ~"-l"]).unwrap();
158158
let output_text = str::from_utf8(outp.output);
159159
debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
160160
for l in output_text.line_iter() {

0 commit comments

Comments
 (0)