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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ use std::str;
use std::io::process::{ProcessExit, Command, Process, ProcessOutput}; use std::io::process::{ProcessExit, Command, Process, ProcessOutput};
#[cfg(target_os = "win32")] #[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(); let env = os::env();
// Make sure we include the aux directory in the path // 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 mut new_env: Vec<_> = env.move_iter().map(|(k, v)| {
let new_v = if "PATH" == k { let new_v = if "PATH" == k {
format!("{};{};{}", v, lib_path, aux_path) format_strbuf!("{};{};{}", v, lib_path, aux_path)
} else { } else {
v v.to_strbuf()
}; };
(k, new_v) (k.to_strbuf(), new_v)
}).collect(); }).collect();
if prog.ends_with("rustc.exe") { 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; 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 = "linux")]
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")] #[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 // Make sure we include the aux directory in the path
let aux_path = prog + ".libaux"; 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") { let var = if cfg!(target_os = "macos") {
"DYLD_LIBRARY_PATH" "DYLD_LIBRARY_PATH"
} else { } 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) { let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
Some(i) => env.remove(i).unwrap().val1(), Some(i) => env.remove(i).unwrap().val1(),
None => "".to_owned(), None => "".to_strbuf(),
}; };
env.push((var.to_owned(), if prev.is_empty() { env.push((var.to_strbuf(), if prev.is_empty() {
lib_path + ":" + aux_path format_strbuf!("{}:{}", lib_path, aux_path)
} else { } else {
lib_path + ":" + aux_path + ":" + prev format_strbuf!("{}:{}:{}", lib_path, aux_path, prev)
})); }));
return env; 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, pub fn run(lib_path: &str,
prog: &str, prog: &str,
args: &[~str], args: &[StrBuf],
env: Vec<(~str, ~str)> , env: Vec<(StrBuf, StrBuf)> ,
input: Option<~str>) -> Option<Result> { input: Option<StrBuf>) -> Option<Result> {
let env = env.clone().append(target_env(lib_path, prog).as_slice()); let env = env.clone().append(target_env(lib_path, prog).as_slice());
match Command::new(prog).args(args).env(env.as_slice()).spawn() { match Command::new(prog).args(args).env(env.as_slice()).spawn() {
@ -78,8 +81,8 @@ pub fn run(lib_path: &str,
Some(Result { Some(Result {
status: status, status: status,
out: str::from_utf8(output.as_slice()).unwrap().to_owned(), out: str::from_utf8(output.as_slice()).unwrap().to_strbuf(),
err: str::from_utf8(error.as_slice()).unwrap().to_owned() err: str::from_utf8(error.as_slice()).unwrap().to_strbuf()
}) })
}, },
Err(..) => None Err(..) => None
@ -88,9 +91,9 @@ pub fn run(lib_path: &str,
pub fn run_background(lib_path: &str, pub fn run_background(lib_path: &str,
prog: &str, prog: &str,
args: &[~str], args: &[StrBuf],
env: Vec<(~str, ~str)> , env: Vec<(StrBuf, StrBuf)> ,
input: Option<~str>) -> Option<Process> { input: Option<StrBuf>) -> Option<Process> {
let env = env.clone().append(target_env(lib_path, prog).as_slice()); let env = env.clone().append(target_env(lib_path, prog).as_slice());
match Command::new(prog).args(args).env(env.as_slice()).spawn() { 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")] #[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 // Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own // maintain the current value while adding our own
match getenv(lib_path_env_var()) { match getenv(lib_path_env_var().as_slice()) {
Some(curr) => { 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")] #[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")] #[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); debug!("{}", s);
if config.verbose { println!("{}", s); } if config.verbose { println!("{}", s); }
} }