compiletest: Remove all uses of ~str from compiletest

This commit is contained in:
Patrick Walton 2014-05-14 20:47:24 -07:00
parent bbd034c3a6
commit 78bc758c94
7 changed files with 696 additions and 422 deletions

View File

@ -56,10 +56,10 @@ impl fmt::Show for Mode {
#[deriving(Clone)]
pub struct Config {
// The library paths required for running the compiler
pub compile_lib_path: ~str,
pub compile_lib_path: StrBuf,
// The library paths required for running compiled programs
pub run_lib_path: ~str,
pub run_lib_path: StrBuf,
// The rustc executable
pub rustc_path: Path,
@ -80,7 +80,7 @@ pub struct Config {
pub aux_base: Path,
// The name of the stage being built (stage1, etc)
pub stage_id: ~str,
pub stage_id: StrBuf,
// The test mode, compile-fail, run-fail, run-pass
pub mode: Mode,
@ -110,37 +110,37 @@ pub struct Config {
// A command line to prefix program execution with,
// for running under valgrind
pub runtool: Option<~str>,
pub runtool: Option<StrBuf>,
// Flags to pass to the compiler when building for the host
pub host_rustcflags: Option<~str>,
pub host_rustcflags: Option<StrBuf>,
// Flags to pass to the compiler when building for the target
pub target_rustcflags: Option<~str>,
pub target_rustcflags: Option<StrBuf>,
// Run tests using the JIT
pub jit: bool,
// Target system to be tested
pub target: ~str,
pub target: StrBuf,
// Host triple for the compiler being invoked
pub host: ~str,
pub host: StrBuf,
// Path to the android tools
pub android_cross_path: Path,
// Extra parameter to run adb on arm-linux-androideabi
pub adb_path: ~str,
pub adb_path: StrBuf,
// Extra parameter to run test sute on arm-linux-androideabi
pub adb_test_dir: ~str,
pub adb_test_dir: StrBuf,
// status whether android device available or not
pub adb_device_status: bool,
// the path containing LLDB's Python module
pub lldb_python_dir: Option<~str>,
pub lldb_python_dir: Option<StrBuf>,
// Explain what's going on
pub verbose: bool

View File

@ -48,12 +48,14 @@ fn start(argc: int, argv: **u8) -> int {
pub fn main() {
let args = os::args();
let config = parse_config(args.move_iter().collect());
let config = parse_config(args.move_iter()
.map(|x| x.to_strbuf())
.collect());
log_config(&config);
run_tests(&config);
}
pub fn parse_config(args: Vec<~str> ) -> Config {
pub fn parse_config(args: Vec<StrBuf> ) -> Config {
let groups : Vec<getopts::OptGroup> =
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
@ -91,7 +93,7 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
assert!(!args.is_empty());
let argv0 = (*args.get(0)).clone();
let args_ = args.tail();
if *args.get(1) == "-h".to_owned() || *args.get(1) == "--help".to_owned() {
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::usage(message, groups.as_slice()));
println!("");
@ -99,7 +101,11 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
}
let matches =
&match getopts::getopts(args_, groups.as_slice()) {
&match getopts::getopts(args_.iter()
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
groups.as_slice()) {
Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg())
};
@ -129,15 +135,17 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
};
Config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
compile_lib_path: matches.opt_str("compile-lib-path")
.unwrap()
.to_strbuf(),
run_lib_path: matches.opt_str("run-lib-path").unwrap().to_strbuf(),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap(),
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter: filter,
@ -147,21 +155,30 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"),
target_rustcflags: matches.opt_str("target-rustcflags"),
runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()),
host_rustcflags: matches.opt_str("host-rustcflags")
.map(|x| x.to_strbuf()),
target_rustcflags: matches.opt_str("target-rustcflags")
.map(|x| x.to_strbuf()),
jit: matches.opt_present("jit"),
target: opt_str2(matches.opt_str("target")).to_str(),
host: opt_str2(matches.opt_str("host")).to_str(),
target: opt_str2(matches.opt_str("target").map(|x| x.to_strbuf())),
host: opt_str2(matches.opt_str("host").map(|x| x.to_strbuf())),
android_cross_path: opt_path(matches, "android-cross-path"),
adb_path: opt_str2(matches.opt_str("adb-path")).to_str(),
adb_test_dir:
opt_str2(matches.opt_str("adb-test-dir")).to_str(),
adb_path: opt_str2(matches.opt_str("adb-path")
.map(|x| x.to_strbuf())),
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")
.map(|x| x.to_strbuf())),
adb_device_status:
"arm-linux-androideabi" == opt_str2(matches.opt_str("target")) &&
"(none)" != opt_str2(matches.opt_str("adb-test-dir")) &&
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
lldb_python_dir: matches.opt_str("lldb-python-dir"),
"arm-linux-androideabi" ==
opt_str2(matches.opt_str("target")
.map(|x| x.to_strbuf())).as_slice() &&
"(none)" !=
opt_str2(matches.opt_str("adb-test-dir")
.map(|x| x.to_strbuf())).as_slice() &&
!opt_str2(matches.opt_str("adb-test-dir")
.map(|x| x.to_strbuf())).is_empty(),
lldb_python_dir: matches.opt_str("lldb-python-dir")
.map(|x| x.to_strbuf()),
test_shard: test::opt_shard(matches.opt_str("test-shard")
.map(|x| x.to_strbuf())),
verbose: matches.opt_present("verbose")
@ -170,50 +187,59 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
pub fn log_config(config: &Config) {
let c = config;
logv(c, format!("configuration:"));
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
logv(c, format!("run_lib_path: {}", config.run_lib_path));
logv(c, format!("rustc_path: {}", config.rustc_path.display()));
logv(c, format!("src_base: {}", config.src_base.display()));
logv(c, format!("build_base: {}", config.build_base.display()));
logv(c, format!("stage_id: {}", config.stage_id));
logv(c, format!("mode: {}", config.mode));
logv(c, format!("run_ignored: {}", config.run_ignored));
logv(c, format!("filter: {}", opt_str(&config.filter.as_ref().map(|re| re.to_str()))));
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
logv(c, format!("jit: {}", config.jit));
logv(c, format!("target: {}", config.target));
logv(c, format!("host: {}", config.host));
logv(c, format!("android-cross-path: {}", config.android_cross_path.display()));
logv(c, format!("adb_path: {}", config.adb_path));
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
logv(c, format!("adb_device_status: {}", config.adb_device_status));
logv(c, format_strbuf!("configuration:"));
logv(c, format_strbuf!("compile_lib_path: {}", config.compile_lib_path));
logv(c, format_strbuf!("run_lib_path: {}", config.run_lib_path));
logv(c, format_strbuf!("rustc_path: {}", config.rustc_path.display()));
logv(c, format_strbuf!("src_base: {}", config.src_base.display()));
logv(c, format_strbuf!("build_base: {}", config.build_base.display()));
logv(c, format_strbuf!("stage_id: {}", config.stage_id));
logv(c, format_strbuf!("mode: {}", config.mode));
logv(c, format_strbuf!("run_ignored: {}", config.run_ignored));
logv(c, format_strbuf!("filter: {}",
opt_str(&config.filter
.as_ref()
.map(|re| {
re.to_str().into_strbuf()
}))));
logv(c, format_strbuf!("runtool: {}", opt_str(&config.runtool)));
logv(c, format_strbuf!("host-rustcflags: {}",
opt_str(&config.host_rustcflags)));
logv(c, format_strbuf!("target-rustcflags: {}",
opt_str(&config.target_rustcflags)));
logv(c, format_strbuf!("jit: {}", config.jit));
logv(c, format_strbuf!("target: {}", config.target));
logv(c, format_strbuf!("host: {}", config.host));
logv(c, format_strbuf!("android-cross-path: {}",
config.android_cross_path.display()));
logv(c, format_strbuf!("adb_path: {}", config.adb_path));
logv(c, format_strbuf!("adb_test_dir: {}", config.adb_test_dir));
logv(c, format_strbuf!("adb_device_status: {}",
config.adb_device_status));
match config.test_shard {
None => logv(c, "test_shard: (all)".to_owned()),
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
None => logv(c, "test_shard: (all)".to_strbuf()),
Some((a,b)) => logv(c, format_strbuf!("test_shard: {}.{}", a, b))
}
logv(c, format!("verbose: {}", config.verbose));
logv(c, format!("\n"));
logv(c, format_strbuf!("verbose: {}", config.verbose));
logv(c, format_strbuf!("\n"));
}
pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str {
pub fn opt_str<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
match *maybestr {
None => "(none)",
Some(ref s) => {
let s: &'a str = *s;
s
}
Some(ref s) => s.as_slice(),
}
}
pub fn opt_str2(maybestr: Option<~str>) -> ~str {
match maybestr { None => "(none)".to_owned(), Some(s) => { s } }
pub fn opt_str2(maybestr: Option<StrBuf>) -> StrBuf {
match maybestr {
None => "(none)".to_strbuf(),
Some(s) => s,
}
}
pub fn run_tests(config: &Config) {
if config.target == "arm-linux-androideabi".to_owned() {
if config.target.as_slice() == "arm-linux-androideabi" {
match config.mode {
DebugInfoGdb => {
println!("arm-linux-androideabi debug-info \
@ -321,11 +347,11 @@ pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
// Try to elide redundant long paths
fn shorten(path: &Path) -> ~str {
fn shorten(path: &Path) -> StrBuf {
let filename = path.filename_str();
let p = path.dir_path();
let dir = p.filename_str();
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
format_strbuf!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}
test::DynTestName(format_strbuf!("[{}] {}",
@ -336,14 +362,16 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_owned();
test::DynTestFn(proc() { runtest::run(config, testfile) })
let testfile = testfile.as_str().unwrap().to_strbuf();
test::DynTestFn(proc() {
runtest::run(config, testfile)
})
}
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_owned();
let testfile = testfile.as_str().unwrap().to_strbuf();
test::DynMetricFn(proc(mm) {
runtest::run_metrics(config, testfile, mm)
})

View File

@ -12,8 +12,8 @@ use std::io::{BufferedReader, File};
pub struct ExpectedError {
pub line: uint,
pub kind: ~str,
pub msg: ~str,
pub kind: StrBuf,
pub msg: StrBuf,
}
// Load any test directives embedded in the file
@ -23,17 +23,18 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
let mut line_num = 1u;
for ln in rdr.lines() {
error_patterns.push_all_move(parse_expected(line_num, ln.unwrap()));
error_patterns.push_all_move(parse_expected(line_num,
ln.unwrap().to_strbuf()));
line_num += 1u;
}
return error_patterns;
}
fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
let line = line.trim();
let error_tag = "//~".to_owned();
fn parse_expected(line_num: uint, line: StrBuf) -> Vec<ExpectedError> {
let line = line.as_slice().trim().to_strbuf();
let error_tag = "//~".to_strbuf();
let mut idx;
match line.find_str(error_tag) {
match line.as_slice().find_str(error_tag.as_slice()) {
None => return Vec::new(),
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
}
@ -42,25 +43,34 @@ fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
// three lines above current line:
let mut adjust_line = 0u;
let len = line.len();
while idx < len && line[idx] == ('^' as u8) {
while idx < len && line.as_slice()[idx] == ('^' as u8) {
adjust_line += 1u;
idx += 1u;
}
// Extract kind:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
while idx < len && line.as_slice()[idx] == (' ' as u8) {
idx += 1u;
}
let start_kind = idx;
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
while idx < len && line.as_slice()[idx] != (' ' as u8) {
idx += 1u;
}
let kind = line.slice(start_kind, idx);
let kind = kind.to_ascii().to_lower().into_str();
let kind = line.as_slice().slice(start_kind, idx);
let kind = kind.to_ascii().to_lower().into_str().to_strbuf();
// Extract msg:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
let msg = line.slice(idx, len).to_owned();
while idx < len && line.as_slice()[idx] == (' ' as u8) {
idx += 1u;
}
let msg = line.as_slice().slice(idx, len).to_strbuf();
debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
return vec!(ExpectedError{line: line_num - adjust_line, kind: kind,
msg: msg});
return vec!(ExpectedError{
line: line_num - adjust_line,
kind: kind,
msg: msg,
});
}

View File

@ -14,20 +14,20 @@ use util;
pub struct TestProps {
// Lines that should be expected, in order, on standard out
pub error_patterns: Vec<~str> ,
pub error_patterns: Vec<StrBuf> ,
// Extra flags to pass to the compiler
pub compile_flags: Option<~str>,
pub compile_flags: Option<StrBuf>,
// Extra flags to pass when the compiled code is run (such as --bench)
pub run_flags: Option<~str>,
pub run_flags: Option<StrBuf>,
// If present, the name of a file that this test should match when
// pretty-printed
pub pp_exact: Option<Path>,
// Modules from aux directory that should be compiled
pub aux_builds: Vec<~str> ,
pub aux_builds: Vec<StrBuf> ,
// Environment settings to use during execution
pub exec_env: Vec<(~str,~str)> ,
pub exec_env: Vec<(StrBuf,StrBuf)> ,
// Lines to check if they appear in the expected debugger output
pub check_lines: Vec<~str> ,
pub check_lines: Vec<StrBuf> ,
// Flag to force a crate to be built with the host architecture
pub force_host: bool,
// Check stdout for error-pattern output as well as stderr
@ -119,22 +119,30 @@ pub fn load_props(testfile: &Path) -> TestProps {
}
pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
fn ignore_target(config: &Config) -> ~str {
"ignore-".to_owned() + util::get_os(config.target)
fn ignore_target(config: &Config) -> StrBuf {
format_strbuf!("ignore-{}", util::get_os(config.target.as_slice()))
}
fn ignore_stage(config: &Config) -> ~str {
"ignore-".to_owned() + config.stage_id.split('-').next().unwrap()
fn ignore_stage(config: &Config) -> StrBuf {
format_strbuf!("ignore-{}",
config.stage_id.as_slice().split('-').next().unwrap())
}
let val = iter_header(testfile, |ln| {
if parse_name_directive(ln, "ignore-test") { false }
else if parse_name_directive(ln, ignore_target(config)) { false }
else if parse_name_directive(ln, ignore_stage(config)) { false }
else if config.mode == common::Pretty &&
parse_name_directive(ln, "ignore-pretty") { false }
else if config.target != config.host &&
parse_name_directive(ln, "ignore-cross-compile") { false }
else { true }
if parse_name_directive(ln, "ignore-test") {
false
} else if parse_name_directive(ln, ignore_target(config).as_slice()) {
false
} else if parse_name_directive(ln, ignore_stage(config).as_slice()) {
false
} else if config.mode == common::Pretty &&
parse_name_directive(ln, "ignore-pretty") {
false
} else if config.target != config.host &&
parse_name_directive(ln, "ignore-cross-compile") {
false
} else {
true
}
});
!val
@ -156,24 +164,24 @@ fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
return true;
}
fn parse_error_pattern(line: &str) -> Option<~str> {
parse_name_value_directive(line, "error-pattern".to_owned())
fn parse_error_pattern(line: &str) -> Option<StrBuf> {
parse_name_value_directive(line, "error-pattern".to_strbuf())
}
fn parse_aux_build(line: &str) -> Option<~str> {
parse_name_value_directive(line, "aux-build".to_owned())
fn parse_aux_build(line: &str) -> Option<StrBuf> {
parse_name_value_directive(line, "aux-build".to_strbuf())
}
fn parse_compile_flags(line: &str) -> Option<~str> {
parse_name_value_directive(line, "compile-flags".to_owned())
fn parse_compile_flags(line: &str) -> Option<StrBuf> {
parse_name_value_directive(line, "compile-flags".to_strbuf())
}
fn parse_run_flags(line: &str) -> Option<~str> {
parse_name_value_directive(line, "run-flags".to_owned())
fn parse_run_flags(line: &str) -> Option<StrBuf> {
parse_name_value_directive(line, "run-flags".to_strbuf())
}
fn parse_check_line(line: &str) -> Option<~str> {
parse_name_value_directive(line, "check".to_owned())
fn parse_check_line(line: &str) -> Option<StrBuf> {
parse_name_value_directive(line, "check".to_strbuf())
}
fn parse_force_host(line: &str) -> bool {
@ -192,13 +200,16 @@ fn parse_no_pretty_expanded(line: &str) -> bool {
parse_name_directive(line, "no-pretty-expanded")
}
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
parse_name_value_directive(line, "exec-env".to_owned()).map(|nv| {
fn parse_exec_env(line: &str) -> Option<(StrBuf, StrBuf)> {
parse_name_value_directive(line, "exec-env".to_strbuf()).map(|nv| {
// nv is either FOO or FOO=BAR
let mut strs: Vec<~str> = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
let mut strs: Vec<StrBuf> = nv.as_slice()
.splitn('=', 1)
.map(|s| s.to_strbuf())
.collect();
match strs.len() {
1u => (strs.pop().unwrap(), "".to_owned()),
1u => (strs.pop().unwrap(), "".to_strbuf()),
2u => {
let end = strs.pop().unwrap();
(strs.pop().unwrap(), end)
@ -209,7 +220,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
}
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
match parse_name_value_directive(line, "pp-exact".to_owned()) {
match parse_name_value_directive(line, "pp-exact".to_strbuf()) {
Some(s) => Some(Path::new(s)),
None => {
if parse_name_directive(line, "pp-exact") {
@ -225,14 +236,14 @@ fn parse_name_directive(line: &str, directive: &str) -> bool {
line.contains(directive)
}
pub fn parse_name_value_directive(line: &str,
directive: ~str) -> Option<~str> {
let keycolon = directive + ":";
match line.find_str(keycolon) {
pub fn parse_name_value_directive(line: &str, directive: StrBuf)
-> Option<StrBuf> {
let keycolon = format_strbuf!("{}:", directive);
match line.find_str(keycolon.as_slice()) {
Some(colon) => {
let value = line.slice(colon + keycolon.len(),
line.len()).to_owned();
debug!("{}: {}", directive, value);
line.len()).to_strbuf();
debug!("{}: {}", directive, value);
Some(value)
}
None => None

View File

@ -13,7 +13,7 @@ use std::str;
use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
#[cfg(target_os = "win32")]
fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf, StrBuf)> {
let env = os::env();
// Make sure we include the aux directory in the path
@ -22,14 +22,14 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
let mut new_env: Vec<_> = env.move_iter().map(|(k, v)| {
let new_v = if "PATH" == k {
format!("{};{};{}", v, lib_path, aux_path)
format_strbuf!("{};{};{}", v, lib_path, aux_path)
} else {
v
v.to_strbuf()
};
(k, new_v)
(k.to_strbuf(), new_v)
}).collect();
if prog.ends_with("rustc.exe") {
new_env.push(("RUST_THREADS".to_owned(), "1".to_owned()));
new_env.push(("RUST_THREADS".to_strbuf(), "1".to_strbuf()));
}
return new_env;
}
@ -37,11 +37,14 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
fn target_env(lib_path: &str, prog: &str) -> Vec<(StrBuf,StrBuf)> {
// Make sure we include the aux directory in the path
let aux_path = prog + ".libaux";
let mut env: Vec<(~str,~str)> = os::env().move_iter().collect();
let mut env: Vec<(StrBuf,StrBuf)> =
os::env().move_iter()
.map(|(ref k, ref v)| (k.to_strbuf(), v.to_strbuf()))
.collect();
let var = if cfg!(target_os = "macos") {
"DYLD_LIBRARY_PATH"
} else {
@ -49,23 +52,23 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
};
let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
Some(i) => env.remove(i).unwrap().val1(),
None => "".to_owned(),
None => "".to_strbuf(),
};
env.push((var.to_owned(), if prev.is_empty() {
lib_path + ":" + aux_path
env.push((var.to_strbuf(), if prev.is_empty() {
format_strbuf!("{}:{}", lib_path, aux_path)
} else {
lib_path + ":" + aux_path + ":" + prev
format_strbuf!("{}:{}:{}", lib_path, aux_path, prev)
}));
return env;
}
pub struct Result {pub status: ProcessExit, pub out: ~str, pub err: ~str}
pub struct Result {pub status: ProcessExit, pub out: StrBuf, pub err: StrBuf}
pub fn run(lib_path: &str,
prog: &str,
args: &[~str],
env: Vec<(~str, ~str)> ,
input: Option<~str>) -> Option<Result> {
args: &[StrBuf],
env: Vec<(StrBuf, StrBuf)> ,
input: Option<StrBuf>) -> Option<Result> {
let env = env.clone().append(target_env(lib_path, prog).as_slice());
match Command::new(prog).args(args).env(env.as_slice()).spawn() {
@ -78,8 +81,8 @@ pub fn run(lib_path: &str,
Some(Result {
status: status,
out: str::from_utf8(output.as_slice()).unwrap().to_owned(),
err: str::from_utf8(error.as_slice()).unwrap().to_owned()
out: str::from_utf8(output.as_slice()).unwrap().to_strbuf(),
err: str::from_utf8(error.as_slice()).unwrap().to_strbuf()
})
},
Err(..) => None
@ -88,9 +91,9 @@ pub fn run(lib_path: &str,
pub fn run_background(lib_path: &str,
prog: &str,
args: &[~str],
env: Vec<(~str, ~str)> ,
input: Option<~str>) -> Option<Process> {
args: &[StrBuf],
env: Vec<(StrBuf, StrBuf)> ,
input: Option<StrBuf>) -> Option<Process> {
let env = env.clone().append(target_env(lib_path, prog).as_slice());
match Command::new(prog).args(args).env(env.as_slice()).spawn() {

File diff suppressed because it is too large Load Diff

View File

@ -33,25 +33,25 @@ pub fn get_os(triple: &str) -> &'static str {
}
#[cfg(target_os = "win32")]
pub fn make_new_path(path: &str) -> ~str {
pub fn make_new_path(path: &str) -> StrBuf {
// Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own
match getenv(lib_path_env_var()) {
match getenv(lib_path_env_var().as_slice()) {
Some(curr) => {
format!("{}{}{}", path, path_div(), curr)
format_strbuf!("{}{}{}", path, path_div(), curr)
}
None => path.to_str()
None => path.to_str().to_strbuf()
}
}
#[cfg(target_os = "win32")]
pub fn lib_path_env_var() -> ~str { "PATH".to_owned() }
pub fn lib_path_env_var() -> StrBuf { "PATH".to_strbuf() }
#[cfg(target_os = "win32")]
pub fn path_div() -> ~str { ";".to_owned() }
pub fn path_div() -> StrBuf { ";".to_strbuf() }
pub fn logv(config: &Config, s: ~str) {
pub fn logv(config: &Config, s: StrBuf) {
debug!("{}", s);
if config.verbose { println!("{}", s); }
}