Skip to content

Commit

Permalink
auto merge of #9655 : kballard/rust/path-rewrite, r=alexcrichton
Browse files Browse the repository at this point in the history
Rewrite the entire `std::path` module from scratch.

`PosixPath` is now based on `~[u8]`, which fixes #7225.
Unnecessary allocation has been eliminated.

There are a lot of clients of `Path` that still assume utf-8 paths.
This is covered in #9639.
  • Loading branch information
bors committed Oct 16, 2013
2 parents fabec99 + d108a22 commit 40180cd
Show file tree
Hide file tree
Showing 62 changed files with 6,330 additions and 2,751 deletions.
36 changes: 19 additions & 17 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ pub fn parse_config(args: ~[~str]) -> config {
}

fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
Path(m.opt_str(nm).unwrap())
Path::new(m.opt_str(nm).unwrap())
}

config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: matches.opt_str("clang-path").map(|s| Path(s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path(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)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
Expand All @@ -123,10 +123,10 @@ pub fn parse_config(args: ~[~str]) -> config {
} else {
None
},
logfile: matches.opt_str("logfile").map(|s| Path(s)),
save_metrics: matches.opt_str("save-metrics").map(|s| Path(s)),
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
ratchet_metrics:
matches.opt_str("ratchet-metrics").map(|s| Path(s)),
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"),
Expand Down Expand Up @@ -155,9 +155,9 @@ pub fn log_config(config: &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.to_str()));
logv(c, format!("src_base: {}", config.src_base.to_str()));
logv(c, format!("build_base: {}", config.build_base.to_str()));
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: {}", mode_str(config.mode)));
logv(c, format!("run_ignored: {}", config.run_ignored));
Expand Down Expand Up @@ -245,12 +245,12 @@ pub fn test_opts(config: &config) -> test::TestOpts {

pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
debug2!("making tests from {}",
config.src_base.to_str());
config.src_base.display());
let mut tests = ~[];
let dirs = os::list_dir_path(&config.src_base);
for file in dirs.iter() {
let file = file.clone();
debug2!("inspecting file {}", file.to_str());
debug2!("inspecting file {}", file.display());
if is_test(config, &file) {
let t = do make_test(config, &file) {
match config.mode {
Expand All @@ -272,7 +272,7 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
_ => ~[~".rc", ~".rs"]
};
let invalid_prefixes = ~[~".", ~"#", ~"~"];
let name = testfile.filename().unwrap();
let name = testfile.filename_str().unwrap();

let mut valid = false;

Expand Down Expand Up @@ -303,9 +303,9 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {

// Try to elide redundant long paths
fn shorten(path: &Path) -> ~str {
let filename = path.filename();
let p = path.pop();
let dir = p.filename();
let filename = path.filename_str();
let p = path.dir_path();
let dir = p.filename_str();
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}

Expand All @@ -317,13 +317,15 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
use std::cell::Cell;
let config = Cell::new((*config).clone());
let testfile = Cell::new(testfile.to_str());
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
}

pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
use std::cell::Cell;
let config = Cell::new((*config).clone());
let testfile = Cell::new(testfile.to_str());
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) })
}
4 changes: 2 additions & 2 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ 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") {
Some(s) => Some(Path(s)),
Some(s) => Some(Path::new(s)),
None => {
if parse_name_directive(line, "pp-exact") {
Some(testfile.file_path())
testfile.filename().map(|s| Path::new(s))
} else {
None
}
Expand Down
Loading

0 comments on commit 40180cd

Please sign in to comment.