Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::run: Use Result instead of condition #10654

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn run(lib_path: &str,
in_fd: None,
out_fd: None,
err_fd: None
});
}).unwrap();

for input in input.iter() {
process.input().write(input.as_bytes());
Expand All @@ -82,7 +82,7 @@ pub fn run_background(lib_path: &str,
in_fd: None,
out_fd: None,
err_fd: None
});
}).unwrap();

for input in input.iter() {
process.input().write(input.as_bytes());
Expand Down
44 changes: 28 additions & 16 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,20 @@ pub mod write {
~"-o", object.as_str().unwrap().to_owned(),
assembly.as_str().unwrap().to_owned()];

let prog = run::process_output(cc_prog, cc_args);

if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
sess.note(format!("{} arguments: {}",
cc_prog, cc_args.connect(" ")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
match run::process_output(cc_prog, cc_args) {
Ok(prog) => {
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
sess.note(format!("{} arguments: {}",
cc_prog, cc_args.connect(" ")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
}
}
Err(err) => {
sess.err(format!("linking with `{}` failed: {}", cc_prog, err.desc));
sess.abort_if_errors();
}
}
}

Expand Down Expand Up @@ -945,14 +951,20 @@ pub fn link_binary(sess: Session,
}

// We run 'cc' here
let prog = run::process_output(cc_prog, cc_args);

if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
sess.note(format!("{} arguments: {}",
cc_prog, cc_args.connect(" ")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
match run::process_output(cc_prog, cc_args) {
Ok(prog) => {
if !prog.status.success() {
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
sess.note(format!("{} arguments: {}",
cc_prog, cc_args.connect(" ")));
sess.note(str::from_utf8(prog.error + prog.output));
sess.abort_if_errors();
}
}
Err(err) => {
sess.err(format!("linking with `{}` failed: {}", cc_prog, err.desc));
sess.abort_if_errors();
}
}

// On OSX, debuggers needs this utility to get run to do some munging of the
Expand Down
2 changes: 1 addition & 1 deletion src/librustpkg/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn build_library_in_workspace(exec: &mut workcache::Exec,

let all_args = flags + absolute_paths + cc_args +
~[~"-o", out_name.as_str().unwrap().to_owned()];
let exit_process = run::process_status(tool, all_args);
let exit_process = run::process_status(tool, all_args).unwrap();
if exit_process.success() {
let out_name_str = out_name.as_str().unwrap().to_owned();
exec.discover_output("binary",
Expand Down
9 changes: 6 additions & 3 deletions src/librustpkg/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ impl<'self> PkgScript<'self> {
// FIXME #7401 should support commands besides `install`
// FIXME (#9639): This needs to handle non-utf8 paths
let status = run::process_status(exe.as_str().unwrap(),
[sysroot.as_str().unwrap().to_owned(), ~"install"]);
[sysroot.as_str().unwrap().to_owned(),
~"install"]).unwrap();
if !status.success() {
debug!("run_custom: first pkg command failed with {:?}", status);
(~[], status)
Expand All @@ -181,7 +182,8 @@ impl<'self> PkgScript<'self> {
exe.display(), sysroot.display(), "configs");
// FIXME (#9639): This needs to handle non-utf8 paths
let output = run::process_output(exe.as_str().unwrap(),
[sysroot.as_str().unwrap().to_owned(), ~"configs"]);
[sysroot.as_str().unwrap().to_owned(),
~"configs"]).unwrap();
debug!("run_custom: second pkg command did {:?}", output.status);
// Run the configs() function to get the configs
let cfgs = str::from_utf8_slice(output.output).word_iter()
Expand Down Expand Up @@ -697,7 +699,8 @@ impl CtxMethods for BuildContext {
Some(test_exec) => {
debug!("test: test_exec = {}", test_exec.display());
// FIXME (#9639): This needs to handle non-utf8 paths
let status = run::process_status(test_exec.as_str().unwrap(), [~"--test"]);
let status = run::process_status(test_exec.as_str().unwrap(),
[~"--test"]).unwrap();
if !status.success() {
fail!("Some tests failed");
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustpkg/source_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
// FIXME (#9639): This needs to handle non-utf8 paths
let outp = run::process_output("git", [~"clone",
source.as_str().unwrap().to_owned(),
target.as_str().unwrap().to_owned()]);
target.as_str().unwrap().to_owned()]).unwrap();
if !outp.status.success() {
println(str::from_utf8_owned(outp.output.clone()));
println(str::from_utf8_owned(outp.error));
Expand All @@ -51,7 +51,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
let outp = run::process_output("git",
[format!("--work-tree={}", target.as_str().unwrap().to_owned()),
format!("--git-dir={}", git_dir.as_str().unwrap().to_owned()),
~"checkout", format!("{}", *s)]);
~"checkout", format!("{}", *s)]).unwrap();
if !outp.status.success() {
println(str::from_utf8_owned(outp.output.clone()));
println(str::from_utf8_owned(outp.error));
Expand All @@ -72,7 +72,7 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
let args = [format!("--work-tree={}", target.as_str().unwrap().to_owned()),
format!("--git-dir={}", git_dir.as_str().unwrap().to_owned()),
~"pull", ~"--no-edit", source.as_str().unwrap().to_owned()];
let outp = run::process_output("git", args);
let outp = run::process_output("git", args).unwrap();
assert!(outp.status.success());
}
CheckedOutSources
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {

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

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

Expand Down
18 changes: 10 additions & 8 deletions src/librustpkg/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
in_fd: None,
out_fd: None,
err_fd: None
});
}).unwrap();
let rslt = prog.finish_with_output();
if !rslt.status.success() {
fail!("{} [git returned {:?}, output = {}, error = {}]", err_msg,
Expand Down Expand Up @@ -286,7 +286,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
in_fd: None,
out_fd: None,
err_fd: None
});
}).unwrap();
let output = prog.finish_with_output();
debug!("Output from command {} with args {:?} was {} \\{{}\\}[{:?}]",
cmd, args, str::from_utf8(output.output),
Expand Down Expand Up @@ -504,9 +504,10 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
// should be able to do this w/o a process
// FIXME (#9639): This needs to handle non-utf8 paths
// n.b. Bumps time up by 2 seconds to get around granularity issues
if !run::process_output("touch", [~"--date",
let output = run::process_output("touch", [~"--date",
~"+2 seconds",
p.as_str().unwrap().to_owned()]).status.success() {
p.as_str().unwrap().to_owned()]).unwrap();
if !output.status.success() {
let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path"));
}
}
Expand All @@ -523,8 +524,9 @@ fn touch_source_file(workspace: &Path, pkgid: &PkgId) {
// should be able to do this w/o a process
// FIXME (#9639): This needs to handle non-utf8 paths
// n.b. Bumps time up by 2 seconds to get around granularity issues
if !run::process_output("touch", [~"-A02",
p.as_str().unwrap().to_owned()]).status.success() {
let output = run::process_output("touch", [~"-A02",
p.as_str().unwrap().to_owned()]).unwrap();
if !output.status.success() {
let _ = cond.raise((pkg_src_dir.clone(), ~"Bad path"));
}
}
Expand Down Expand Up @@ -1278,7 +1280,7 @@ fn test_extern_mod() {
in_fd: None,
out_fd: None,
err_fd: None
});
}).unwrap();
let outp = prog.finish_with_output();
if !outp.status.success() {
fail!("output was {}, error was {}",
Expand Down Expand Up @@ -1333,7 +1335,7 @@ fn test_extern_mod_simpler() {
in_fd: None,
out_fd: None,
err_fd: None
});
}).unwrap();
let outp = prog.finish_with_output();
if !outp.status.success() {
fail!("output was {}, error was {}",
Expand Down
6 changes: 3 additions & 3 deletions src/librustpkg/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
}
// FIXME (#9639): This needs to handle non-utf8 paths
let outp = run::process_output("git",
["--git-dir=" + git_dir.as_str().unwrap(), ~"tag", ~"-l"]);
["--git-dir=" + git_dir.as_str().unwrap(), ~"tag", ~"-l"]).unwrap();

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

Expand Down Expand Up @@ -142,7 +142,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
// FIXME (#9639): This needs to handle non-utf8 paths
let outp = run::process_output("git", [~"clone", format!("https://{}",
remote_path.as_str().unwrap()),
tmp_dir.as_str().unwrap().to_owned()]);
tmp_dir.as_str().unwrap().to_owned()]).unwrap();
if outp.status.success() {
debug!("Cloned it... ( {}, {} )",
str::from_utf8(outp.output),
Expand All @@ -154,7 +154,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
// FIXME (#9639): This needs to handle non-utf8 paths
let outp = run::process_output("git",
["--git-dir=" + git_dir.as_str().unwrap(),
~"tag", ~"-l"]);
~"tag", ~"-l"]).unwrap();
let output_text = str::from_utf8(outp.output);
debug!("Full output: ( {} ) [{:?}]", output_text, outp.status);
for l in output_text.line_iter() {
Expand Down
Loading