Convert std::run to istrs. Issue #855

This commit is contained in:
Brian Anderson 2011-08-24 18:40:57 -07:00
parent 4cf2e510e0
commit 20178b9312
5 changed files with 39 additions and 28 deletions

View File

@ -551,12 +551,14 @@ fn main(args: [str]) {
let glu: str = binary_dir + "/lib/glue.o";
let main: str = binary_dir + "/lib/main.o";
let stage: str = "-L" + binary_dir + "/lib";
let prog: str = "gcc";
let prog: istr = ~"gcc";
// The invocations of gcc share some flags across platforms
let gcc_args =
[stage, "-Lrt", "-lrustrt", glu, "-m32", "-o", saved_out_filename,
saved_out_filename + ".o"];
[istr::from_estr(stage),
~"-Lrt", ~"-lrustrt", istr::from_estr(glu),
~"-m32", ~"-o", istr::from_estr(saved_out_filename),
istr::from_estr(saved_out_filename) + ~".o"];
let lib_cmd;
let os = sess.get_targ_cfg().os;
@ -590,46 +592,49 @@ fn main(args: [str]) {
let cstore = sess.get_cstore();
for cratepath: str in cstore::get_used_crate_files(cstore) {
if str::ends_with(cratepath, ".rlib") {
gcc_args += [cratepath];
gcc_args += [istr::from_estr(cratepath)];
cont;
}
let cratepath = istr::from_estr(cratepath);
let dir = fs::dirname(cratepath);
if dir != ~"" { gcc_args += ["-L" + istr::to_estr(dir)]; }
if dir != ~"" { gcc_args += [~"-L" + dir]; }
let libarg = unlib(sess.get_targ_cfg(), fs::basename(cratepath));
gcc_args += ["-l" + istr::to_estr(libarg)];
gcc_args += [~"-l" + libarg];
}
let ula = cstore::get_used_link_args(cstore);
for arg: str in ula { gcc_args += [arg]; }
for arg: str in ula { gcc_args += [istr::from_estr(arg)]; }
let used_libs = cstore::get_used_libraries(cstore);
for l: str in used_libs { gcc_args += ["-l" + l]; }
for l: str in used_libs { gcc_args += [~"-l" + istr::from_estr(l)]; }
if sopts.library {
gcc_args += [lib_cmd];
gcc_args += [istr::from_estr(lib_cmd)];
} else {
// FIXME: why do we hardcode -lm?
gcc_args += ["-lm", main];
gcc_args += [~"-lm", istr::from_estr(main)];
}
// We run 'gcc' here
let err_code = run::run_program(prog, gcc_args);
if 0 != err_code {
sess.err(#fmt["linking with gcc failed with code %d", err_code]);
sess.note(#fmt["gcc arguments: %s", str::connect(gcc_args, " ")]);
sess.note(#fmt["gcc arguments: %s",
istr::to_estr(istr::connect(gcc_args, ~" "))]);
sess.abort_if_errors();
}
// Clean up on Darwin
if sess.get_targ_cfg().os == session::os_macos {
run::run_program("dsymutil", [saved_out_filename]);
run::run_program(~"dsymutil",
[istr::from_estr(saved_out_filename)]);
}
// Remove the temporary object file if we aren't saving temps
if !sopts.save_temps {
run::run_program("rm", [saved_out_filename + ".o"]);
run::run_program(~"rm",
[istr::from_estr(saved_out_filename) + ~".o"]);
}
}

View File

@ -24,7 +24,7 @@ import rustc::syntax::print::pprust;
fn write_file(filename: &str, content: &str) {
io::file_writer(filename, [io::create, io::truncate]).write_str(content);
// Work around https://github.com/graydon/rust/issues/726
std::run::run_program("chmod", ["644", filename]);
std::run::run_program(~"chmod", [~"644", istr::from_estr(filename)]);
}
fn file_contains(filename: &str, needle: &str) -> bool {
@ -190,8 +190,9 @@ fn check_whole_compiler(code: &str) {
let filename = "test.rs";
write_file(filename, code);
let p =
std::run::program_output("/Users/jruderman/code/rust/build/stage1/rustc",
["-c", filename]);
std::run::program_output(
~"/Users/jruderman/code/rust/build/stage1/rustc",
[~"-c", istr::from_estr(filename)]);
//log_err #fmt("Status: %d", p.status);
//log_err "Output: " + p.out;
@ -328,9 +329,9 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) {
log_err #fmt["Did not converge after %u iterations!", i];
write_file("round-trip-a.rs", old);
write_file("round-trip-b.rs", new);
std::run::run_program("diff",
["-w", "-u", "round-trip-a.rs",
"round-trip-b.rs"]);
std::run::run_program(~"diff",
[~"-w", ~"-u", ~"round-trip-a.rs",
~"round-trip-b.rs"]);
fail "Mismatch";
}
}

View File

@ -19,8 +19,10 @@ fn arg_vec(prog: str, args: &[str]) -> [sbuf] {
ret argptrs;
}
fn spawn_process(prog: str, args: &[str], in_fd: int, out_fd: int,
fn spawn_process(prog: &istr, args: &[istr], in_fd: int, out_fd: int,
err_fd: int) -> int {
let prog = istr::to_estr(prog);
let args = istr::to_estrs(args);
// Note: we have to hold on to this vector reference while we hold a
// pointer to its buffer
let argv = arg_vec(prog, args);
@ -29,7 +31,7 @@ fn spawn_process(prog: str, args: &[str], in_fd: int, out_fd: int,
ret pid;
}
fn run_program(prog: str, args: &[str]) -> int {
fn run_program(prog: &istr, args: &[istr]) -> int {
ret os::waitpid(spawn_process(prog, args, 0, 0, 0));
}
@ -46,7 +48,7 @@ type program =
resource program_res(p: program) { p.destroy(); }
fn start_program(prog: str, args: &[str]) -> @program_res {
fn start_program(prog: &istr, args: &[istr]) -> @program_res {
let pipe_input = os::pipe();
let pipe_output = os::pipe();
let pipe_err = os::pipe();
@ -106,7 +108,7 @@ fn read_all(rd: &io::reader) -> str {
ret buf;
}
fn program_output(prog: str, args: [str]) ->
fn program_output(prog: &istr, args: &[istr]) ->
{status: int, out: str, err: str} {
let pr = start_program(prog, args);
pr.close_input();

View File

@ -13,6 +13,7 @@ import std::os;
import std::run;
import std::io;
import std::str;
import std::istr;
import std::comm::chan;
import std::comm::port;
import std::comm::send;
@ -128,7 +129,8 @@ fn worker(p: port<request>) {
let pipe_out = os::pipe();
let pipe_err = os::pipe();
let spawnproc =
bind run::spawn_process(execparms.prog, execparms.args,
bind run::spawn_process(istr::from_estr(execparms.prog),
istr::from_estrs(execparms.args),
pipe_in.in, pipe_out.out, pipe_err.out);
let pid = with_lib_path(execparms.lib_path, spawnproc);

View File

@ -11,9 +11,9 @@ import std::vec;
#[cfg(target_os = "macos")]
#[test]
fn test_leaks() {
run::run_program("echo", []);
run::start_program("echo", []);
run::program_output("echo", []);
run::run_program(~"echo", []);
run::start_program(~"echo", []);
run::program_output(~"echo", []);
}
// FIXME
@ -29,7 +29,8 @@ fn test_pipes() {
let pipe_err = os::pipe();
let pid =
run::spawn_process("cat", [], pipe_in.in, pipe_out.out, pipe_err.out);
run::spawn_process(~"cat", [],
pipe_in.in, pipe_out.out, pipe_err.out);
os::libc::close(pipe_in.in);
os::libc::close(pipe_out.out);
os::libc::close(pipe_err.out);