Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start using core::path2::Path in a lot of places.

  • Loading branch information...
commit c284b8b1dc348ab8b9c82350dd1b4e53fac1225c 1 parent a8f1bee
@graydon graydon authored
Showing with 1,135 additions and 1,111 deletions.
  1. +242 −235 src/cargo/cargo.rs
  2. +17 −12 src/cargo/pgp.rs
  3. +5 −5 src/compiletest/common.rs
  4. +28 −20 src/compiletest/compiletest.rs
  5. +1 −1  src/compiletest/errors.rs
  6. +7 −7 src/compiletest/header.rs
  7. +69 −63 src/compiletest/runtest.rs
  8. +55 −48 src/fuzzer/fuzzer.rs
  9. +1 −1  src/libcore/core.rc
  10. +8 −2 src/libcore/core.rs
  11. +24 −21 src/libcore/io.rs
  12. +120 −128 src/libcore/os.rs
  13. +165 −129 src/libcore/path2.rs
  14. +8 −7 src/libstd/tempfile.rs
  15. +1 −1  src/libstd/test.rs
  16. +8 −9 src/libsyntax/ext/source_util.rs
  17. +13 −12 src/libsyntax/parse.rs
  18. +27 −28 src/libsyntax/parse/eval.rs
  19. +51 −78 src/rustc/back/link.rs
  20. +119 −136 src/rustc/back/rpath.rs
  21. +31 −34 src/rustc/driver/driver.rs
  22. +5 −3 src/rustc/driver/rustc.rs
  23. +3 −3 src/rustc/driver/session.rs
  24. +2 −2 src/rustc/metadata/creader.rs
  25. +5 −5 src/rustc/metadata/cstore.rs
  26. +40 −43 src/rustc/metadata/filesearch.rs
  27. +17 −15 src/rustc/metadata/loader.rs
  28. +1 −1  src/rustc/middle/trans/base.rs
  29. +7 −6 src/rustc/middle/trans/debuginfo.rs
  30. +3 −0  src/rustc/util/ppaux.rs
  31. +1 −1  src/rustdoc/astsrv.rs
  32. +14 −13 src/rustdoc/config.rs
  33. +2 −2 src/rustdoc/markdown_index_pass.rs
  34. +1 −1  src/rustdoc/markdown_pass.rs
  35. +16 −16 src/rustdoc/markdown_writer.rs
  36. +3 −3 src/rustdoc/parse.rs
  37. +2 −2 src/rustdoc/rustdoc.rs
  38. +3 −5 src/test/bench/core-std.rs
  39. +2 −1  src/test/bench/shootout-fasta.rs
  40. +3 −5 src/test/bench/shootout-k-nucleotide-pipes.rs
  41. +3 −5 src/test/bench/shootout-k-nucleotide.rs
  42. +1 −1  src/test/bench/shootout-mandelbrot.rs
  43. +1 −1  src/test/bench/task-perf-word-count-generic.rs
View
477 src/cargo/cargo.rs
@@ -43,12 +43,12 @@ type source = @{
type cargo = {
pgp: bool,
- root: ~str,
- installdir: ~str,
- bindir: ~str,
- libdir: ~str,
- workdir: ~str,
- sourcedir: ~str,
+ root: Path,
+ installdir: Path,
+ bindir: Path,
+ libdir: Path,
+ workdir: Path,
+ sourcedir: Path,
sources: map::hashmap<~str, source>,
mut current_install: ~str,
dep_cache: map::hashmap<~str, bool>,
@@ -185,7 +185,7 @@ fn has_archive_extension(p: ~str) -> bool {
}
fn is_archive_path(u: ~str) -> bool {
- has_archive_extension(u) && os::path_exists(u)
+ has_archive_extension(u) && os::path_exists(&Path(u))
}
fn is_archive_url(u: ~str) -> bool {
@@ -209,7 +209,7 @@ fn assume_source_method(url: ~str) -> ~str {
if is_git_url(url) {
return ~"git";
}
- if str::starts_with(url, ~"file://") || os::path_exists(url) {
+ if str::starts_with(url, ~"file://") || os::path_exists(&Path(url)) {
return ~"file";
}
@@ -238,7 +238,7 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>,
(name, vers, uuid)
}
-fn load_crate(filename: ~str) -> option<crate> {
+fn load_crate(filename: &Path) -> option<crate> {
let sess = parse::new_parse_sess(none);
let c = parse::parse_crate_from_crate_file(filename, ~[], sess);
@@ -368,10 +368,10 @@ fn rest(s: ~str, start: uint) -> ~str {
}
}
-fn need_dir(s: ~str) {
+fn need_dir(s: &Path) {
if os::path_is_dir(s) { return; }
if !os::make_dir(s, 493_i32 /* oct: 755 */) {
- fail fmt!("can't make_dir %s", s);
+ fail fmt!("can't make_dir %s", s.to_str());
}
}
@@ -411,7 +411,7 @@ fn parse_source(name: ~str, j: json::json) -> source {
_ => none
};
if method == ~"file" {
- url = os::make_absolute(url);
+ url = os::make_absolute(&Path(url)).to_str();
}
return @{
name: name,
@@ -425,7 +425,7 @@ fn parse_source(name: ~str, j: json::json) -> source {
};
}
-fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
+fn try_parse_sources(filename: &Path, sources: map::hashmap<~str, source>) {
if !os::path_exists(filename) { return; }
let c = io::read_whole_file_str(filename);
match json::from_str(result::get(c)) {
@@ -436,7 +436,7 @@ fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
}
}
ok(_) => fail ~"malformed sources.json",
- err(e) => fail fmt!("%s:%s", filename, e.to_str())
+ err(e) => fail fmt!("%s:%s", filename.to_str(), e.to_str())
}
}
@@ -543,10 +543,10 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
}
fn load_source_info(c: cargo, src: source) {
- let dir = path::connect(c.sourcedir, src.name);
- let srcfile = path::connect(dir, ~"source.json");
- if !os::path_exists(srcfile) { return; }
- let srcstr = io::read_whole_file_str(srcfile);
+ let dir = c.sourcedir.push(src.name);
+ let srcfile = dir.push("source.json");
+ if !os::path_exists(&srcfile) { return; }
+ let srcstr = io::read_whole_file_str(&srcfile);
match json::from_str(result::get(srcstr)) {
ok(json::dict(s)) => {
let o = parse_source(src.name, json::dict(s));
@@ -565,10 +565,10 @@ fn load_source_info(c: cargo, src: source) {
}
fn load_source_packages(c: cargo, src: source) {
log(debug, ~"loading source: " + src.name);
- let dir = path::connect(c.sourcedir, src.name);
- let pkgfile = path::connect(dir, ~"packages.json");
- if !os::path_exists(pkgfile) { return; }
- let pkgstr = io::read_whole_file_str(pkgfile);
+ let dir = c.sourcedir.push(src.name);
+ let pkgfile = dir.push("packages.json");
+ if !os::path_exists(&pkgfile) { return; }
+ let pkgstr = io::read_whole_file_str(&pkgfile);
match json::from_str(result::get(pkgstr)) {
ok(json::list(js)) => {
for (*js).each |j| {
@@ -639,8 +639,8 @@ fn configure(opts: options) -> cargo {
let p = result::get(get_cargo_dir());
let sources = map::str_hash();
- try_parse_sources(path::connect(home, ~"sources.json"), sources);
- try_parse_sources(path::connect(home, ~"local-sources.json"), sources);
+ try_parse_sources(&home.push("sources.json"), sources);
+ try_parse_sources(&home.push("local-sources.json"), sources);
let dep_cache = map::str_hash();
@@ -648,22 +648,22 @@ fn configure(opts: options) -> cargo {
pgp: pgp::supported(),
root: home,
installdir: p,
- bindir: path::connect(p, ~"bin"),
- libdir: path::connect(p, ~"lib"),
- workdir: path::connect(p, ~"work"),
- sourcedir: path::connect(home, ~"sources"),
+ bindir: p.push("bin"),
+ libdir: p.push("lib"),
+ workdir: p.push("work"),
+ sourcedir: home.push("sources"),
sources: sources,
mut current_install: ~"",
dep_cache: dep_cache,
opts: opts
};
- need_dir(c.root);
- need_dir(c.installdir);
- need_dir(c.sourcedir);
- need_dir(c.workdir);
- need_dir(c.libdir);
- need_dir(c.bindir);
+ need_dir(&c.root);
+ need_dir(&c.installdir);
+ need_dir(&c.sourcedir);
+ need_dir(&c.workdir);
+ need_dir(&c.libdir);
+ need_dir(&c.bindir);
for sources.each_key |k| {
let mut s = sources.get(k);
@@ -672,7 +672,7 @@ fn configure(opts: options) -> cargo {
}
if c.pgp {
- pgp::init(c.root);
+ pgp::init(&c.root);
} else {
warn(~"command `gpg` was not found");
warn(~"you have to install gpg from source " +
@@ -694,22 +694,24 @@ fn for_each_package(c: cargo, b: fn(source, package)) {
}
// Runs all programs in directory <buildpath>
-fn run_programs(buildpath: ~str) {
+fn run_programs(buildpath: &Path) {
let newv = os::list_dir_path(buildpath);
for newv.each |ct| {
- run::run_program(ct, ~[]);
+ run::run_program(ct.to_str(), ~[]);
}
}
// Runs rustc in <path + subdir> with the given flags
-// and returns <path + subdir>
-fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
- extra_flags: ~[~str]) -> option<~str> {
- let buildpath = path::connect(path, subdir);
- need_dir(buildpath);
- debug!("%s: %s -> %s", what, cf, buildpath);
+// and returns <patho + subdir>
+fn run_in_buildpath(what: &str, path: &Path, subdir: &Path, cf: &Path,
+ extra_flags: ~[~str]) -> option<Path> {
+ let buildpath = path.push_rel(subdir);
+ need_dir(&buildpath);
+ debug!("%s: %s -> %s", what, cf.to_str(), buildpath.to_str());
let p = run::program_output(rustc_sysroot(),
- ~[~"--out-dir", buildpath, cf] + extra_flags);
+ ~[~"--out-dir",
+ buildpath.to_str(),
+ cf.to_str()] + extra_flags);
if p.status != 0 {
error(fmt!("rustc failed: %d\n%s\n%s", p.status, p.err, p.out));
return none;
@@ -717,37 +719,42 @@ fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
some(buildpath)
}
-fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
- let buildpath = match run_in_buildpath(~"testing", path, ~"/test", cf,
- ~[ ~"--test"]) {
+fn test_one_crate(_c: cargo, path: &Path, cf: &Path) {
+ let buildpath = match run_in_buildpath(~"testing", path,
+ &Path("test"),
+ cf,
+ ~[ ~"--test"]) {
none => return,
- some(bp) => bp
+ some(bp) => bp
};
- run_programs(buildpath);
+ run_programs(&buildpath);
}
-fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
+fn install_one_crate(c: cargo, path: &Path, cf: &Path) {
let buildpath = match run_in_buildpath(~"installing", path,
- ~"/build", cf, ~[]) {
+ &Path("build"),
+ cf, ~[]) {
none => return,
some(bp) => bp
};
- let newv = os::list_dir_path(buildpath);
+ let newv = os::list_dir_path(&buildpath);
let exec_suffix = os::exe_suffix();
for newv.each |ct| {
- if (exec_suffix != ~"" && str::ends_with(ct, exec_suffix)) ||
- (exec_suffix == ~"" && !str::starts_with(path::basename(ct),
- ~"lib")) {
- debug!(" bin: %s", ct);
- install_to_dir(ct, c.bindir);
+ if (exec_suffix != ~"" && str::ends_with(ct.to_str(),
+ exec_suffix)) ||
+ (exec_suffix == ~"" &&
+ !str::starts_with(option::get(ct.filename()),
+ ~"lib")) {
+ debug!(" bin: %s", ct.to_str());
+ install_to_dir(ct, &c.bindir);
if c.opts.mode == system_mode {
// FIXME (#2662): Put this file in PATH / symlink it so it can
// be used as a generic executable
// `cargo install -G rustray` and `rustray file.obj`
}
} else {
- debug!(" lib: %s", ct);
- install_to_dir(ct, c.libdir);
+ debug!(" lib: %s", ct.to_str());
+ install_to_dir(ct, &c.libdir);
}
}
}
@@ -756,23 +763,22 @@ fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
fn rustc_sysroot() -> ~str {
match os::self_exe_path() {
some(path) => {
- let path = ~[path, ~"..", ~"bin", ~"rustc"];
- let rustc = path::normalize(path::connect_many(path));
- debug!(" rustc: %s", rustc);
- rustc
+ let rustc = path.push_many([~"..", ~"bin", ~"rustc"]);
+ debug!(" rustc: %s", rustc.to_str());
+ rustc.to_str()
}
none => ~"rustc"
}
}
-fn install_source(c: cargo, path: ~str) {
- debug!("source: %s", path);
+fn install_source(c: cargo, path: &Path) {
+ debug!("source: %s", path.to_str());
os::change_dir(path);
let mut cratefiles = ~[];
- for os::walk_dir(~".") |p| {
- if str::ends_with(p, ~".rc") {
- vec::push(cratefiles, p);
+ for os::walk_dir(&Path(".")) |p| {
+ if p.filetype() == some(~"rc") {
+ vec::push(cratefiles, *p);
}
}
@@ -781,7 +787,7 @@ fn install_source(c: cargo, path: ~str) {
}
for cratefiles.each |cf| {
- match load_crate(cf) {
+ match load_crate(&cf) {
none => again,
some(crate) => {
for crate.deps.each |query| {
@@ -789,28 +795,23 @@ fn install_source(c: cargo, path: ~str) {
// (n.b. #1356 says "Cyclic dependency is an error
// condition")
- let wd_base = c.workdir + path::path_sep();
- let wd = match tempfile::mkdtemp(wd_base, ~"") {
- some(wd) => wd,
- none => fail fmt!("needed temp dir: %s", wd_base)
- };
-
- install_query(c, wd, query);
+ let wd = get_temp_workdir(c);
+ install_query(c, &wd, query);
}
os::change_dir(path);
if c.opts.test {
- test_one_crate(c, path, cf);
+ test_one_crate(c, path, &cf);
}
- install_one_crate(c, path, cf);
+ install_one_crate(c, path, &cf);
}
}
}
}
-fn install_git(c: cargo, wd: ~str, url: ~str, reference: option<~str>) {
- run::program_output(~"git", ~[~"clone", url, wd]);
+fn install_git(c: cargo, wd: &Path, url: ~str, reference: option<~str>) {
+ run::program_output(~"git", ~[~"clone", url, wd.to_str()]);
if option::is_some(reference) {
let r = option::get(reference);
os::change_dir(wd);
@@ -820,25 +821,27 @@ fn install_git(c: cargo, wd: ~str, url: ~str, reference: option<~str>) {
install_source(c, wd);
}
-fn install_curl(c: cargo, wd: ~str, url: ~str) {
- let tarpath = path::connect(wd, ~"pkg.tar");
+fn install_curl(c: cargo, wd: &Path, url: ~str) {
+ let tarpath = wd.push("pkg.tar");
let p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o",
- tarpath, url]);
+ tarpath.to_str(), url]);
if p.status != 0 {
fail fmt!("fetch of %s failed: %s", url, p.err);
}
run::run_program(~"tar", ~[~"-x", ~"--strip-components=1",
- ~"-C", wd, ~"-f", tarpath]);
+ ~"-C", wd.to_str(),
+ ~"-f", tarpath.to_str()]);
install_source(c, wd);
}
-fn install_file(c: cargo, wd: ~str, path: ~str) {
+fn install_file(c: cargo, wd: &Path, path: &Path) {
run::program_output(~"tar", ~[~"-x", ~"--strip-components=1",
- ~"-C", wd, ~"-f", path]);
+ ~"-C", wd.to_str(),
+ ~"-f", path.to_str()]);
install_source(c, wd);
}
-fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
+fn install_package(c: cargo, src: ~str, wd: &Path, pkg: package) {
let url = copy pkg.url;
let method = match pkg.method {
~"git" => ~"git",
@@ -850,7 +853,7 @@ fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
match method {
~"git" => install_git(c, wd, url, copy pkg.reference),
- ~"file" => install_file(c, wd, url),
+ ~"file" => install_file(c, wd, &Path(url)),
~"curl" => install_curl(c, wd, copy url),
_ => ()
}
@@ -866,7 +869,7 @@ fn cargo_suggestion(c: cargo, fallback: fn())
fallback();
}
-fn install_uuid(c: cargo, wd: ~str, uuid: ~str) {
+fn install_uuid(c: cargo, wd: &Path, uuid: ~str) {
let mut ps = ~[];
for_each_package(c, |s, p| {
if p.uuid == uuid {
@@ -890,7 +893,7 @@ fn install_uuid(c: cargo, wd: ~str, uuid: ~str) {
}
}
-fn install_named(c: cargo, wd: ~str, name: ~str) {
+fn install_named(c: cargo, wd: &Path, name: ~str) {
let mut ps = ~[];
for_each_package(c, |s, p| {
if p.name == name {
@@ -914,7 +917,7 @@ fn install_named(c: cargo, wd: ~str, name: ~str) {
}
}
-fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
+fn install_uuid_specific(c: cargo, wd: &Path, src: ~str, uuid: ~str) {
match c.sources.find(src) {
some(s) => {
let packages = copy s.packages;
@@ -930,7 +933,7 @@ fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
error(~"can't find package: " + src + ~"/" + uuid);
}
-fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
+fn install_named_specific(c: cargo, wd: &Path, src: ~str, name: ~str) {
match c.sources.find(src) {
some(s) => {
let packages = copy s.packages;
@@ -952,59 +955,45 @@ fn cmd_uninstall(c: cargo) {
return;
}
- let lib = c.libdir;
- let bin = c.bindir;
+ let lib = &c.libdir;
+ let bin = &c.bindir;
let target = c.opts.free[2u];
// FIXME (#2662): needs stronger pattern matching
// FIXME (#2662): needs to uninstall from a specified location in a
// cache instead of looking for it (binaries can be uninstalled by
// name only)
+
+ fn try_uninstall(p: &Path) -> bool {
+ if os::remove_file(p) {
+ info(~"uninstalled: '" + p.to_str() + ~"'");
+ true
+ } else {
+ error(~"could not uninstall: '" +
+ p.to_str() + ~"'");
+ false
+ }
+ }
+
if is_uuid(target) {
for os::list_dir(lib).each |file| {
match str::find_str(file, ~"-" + target + ~"-") {
- some(idx) => {
- let full = path::normalize(path::connect(lib, file));
- if os::remove_file(full) {
- info(~"uninstalled: '" + full + ~"'");
- } else {
- error(~"could not uninstall: '" + full + ~"'");
- }
- return;
- }
- none => again
+ some(_) => if !try_uninstall(&lib.push(file)) { return },
+ none => ()
}
}
-
error(~"can't find package with uuid: " + target);
} else {
for os::list_dir(lib).each |file| {
match str::find_str(file, ~"lib" + target + ~"-") {
- some(idx) => {
- let full = path::normalize(path::connect(lib,
- file));
- if os::remove_file(full) {
- info(~"uninstalled: '" + full + ~"'");
- } else {
- error(~"could not uninstall: '" + full + ~"'");
- }
- return;
- }
- none => again
+ some(_) => if !try_uninstall(&lib.push(file)) { return },
+ none => ()
}
}
for os::list_dir(bin).each |file| {
match str::find_str(file, target) {
- some(idx) => {
- let full = path::normalize(path::connect(bin, file));
- if os::remove_file(full) {
- info(~"uninstalled: '" + full + ~"'");
- } else {
- error(~"could not uninstall: '" + full + ~"'");
- }
- return;
- }
- none => again
+ some(_) => if !try_uninstall(&lib.push(file)) { return },
+ none => ()
}
}
@@ -1012,7 +1001,7 @@ fn cmd_uninstall(c: cargo) {
}
}
-fn install_query(c: cargo, wd: ~str, target: ~str) {
+fn install_query(c: cargo, wd: &Path, target: ~str) {
match c.dep_cache.find(target) {
some(inst) => {
if inst {
@@ -1025,7 +1014,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
c.dep_cache.insert(target, true);
if is_archive_path(target) {
- install_file(c, wd, target);
+ install_file(c, wd, &Path(target));
return;
} else if is_git_url(target) {
let reference = if c.opts.free.len() >= 4u {
@@ -1072,31 +1061,36 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
}
}
+fn get_temp_workdir(c: cargo) -> Path {
+ match tempfile::mkdtemp(&c.workdir, "cargo") {
+ some(wd) => wd,
+ none => fail fmt!("needed temp dir: %s",
+ c.workdir.to_str())
+ }
+}
+
fn cmd_install(c: cargo) unsafe {
- let wd_base = c.workdir + path::path_sep();
- let wd = match tempfile::mkdtemp(wd_base, ~"") {
- some(wd) => wd,
- none => fail fmt!("needed temp dir: %s", wd_base)
- };
+ let wd = get_temp_workdir(c);
if vec::len(c.opts.free) == 2u {
let cwd = os::getcwd();
- let status = run::run_program(~"cp", ~[~"-R", cwd, wd]);
+ let status = run::run_program(~"cp", ~[~"-R", cwd.to_str(),
+ wd.to_str()]);
if status != 0 {
- fail fmt!("could not copy directory: %s", cwd);
+ fail fmt!("could not copy directory: %s", cwd.to_str());
}
- install_source(c, wd);
+ install_source(c, &wd);
return;
}
sync(c);
let query = c.opts.free[2];
- c.current_install = copy query;
+ c.current_install = query.to_str();
- install_query(c, wd, copy query);
+ install_query(c, &wd, query);
}
fn sync(c: cargo) {
@@ -1107,45 +1101,47 @@ fn sync(c: cargo) {
}
}
-fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
+fn sync_one_file(c: cargo, dir: &Path, src: source) -> bool {
let name = src.name;
- let srcfile = path::connect(dir, ~"source.json.new");
- let destsrcfile = path::connect(dir, ~"source.json");
- let pkgfile = path::connect(dir, ~"packages.json.new");
- let destpkgfile = path::connect(dir, ~"packages.json");
- let keyfile = path::connect(dir, ~"key.gpg");
- let srcsigfile = path::connect(dir, ~"source.json.sig");
- let sigfile = path::connect(dir, ~"packages.json.sig");
- let url = src.url;
+ let srcfile = dir.push("source.json.new");
+ let destsrcfile = dir.push("source.json");
+ let pkgfile = dir.push("packages.json.new");
+ let destpkgfile = dir.push("packages.json");
+ let keyfile = dir.push("key.gpg");
+ let srcsigfile = dir.push("source.json.sig");
+ let sigfile = dir.push("packages.json.sig");
+ let url = Path(src.url);
let mut has_src_file = false;
- if !os::copy_file(path::connect(url, ~"packages.json"), pkgfile) {
- error(fmt!("fetch for source %s (url %s) failed", name, url));
+ if !os::copy_file(&url.push("packages.json"), &pkgfile) {
+ error(fmt!("fetch for source %s (url %s) failed",
+ name, url.to_str()));
return false;
}
- if os::copy_file(path::connect(url, ~"source.json"), srcfile) {
+ if os::copy_file(&url.push("source.json"), &srcfile) {
has_src_file = false;
}
- os::copy_file(path::connect(url, ~"source.json.sig"), srcsigfile);
- os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile);
+ os::copy_file(&url.push("source.json.sig"), &srcsigfile);
+ os::copy_file(&url.push("packages.json.sig"), &sigfile);
match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
- ~[~"-f", ~"-s", ~"-o", keyfile, u]);
+ ~[~"-f", ~"-s",
+ ~"-o", keyfile.to_str(), u]);
if p.status != 0 {
error(fmt!("fetch for source %s (key %s) failed", name, u));
return false;
}
- pgp::add(c.root, keyfile);
+ pgp::add(&c.root, &keyfile);
}
_ => ()
}
match (src.key, src.keyfp) {
(some(_), some(f)) => {
- let r = pgp::verify(c.root, pkgfile, sigfile, f);
+ let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
if !r {
error(fmt!("signature verification failed for source %s",
@@ -1154,7 +1150,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
}
if has_src_file {
- let e = pgp::verify(c.root, srcfile, srcsigfile, f);
+ let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
if !e {
error(fmt!("signature verification failed for source %s",
@@ -1166,33 +1162,33 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
_ => ()
}
- copy_warn(pkgfile, destpkgfile);
+ copy_warn(&pkgfile, &destpkgfile);
if has_src_file {
- copy_warn(srcfile, destsrcfile);
+ copy_warn(&srcfile, &destsrcfile);
}
- os::remove_file(keyfile);
- os::remove_file(srcfile);
- os::remove_file(srcsigfile);
- os::remove_file(pkgfile);
- os::remove_file(sigfile);
+ os::remove_file(&keyfile);
+ os::remove_file(&srcfile);
+ os::remove_file(&srcsigfile);
+ os::remove_file(&pkgfile);
+ os::remove_file(&sigfile);
info(fmt!("synced source: %s", name));
return true;
}
-fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
+fn sync_one_git(c: cargo, dir: &Path, src: source) -> bool {
let name = src.name;
- let srcfile = path::connect(dir, ~"source.json");
- let pkgfile = path::connect(dir, ~"packages.json");
- let keyfile = path::connect(dir, ~"key.gpg");
- let srcsigfile = path::connect(dir, ~"source.json.sig");
- let sigfile = path::connect(dir, ~"packages.json.sig");
+ let srcfile = dir.push("source.json");
+ let pkgfile = dir.push("packages.json");
+ let keyfile = dir.push("key.gpg");
+ let srcsigfile = dir.push("source.json.sig");
+ let sigfile = dir.push("packages.json.sig");
let url = src.url;
- fn rollback(name: ~str, dir: ~str, insecure: bool) {
+ fn rollback(name: ~str, dir: &Path, insecure: bool) {
fn msg(name: ~str, insecure: bool) {
error(fmt!("could not rollback source: %s", name));
@@ -1216,8 +1212,8 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
}
}
- if !os::path_exists(path::connect(dir, ~".git")) {
- let p = run::program_output(~"git", ~[~"clone", url, dir]);
+ if !os::path_exists(&dir.push(".git")) {
+ let p = run::program_output(~"git", ~[~"clone", url, dir.to_str()]);
if p.status != 0 {
error(fmt!("fetch for source %s (url %s) failed", name, url));
@@ -1238,24 +1234,25 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
}
}
- let has_src_file = os::path_exists(srcfile);
+ let has_src_file = os::path_exists(&srcfile);
match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
- ~[~"-f", ~"-s", ~"-o", keyfile, u]);
+ ~[~"-f", ~"-s",
+ ~"-o", keyfile.to_str(), u]);
if p.status != 0 {
error(fmt!("fetch for source %s (key %s) failed", name, u));
rollback(name, dir, false);
return false;
}
- pgp::add(c.root, keyfile);
+ pgp::add(&c.root, &keyfile);
}
_ => ()
}
match (src.key, src.keyfp) {
(some(_), some(f)) => {
- let r = pgp::verify(c.root, pkgfile, sigfile, f);
+ let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
if !r {
error(fmt!("signature verification failed for source %s",
@@ -1265,7 +1262,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
}
if has_src_file {
- let e = pgp::verify(c.root, srcfile, srcsigfile, f);
+ let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
if !e {
error(fmt!("signature verification failed for source %s",
@@ -1278,22 +1275,22 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
_ => ()
}
- os::remove_file(keyfile);
+ os::remove_file(&keyfile);
info(fmt!("synced source: %s", name));
return true;
}
-fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
+fn sync_one_curl(c: cargo, dir: &Path, src: source) -> bool {
let name = src.name;
- let srcfile = path::connect(dir, ~"source.json.new");
- let destsrcfile = path::connect(dir, ~"source.json");
- let pkgfile = path::connect(dir, ~"packages.json.new");
- let destpkgfile = path::connect(dir, ~"packages.json");
- let keyfile = path::connect(dir, ~"key.gpg");
- let srcsigfile = path::connect(dir, ~"source.json.sig");
- let sigfile = path::connect(dir, ~"packages.json.sig");
+ let srcfile = dir.push("source.json.new");
+ let destsrcfile = dir.push("source.json");
+ let pkgfile = dir.push("packages.json.new");
+ let destpkgfile = dir.push("packages.json");
+ let keyfile = dir.push("key.gpg");
+ let srcsigfile = dir.push("source.json.sig");
+ let sigfile = dir.push("packages.json.sig");
let mut url = src.url;
let smart = !str::ends_with(src.url, ~"packages.json");
let mut has_src_file = false;
@@ -1303,7 +1300,8 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
}
let p = run::program_output(~"curl",
- ~[~"-f", ~"-s", ~"-o", pkgfile, url]);
+ ~[~"-f", ~"-s",
+ ~"-o", pkgfile.to_str(), url]);
if p.status != 0 {
error(fmt!("fetch for source %s (url %s) failed", name, url));
@@ -1313,7 +1311,8 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
url = src.url + ~"/source.json";
let p =
run::program_output(~"curl",
- ~[~"-f", ~"-s", ~"-o", srcfile, url]);
+ ~[~"-f", ~"-s",
+ ~"-o", srcfile.to_str(), url]);
if p.status == 0 {
has_src_file = true;
@@ -1323,12 +1322,13 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
- ~[~"-f", ~"-s", ~"-o", keyfile, u]);
+ ~[~"-f", ~"-s",
+ ~"-o", keyfile.to_str(), u]);
if p.status != 0 {
error(fmt!("fetch for source %s (key %s) failed", name, u));
return false;
}
- pgp::add(c.root, keyfile);
+ pgp::add(&c.root, &keyfile);
}
_ => ()
}
@@ -1341,14 +1341,15 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
url = src.url + ~".sig";
}
- let mut p = run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o",
- sigfile, url]);
+ let mut p = run::program_output(~"curl",
+ ~[~"-f", ~"-s", ~"-o",
+ sigfile.to_str(), url]);
if p.status != 0 {
error(fmt!("fetch for source %s (sig %s) failed", name, url));
return false;
}
- let r = pgp::verify(c.root, pkgfile, sigfile, f);
+ let r = pgp::verify(&c.root, &pkgfile, &sigfile, f);
if !r {
error(fmt!("signature verification failed for source %s",
@@ -1361,14 +1362,14 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o",
- srcsigfile, url]);
+ srcsigfile.to_str(), url]);
if p.status != 0 {
error(fmt!("fetch for source %s (sig %s) failed",
name, url));
return false;
}
- let e = pgp::verify(c.root, srcfile, srcsigfile, f);
+ let e = pgp::verify(&c.root, &srcfile, &srcsigfile, f);
if !e {
error(~"signature verification failed for " +
@@ -1380,17 +1381,17 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
_ => ()
}
- copy_warn(pkgfile, destpkgfile);
+ copy_warn(&pkgfile, &destpkgfile);
if smart && has_src_file {
- copy_warn(srcfile, destsrcfile);
+ copy_warn(&srcfile, &destsrcfile);
}
- os::remove_file(keyfile);
- os::remove_file(srcfile);
- os::remove_file(srcsigfile);
- os::remove_file(pkgfile);
- os::remove_file(sigfile);
+ os::remove_file(&keyfile);
+ os::remove_file(&srcfile);
+ os::remove_file(&srcsigfile);
+ os::remove_file(&pkgfile);
+ os::remove_file(&sigfile);
info(fmt!("synced source: %s", name));
@@ -1399,16 +1400,16 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
fn sync_one(c: cargo, src: source) {
let name = src.name;
- let dir = path::connect(c.sourcedir, name);
+ let dir = c.sourcedir.push(name);
info(fmt!("syncing source: %s...", name));
- need_dir(dir);
+ need_dir(&dir);
let result = match src.method {
- ~"git" => sync_one_git(c, dir, src),
- ~"file" => sync_one_file(c, dir, src),
- _ => sync_one_curl(c, dir, src)
+ ~"git" => sync_one_git(c, &dir, src),
+ ~"file" => sync_one_file(c, &dir, src),
+ _ => sync_one_curl(c, &dir, src)
};
if result {
@@ -1421,35 +1422,39 @@ fn cmd_init(c: cargo) {
let srcurl = ~"http://www.rust-lang.org/cargo/sources.json";
let sigurl = ~"http://www.rust-lang.org/cargo/sources.json.sig";
- let srcfile = path::connect(c.root, ~"sources.json.new");
- let sigfile = path::connect(c.root, ~"sources.json.sig");
- let destsrcfile = path::connect(c.root, ~"sources.json");
+ let srcfile = c.root.push("sources.json.new");
+ let sigfile = c.root.push("sources.json.sig");
+ let destsrcfile = c.root.push("sources.json");
let p =
- run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", srcfile, srcurl]);
+ run::program_output(~"curl", ~[~"-f", ~"-s",
+ ~"-o", srcfile.to_str(), srcurl]);
if p.status != 0 {
error(fmt!("fetch of sources.json failed: %s", p.out));
return;
}
let p =
- run::program_output(~"curl", ~[~"-f", ~"-s", ~"-o", sigfile, sigurl]);
+ run::program_output(~"curl", ~[~"-f", ~"-s",
+ ~"-o", sigfile.to_str(), sigurl]);
if p.status != 0 {
error(fmt!("fetch of sources.json.sig failed: %s", p.out));
return;
}
- let r = pgp::verify(c.root, srcfile, sigfile, pgp::signing_key_fp());
+ let r = pgp::verify(&c.root, &srcfile, &sigfile,
+ pgp::signing_key_fp());
if !r {
- error(fmt!("signature verification failed for '%s'", srcfile));
+ error(fmt!("signature verification failed for '%s'",
+ srcfile.to_str()));
return;
}
- copy_warn(srcfile, destsrcfile);
- os::remove_file(srcfile);
- os::remove_file(sigfile);
+ copy_warn(&srcfile, &destsrcfile);
+ os::remove_file(&srcfile);
+ os::remove_file(&sigfile);
- info(fmt!("initialized .cargo in %s", c.root));
+ info(fmt!("initialized .cargo in %s", c.root.to_str()));
}
fn print_pkg(s: source, p: package) {
@@ -1530,25 +1535,26 @@ fn cmd_search(c: cargo) {
info(fmt!("found %d packages", n));
}
-fn install_to_dir(srcfile: ~str, destdir: ~str) {
- let newfile = path::connect(destdir, path::basename(srcfile));
+fn install_to_dir(srcfile: &Path, destdir: &Path) {
+ let newfile = destdir.push(option::get(srcfile.filename()));
- let status = run::run_program(~"cp", ~[~"-r", srcfile, newfile]);
+ let status = run::run_program(~"cp", ~[~"-r", srcfile.to_str(),
+ newfile.to_str()]);
if status == 0 {
- info(fmt!("installed: '%s'", newfile));
+ info(fmt!("installed: '%s'", newfile.to_str()));
} else {
- error(fmt!("could not install: '%s'", newfile));
+ error(fmt!("could not install: '%s'", newfile.to_str()));
}
}
fn dump_cache(c: cargo) {
- need_dir(c.root);
+ need_dir(&c.root);
- let out = path::connect(c.root, ~"cache.json");
+ let out = c.root.push("cache.json");
let _root = json::dict(map::str_hash());
- if os::path_exists(out) {
- copy_warn(out, path::connect(c.root, ~"cache.json.old"));
+ if os::path_exists(&out) {
+ copy_warn(&out, &c.root.push("cache.json.old"));
}
}
fn dump_sources(c: cargo) {
@@ -1556,15 +1562,15 @@ fn dump_sources(c: cargo) {
return;
}
- need_dir(c.root);
+ need_dir(&c.root);
- let out = path::connect(c.root, ~"sources.json");
+ let out = c.root.push("sources.json");
- if os::path_exists(out) {
- copy_warn(out, path::connect(c.root, ~"sources.json.old"));
+ if os::path_exists(&out) {
+ copy_warn(&out, &c.root.push("sources.json.old"));
}
- match io::buffered_file_writer(out) {
+ match io::buffered_file_writer(&out) {
result::ok(writer) => {
let hash = map::str_hash();
let root = json::dict(hash);
@@ -1600,9 +1606,10 @@ fn dump_sources(c: cargo) {
}
}
-fn copy_warn(srcfile: ~str, destfile: ~str) {
+fn copy_warn(srcfile: &Path, destfile: &Path) {
if !os::copy_file(srcfile, destfile) {
- warn(fmt!("copying %s to %s failed", srcfile, destfile));
+ warn(fmt!("copying %s to %s failed",
+ srcfile.to_str(), destfile.to_str()));
}
}
@@ -1894,7 +1901,7 @@ fn main(argv: ~[~str]) {
let mut c = configure(o);
let home = c.root;
- let first_time = os::path_exists(path::connect(home, ~"sources.json"));
+ let first_time = os::path_exists(&home.push("sources.json"));
if !first_time && o.free[1] != ~"init" {
cmd_init(c);
View
29 src/cargo/pgp.rs
@@ -63,11 +63,13 @@ fn supported() -> bool {
r.status == 0
}
-fn init(root: ~str) {
- let p = path::connect(root, ~"gpg");
- if !os::path_is_dir(p) {
- os::make_dir(p, 0x1c0i32);
- let p = run::start_program(~"gpg", ~[~"--homedir", p, ~"--import"]);
+fn init(root: &Path) {
+ let p = root.push("gpg");
+ if !os::path_is_dir(&p) {
+ os::make_dir(&p, 0x1c0i32);
+ let p = run::start_program(~"gpg", ~[~"--homedir",
+ p.to_str(),
+ ~"--import"]);
p.input().write_str(signing_key());
let s = p.finish();
if s != 0 {
@@ -76,19 +78,22 @@ fn init(root: ~str) {
}
}
-fn add(root: ~str, key: ~str) {
- let path = path::connect(root, ~"gpg");
+fn add(root: &Path, key: &Path) {
+ let path = root.push("gpg");
let p =
- run::program_output(~"gpg", ~[~"--homedir", path, ~"--import", key]);
+ run::program_output(~"gpg", ~[~"--homedir", path.to_str(),
+ ~"--import", key.to_str()]);
if p.status != 0 {
fail ~"pgp add failed: " + p.out;
}
}
-fn verify(root: ~str, data: ~str, sig: ~str, keyfp: ~str) -> bool {
- let path = path::connect(root, ~"gpg");
- let p = gpg(~[~"--homedir", path, ~"--with-fingerprint", ~"--verify", sig,
- data]);
+fn verify(root: &Path, data: &Path, sig: &Path, keyfp: ~str) -> bool {
+ let path = root.push("gpg");
+ let p = gpg(~[~"--homedir", path.to_str(),
+ ~"--with-fingerprint",
+ ~"--verify", sig.to_str(),
+ data.to_str()]);
let res = ~"Primary key fingerprint: " + keyfp;
for str::split_char(p.err, '\n').each |line| {
if line == res { return true; }
View
10 src/compiletest/common.rs
@@ -10,16 +10,16 @@ type config = {
run_lib_path: ~str,
// The rustc executable
- rustc_path: ~str,
+ rustc_path: Path,
// The directory containing the tests to run
- src_base: ~str,
+ src_base: Path,
// The directory where programs should be built
- build_base: ~str,
+ build_base: Path,
// Directory for auxiliary libraries
- aux_base: ~str,
+ aux_base: Path,
// The name of the stage being built (stage1, etc)
stage_id: ~str,
@@ -34,7 +34,7 @@ type config = {
filter: option<~str>,
// Write out a parseable log of tests that were run
- logfile: option<~str>,
+ logfile: option<Path>,
// A command line to prefix program execution with,
// for running under valgrind
View
48 src/compiletest/compiletest.rs
@@ -42,12 +42,16 @@ fn parse_config(args: ~[~str]) -> config {
err(f) => fail getopts::fail_str(f)
};
+ fn opt_path(m: getopts::matches, nm: ~str) -> Path {
+ Path(getopts::opt_str(m, nm))
+ }
+
return {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
run_lib_path: getopts::opt_str(matches, ~"run-lib-path"),
- rustc_path: getopts::opt_str(matches, ~"rustc-path"),
- src_base: getopts::opt_str(matches, ~"src-base"),
- build_base: getopts::opt_str(matches, ~"build-base"),
- aux_base: getopts::opt_str(matches, ~"aux-base"),
+ rustc_path: opt_path(matches, ~"rustc-path"),
+ src_base: opt_path(matches, ~"src-base"),
+ build_base: opt_path(matches, ~"build-base"),
+ aux_base: opt_path(matches, ~"aux-base"),
stage_id: getopts::opt_str(matches, ~"stage-id"),
mode: str_mode(getopts::opt_str(matches, ~"mode")),
run_ignored: getopts::opt_present(matches, ~"ignored"),
@@ -55,7 +59,9 @@ fn parse_config(args: ~[~str]) -> config {
if vec::len(matches.free) > 0u {
option::some(matches.free[0])
} else { option::none },
- logfile: getopts::opt_maybe_str(matches, ~"logfile"),
+ logfile: option::map(getopts::opt_maybe_str(matches,
+ ~"logfile"),
+ |s| Path(s)),
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
verbose: getopts::opt_present(matches, ~"verbose")};
@@ -66,9 +72,9 @@ fn log_config(config: config) {
logv(c, fmt!("configuration:"));
logv(c, fmt!("compile_lib_path: %s", config.compile_lib_path));
logv(c, fmt!("run_lib_path: %s", config.run_lib_path));
- logv(c, fmt!("rustc_path: %s", config.rustc_path));
- logv(c, fmt!("src_base: %s", config.src_base));
- logv(c, fmt!("build_base: %s", config.build_base));
+ logv(c, fmt!("rustc_path: %s", config.rustc_path.to_str()));
+ logv(c, fmt!("src_base: %s", config.src_base.to_str()));
+ logv(c, fmt!("build_base: %s", config.build_base.to_str()));
logv(c, fmt!("stage_id: %s", config.stage_id));
logv(c, fmt!("mode: %s", mode_str(config.mode)));
logv(c, fmt!("run_ignored: %b", config.run_ignored));
@@ -122,18 +128,19 @@ fn test_opts(config: config) -> test::test_opts {
run_ignored: config.run_ignored,
logfile:
match config.logfile {
- option::some(s) => option::some(s),
+ option::some(s) => option::some(s.to_str()),
option::none => option::none
}
}
}
fn make_tests(config: config) -> ~[test::test_desc] {
- debug!("making tests from %s", config.src_base);
+ debug!("making tests from %s",
+ config.src_base.to_str());
let mut tests = ~[];
- for os::list_dir_path(config.src_base).each |file| {
- let file = file;
- debug!("inspecting file %s", file);
+ for os::list_dir_path(&config.src_base).each |file| {
+ let file = copy file;
+ debug!("inspecting file %s", file.to_str());
if is_test(config, file) {
vec::push(tests, make_test(config, file))
}
@@ -141,7 +148,7 @@ fn make_tests(config: config) -> ~[test::test_desc] {
return tests;
}
-fn is_test(config: config, testfile: ~str) -> bool {
+fn is_test(config: config, testfile: &Path) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
match config.mode {
@@ -149,7 +156,7 @@ fn is_test(config: config, testfile: ~str) -> bool {
_ => ~[~".rc", ~".rs"]
};
let invalid_prefixes = ~[~".", ~"#", ~"~"];
- let name = path::basename(testfile);
+ let name = option::get(testfile.filename());
let mut valid = false;
@@ -164,7 +171,7 @@ fn is_test(config: config, testfile: ~str) -> bool {
return valid;
}
-fn make_test(config: config, testfile: ~str) ->
+fn make_test(config: config, testfile: &Path) ->
test::test_desc {
{
name: make_test_name(config, testfile),
@@ -174,12 +181,13 @@ fn make_test(config: config, testfile: ~str) ->
}
}
-fn make_test_name(config: config, testfile: ~str) -> ~str {
- fmt!("[%s] %s", mode_str(config.mode), testfile)
+fn make_test_name(config: config, testfile: &Path) -> ~str {
+ fmt!("[%s] %s", mode_str(config.mode), testfile.to_str())
}
-fn make_test_closure(config: config, testfile: ~str) -> test::test_fn {
- fn~() { runtest::run(config, copy testfile) }
+fn make_test_closure(config: config, testfile: &Path) -> test::test_fn {
+ let testfile = testfile.to_str();
+ fn~() { runtest::run(config, testfile) }
}
// Local Variables:
View
2  src/compiletest/errors.rs
@@ -6,7 +6,7 @@ export expected_error;
type expected_error = { line: uint, kind: ~str, msg: ~str };
// Load any test directives embedded in the file
-fn load_errors(testfile: ~str) -> ~[expected_error] {
+fn load_errors(testfile: &Path) -> ~[expected_error] {
let mut error_patterns = ~[];
let rdr = result::get(io::file_reader(testfile));
let mut line_num = 1u;
View
14 src/compiletest/header.rs
@@ -14,7 +14,7 @@ type test_props = {
compile_flags: option<~str>,
// If present, the name of a file that this test should match when
// pretty-printed
- pp_exact: option<~str>,
+ pp_exact: option<Path>,
// Modules from aux directory that should be compiled
aux_builds: ~[~str],
// Environment settings to use during execution
@@ -22,7 +22,7 @@ type test_props = {
};
// Load any test directives embedded in the file
-fn load_props(testfile: ~str) -> test_props {
+fn load_props(testfile: &Path) -> test_props {
let mut error_patterns = ~[];
let mut aux_builds = ~[];
let mut exec_env = ~[];
@@ -59,7 +59,7 @@ fn load_props(testfile: ~str) -> test_props {
};
}
-fn is_test_ignored(config: config, testfile: ~str) -> bool {
+fn is_test_ignored(config: config, testfile: &Path) -> bool {
let mut found = false;
for iter_header(testfile) |ln| {
if parse_name_directive(ln, ~"xfail-test") { return true; }
@@ -74,7 +74,7 @@ fn is_test_ignored(config: config, testfile: ~str) -> bool {
}
}
-fn iter_header(testfile: ~str, it: fn(~str) -> bool) -> bool {
+fn iter_header(testfile: &Path, it: fn(~str) -> bool) -> bool {
let rdr = result::get(io::file_reader(testfile));
while !rdr.eof() {
let ln = rdr.read_line();
@@ -114,12 +114,12 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
}
}
-fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
+fn parse_pp_exact(line: ~str, testfile: &Path) -> option<Path> {
match parse_name_value_directive(line, ~"pp-exact") {
- option::some(s) => option::some(s),
+ option::some(s) => option::some(Path(s)),
option::none => {
if parse_name_directive(line, ~"pp-exact") {
- option::some(path::basename(testfile))
+ option::some(testfile.file_path())
} else {
option::none
}
View
132 src/compiletest/runtest.rs
@@ -16,17 +16,18 @@ fn run(config: config, testfile: ~str) {
// We're going to be dumping a lot of info. Start on a new line.
io::stdout().write_str(~"\n\n");
}
- debug!("running %s", testfile);
- let props = load_props(testfile);
+ let testfile = Path(testfile);
+ debug!("running %s", testfile.to_str());
+ let props = load_props(&testfile);
match config.mode {
- mode_compile_fail => run_cfail_test(config, props, testfile),
- mode_run_fail => run_rfail_test(config, props, testfile),
- mode_run_pass => run_rpass_test(config, props, testfile),
- mode_pretty => run_pretty_test(config, props, testfile)
+ mode_compile_fail => run_cfail_test(config, props, &testfile),
+ mode_run_fail => run_rfail_test(config, props, &testfile),
+ mode_run_pass => run_rpass_test(config, props, &testfile),
+ mode_pretty => run_pretty_test(config, props, &testfile)
}
}
-fn run_cfail_test(config: config, props: test_props, testfile: ~str) {
+fn run_cfail_test(config: config, props: test_props, testfile: &Path) {
let procres = compile_test(config, props, testfile);
if procres.status == 0 {
@@ -46,7 +47,7 @@ fn run_cfail_test(config: config, props: test_props, testfile: ~str) {
}
}
-fn run_rfail_test(config: config, props: test_props, testfile: ~str) {
+fn run_rfail_test(config: config, props: test_props, testfile: &Path) {
let mut procres = compile_test(config, props, testfile);
if procres.status != 0 { fatal_procres(~"compilation failed!", procres); }
@@ -74,7 +75,7 @@ fn check_correct_failure_status(procres: procres) {
}
}
-fn run_rpass_test(config: config, props: test_props, testfile: ~str) {
+fn run_rpass_test(config: config, props: test_props, testfile: &Path) {
let mut procres = compile_test(config, props, testfile);
if procres.status != 0 { fatal_procres(~"compilation failed!", procres); }
@@ -84,7 +85,7 @@ fn run_rpass_test(config: config, props: test_props, testfile: ~str) {
if procres.status != 0 { fatal_procres(~"test run failed!", procres); }
}
-fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
+fn run_pretty_test(config: config, props: test_props, testfile: &Path) {
if option::is_some(props.pp_exact) {
logv(config, ~"testing for exact pretty-printing");
} else { logv(config, ~"testing for converging pretty-printing"); }
@@ -111,8 +112,8 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
let mut expected =
match props.pp_exact {
option::some(file) => {
- let filepath = path::connect(path::dirname(testfile), file);
- result::get(io::read_whole_file_str(filepath))
+ let filepath = testfile.dir_path().push_rel(&file);
+ result::get(io::read_whole_file_str(&filepath))
}
option::none => { srcs[vec::len(srcs) - 2u] }
};
@@ -136,15 +137,15 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
return;
- fn print_source(config: config, testfile: ~str, src: ~str) -> procres {
+ fn print_source(config: config, testfile: &Path, src: ~str) -> procres {
compose_and_run(config, testfile, make_pp_args(config, testfile),
~[], config.compile_lib_path, option::some(src))
}
- fn make_pp_args(config: config, _testfile: ~str) -> procargs {
+ fn make_pp_args(config: config, _testfile: &Path) -> procargs {
let prog = config.rustc_path;
let args = ~[~"-", ~"--pretty", ~"normal"];
- return {prog: prog, args: args};
+ return {prog: prog.to_str(), args: args};
}
fn compare_source(expected: ~str, actual: ~str) {
@@ -168,28 +169,30 @@ actual:\n\
}
fn typecheck_source(config: config, props: test_props,
- testfile: ~str, src: ~str) -> procres {
+ testfile: &Path, src: ~str) -> procres {
compose_and_run_compiler(
config, props, testfile,
make_typecheck_args(config, testfile),
option::some(src))
}
- fn make_typecheck_args(config: config, testfile: ~str) -> procargs {
+ fn make_typecheck_args(config: config, testfile: &Path) -> procargs {
let prog = config.rustc_path;
let mut args = ~[~"-",
- ~"--no-trans", ~"--lib", ~"-L", config.build_base,
- ~"-L", aux_output_dir_name(config, testfile)];
+ ~"--no-trans", ~"--lib",
+ ~"-L", config.build_base.to_str(),
+ ~"-L",
+ aux_output_dir_name(config, testfile).to_str()];
args += split_maybe_args(config.rustcflags);
- return {prog: prog, args: args};
+ return {prog: prog.to_str(), args: args};
}
}
fn check_error_patterns(props: test_props,
- testfile: ~str,
+ testfile: &Path,
procres: procres) {
if vec::is_empty(props.error_patterns) {
- fatal(~"no error pattern specified in " + testfile);
+ fatal(~"no error pattern specified in " + testfile.to_str());
}
if procres.status == 0 {
@@ -228,7 +231,7 @@ fn check_error_patterns(props: test_props,
}
fn check_expected_errors(expected_errors: ~[errors::expected_error],
- testfile: ~str,
+ testfile: &Path,
procres: procres) {
// true if we found the error in question
@@ -240,7 +243,7 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
}
let prefixes = vec::map(expected_errors, |ee| {
- fmt!("%s:%u:", testfile, ee.line)
+ fmt!("%s:%u:", testfile.to_str(), ee.line)
});
// Scan and extract our error/warning messages,
@@ -291,8 +294,8 @@ type procargs = {prog: ~str, args: ~[~str]};
type procres = {status: int, stdout: ~str, stderr: ~str, cmdline: ~str};
fn compile_test(config: config, props: test_props,
- testfile: ~str) -> procres {
- let link_args = ~[~"-L", aux_output_dir_name(config, testfile)];
+ testfile: &Path) -> procres {
+ let link_args = ~[~"-L", aux_output_dir_name(config, testfile).to_str()];
compose_and_run_compiler(
config, props, testfile,
make_compile_args(config, props, link_args,
@@ -301,7 +304,7 @@ fn compile_test(config: config, props: test_props,
}
fn exec_compiled_test(config: config, props: test_props,
- testfile: ~str) -> procres {
+ testfile: &Path) -> procres {
compose_and_run(config, testfile,
make_run_args(config, props, testfile),
props.exec_env,
@@ -311,26 +314,28 @@ fn exec_compiled_test(config: config, props: test_props,
fn compose_and_run_compiler(
config: config,
props: test_props,
- testfile: ~str,
+ testfile: &Path,
args: procargs,
input: option<~str>) -> procres {
if props.aux_builds.is_not_empty() {
- ensure_dir(aux_output_dir_name(config, testfile));
+ ensure_dir(&aux_output_dir_name(config, testfile));
}
- let extra_link_args = ~[~"-L", aux_output_dir_name(config, testfile)];
+ let extra_link_args = ~[~"-L",
+ aux_output_dir_name(config, testfile).to_str()];
do vec::iter(props.aux_builds) |rel_ab| {
- let abs_ab = path::connect(config.aux_base, rel_ab);
+ let abs_ab = config.aux_base.push_rel(&Path(rel_ab));
let aux_args =
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
- |a,b| make_lib_name(a, b, testfile), abs_ab);
- let auxres = compose_and_run(config, abs_ab, aux_args, ~[],
+ |a,b| make_lib_name(a, b, testfile), &abs_ab);
+ let auxres = compose_and_run(config, &abs_ab, aux_args, ~[],
config.compile_lib_path, option::none);
if auxres.status != 0 {
fatal_procres(
- fmt!("auxiliary build of %s failed to compile: ", abs_ab),
+ fmt!("auxiliary build of %s failed to compile: ",
+ abs_ab.to_str()),
auxres);
}
}
@@ -339,14 +344,14 @@ fn compose_and_run_compiler(
config.compile_lib_path, input)
}
-fn ensure_dir(path: Path) {
+fn ensure_dir(path: &Path) {
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
- fail fmt!("can't make dir %s", path);
+ fail fmt!("can't make dir %s", path.to_str());
}
}
-fn compose_and_run(config: config, testfile: ~str,
+fn compose_and_run(config: config, testfile: &Path,
procargs: procargs,
procenv: ~[(~str, ~str)],
lib_path: ~str,
@@ -356,28 +361,30 @@ fn compose_and_run(config: config, testfile: ~str,
}
fn make_compile_args(config: config, props: test_props, extras: ~[~str],
- xform: fn(config, ~str) -> ~str, testfile: ~str) ->
- procargs {
+ xform: fn(config, (&Path)) -> Path,
+ testfile: &Path) -> procargs {
let prog = config.rustc_path;
- let mut args = ~[testfile, ~"-o", xform(config, testfile),
- ~"-L", config.build_base] + extras;
+ let mut args = ~[testfile.to_str(),
+ ~"-o", xform(config, testfile).to_str(),
+ ~"-L", config.build_base.to_str()]
+ + extras;
args += split_maybe_args(config.rustcflags);
args += split_maybe_args(props.compile_flags);
- return {prog: prog, args: args};
+ return {prog: prog.to_str(), args: args};
}
-fn make_lib_name(config: config, auxfile: ~str, testfile: ~str) -> ~str {
+fn make_lib_name(config: config, auxfile: &Path, testfile: &Path) -> Path {
// what we return here is not particularly important, as it
// happens; rustc ignores everything except for the directory.
let auxname = output_testname(auxfile);
- path::connect(aux_output_dir_name(config, testfile), auxname)
+ aux_output_dir_name(config, testfile).push_rel(&auxname)
}
-fn make_exe_name(config: config, testfile: ~str) -> ~str {
- output_base_name(config, testfile) + os::exe_suffix()
+fn make_exe_name(config: config, testfile: &Path) -> Path {
+ Path(output_base_name(config, testfile).to_str() + os::exe_suffix())
}
-fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
+fn make_run_args(config: config, _props: test_props, testfile: &Path) ->
procargs {
let toolargs = {
// If we've got another tool to run under (valgrind),
@@ -390,7 +397,7 @@ fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
split_maybe_args(runtool)
};
- let args = toolargs + ~[make_exe_name(config, testfile)];
+ let args = toolargs + ~[make_exe_name(config, testfile).to_str()];
return {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
}
@@ -408,7 +415,7 @@ fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
}
}
-fn program_output(config: config, testfile: ~str, lib_path: ~str, prog: ~str,
+fn program_output(config: config, testfile: &Path, lib_path: ~str, prog: ~str,
args: ~[~str], env: ~[(~str, ~str)],
input: option<~str>) -> procres {
let cmdline =
@@ -445,37 +452,36 @@ fn lib_path_cmd_prefix(path: ~str) -> ~str {
fmt!("%s=\"%s\"", util::lib_path_env_var(), util::make_new_path(path))
}
-fn dump_output(config: config, testfile: ~str, out: ~str, err: ~str) {
+fn dump_output(config: config, testfile: &Path, out: ~str, err: ~str) {
dump_output_file(config, testfile, out, ~"out");
dump_output_file(config, testfile, err, ~"err");
maybe_dump_to_stdout(config, out, err);
}
-fn dump_output_file(config: config, testfile: ~str,
+fn dump_output_file(config: config, testfile: &Path,
out: ~str, extension: ~str) {
let outfile = make_out_name(config, testfile, extension);
let writer = result::get(
- io::file_writer(outfile, ~[io::Create, io::Truncate]));
+ io::file_writer(&outfile, ~[io::Create, io::Truncate]));
writer.write_str(out);
}
-fn make_out_name(config: config, testfile: ~str, extension: ~str) -> ~str {
- output_base_name(config, testfile) + ~"." + extension
+fn make_out_name(config: config, testfile: &Path, extension: ~str) -> Path {
+ output_base_name(config, testfile).with_filetype(extension)
}
-fn aux_output_dir_name(config: config, testfile: ~str) -> ~str {
- output_base_name(config, testfile) + ~".libaux"
+fn aux_output_dir_name(config: config, testfile: &Path) -> Path {
+ output_base_name(config, testfile).with_filetype("libaux")
}
-fn output_testname(testfile: ~str) -> ~str {
- let parts = str::split_char(path::basename(testfile), '.');
- str::connect(vec::slice(parts, 0u, vec::len(parts) - 1u), ~".")
+fn output_testname(testfile: &Path) -> Path {
+ Path(option::get(testfile.filestem()))
}
-fn output_base_name(config: config, testfile: ~str) -> ~str {
- let base = config.build_base;
- let filename = output_testname(testfile);
- fmt!("%s%s.%s", base, filename, config.stage_id)
+fn output_base_name(config: config, testfile: &Path) -> Path {
+ config.build_base
+ .push_rel(&output_testname(testfile))
+ .with_filetype(config.stage_id)
}
fn maybe_dump_to_stdout(config: config, out: ~str, err: ~str) {
View
103 src/fuzzer/fuzzer.rs
@@ -8,7 +8,7 @@ import syntax::diagnostic;
enum test_mode { tm_converge, tm_run, }
type context = { mode: test_mode }; // + rng
-fn write_file(filename: ~str, content: ~str) {
+fn write_file(filename: &Path, content: ~str) {
result::get(
io::file_writer(filename, ~[io::Create, io::Truncate]))
.write_str(content);
@@ -18,13 +18,13 @@ fn contains(haystack: ~str, needle: ~str) -> bool {
str::contains(haystack, needle)
}
-fn find_rust_files(&files: ~[~str], path: ~str) {
- if str::ends_with(path, ~".rs") && !contains(path, ~"utf8") {
+fn find_rust_files(files: &mut ~[Path], path: &Path) {
+ if path.filetype() == some(~"rs") && !contains(path.to_str(), ~"utf8") {
// ignoring "utf8" tests because something is broken
- files += ~[path];
+ vec::push(*files, *path);
} else if os::path_is_dir(path)
- && !contains(path, ~"compile-fail")
- && !contains(path, ~"build") {
+ && !contains(path.to_str(), ~"compile-fail")
+ && !contains(path.to_str(), ~"build") {
for os::list_dir_path(path).each |p| {
find_rust_files(files, p);
}
@@ -221,7 +221,7 @@ fn as_str(f: fn@(io::Writer)) -> ~str {
}
fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
- filename: ~str, cx: context) {
+ filename: &Path, cx: context) {
let stolen = steal(crate, cx.mode);
let extra_exprs = vec::filter(common_exprs(),
|a| safe_to_use_expr(a, cx.mode) );
@@ -235,14 +235,14 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
fn check_variants_T<T: copy>(
crate: ast::crate,
codemap: codemap::codemap,
- filename: ~str,
+ filename: &Path,
thing_label: ~str,
things: ~[T],
stringifier: fn@(@T, syntax::parse::token::ident_interner) -> ~str,
replacer: fn@(ast::crate, uint, T, test_mode) -> ast::crate,
cx: context
) {
- error!("%s contains %u %s objects", filename,
+ error!("%s contains %u %s objects", filename.to_str(),
vec::len(things), thing_label);
// Assuming we're not generating any token_trees
@@ -253,6 +253,7 @@ fn check_variants_T<T: copy>(
if L < 100u {
do under(uint::min(L, 20u)) |i| {
log(error, ~"Replacing... #" + uint::str(i));
+ let fname = str::from_slice(filename.to_str());
do under(uint::min(L, 30u)) |j| {
log(error, ~"With... " + stringifier(@things[j], intr));
let crate2 = @replacer(crate, i, things[j], cx.mode);
@@ -265,7 +266,7 @@ fn check_variants_T<T: copy>(
intr,
diagnostic::mk_span_handler(handler, codemap),
crate2,
- filename,
+ fname,
rdr, a,
pprust::no_ann(),
false))
@@ -276,11 +277,12 @@ fn check_variants_T<T: copy>(
}
tm_run => {
let file_label = fmt!("rusttmp/%s_%s_%u_%u",
- last_part(filename),
+ last_part(filename.to_str()),
thing_label, i, j);
let safe_to_run = !(content_is_dangerous_to_run(*str3)
|| has_raw_pointers(*crate2));
- check_whole_compiler(*str3, file_label, safe_to_run);
+ check_whole_compiler(*str3, &Path(file_label),
+ safe_to_run);
}
}
}
@@ -305,9 +307,9 @@ enum happiness {
// - that would be tricky, requiring use of tasks or serialization
// or randomness.
// This seems to find plenty of bugs as it is :)
-fn check_whole_compiler(code: ~str, suggested_filename_prefix: ~str,
+fn check_whole_compiler(code: ~str, suggested_filename_prefix: &Path,
allow_running: bool) {
- let filename = suggested_filename_prefix + ~".rs";
+ let filename = &suggested_filename_prefix.with_filetype("rs");
write_file(filename, code);
let compile_result = check_compiling(filename);
@@ -320,32 +322,32 @@ fn check_whole_compiler(code: ~str, suggested_filename_prefix: ~str,
match run_result {
passed | cleanly_rejected(_) | known_bug(_) => {
removeIfExists(suggested_filename_prefix);
- removeIfExists(suggested_filename_prefix + ~".rs");
- removeDirIfExists(suggested_filename_prefix + ~".dSYM");
+ removeIfExists(&suggested_filename_prefix.with_filetype("rs"));
+ removeDirIfExists(&suggested_filename_prefix.with_filetype("dSYM"));
}
failed(s) => {
log(error, ~"check_whole_compiler failure: " + s);
- log(error, ~"Saved as: " + filename);
+ log(error, ~"Saved as: " + filename.to_str());
}
}
}
-fn removeIfExists(filename: ~str) {
+fn removeIfExists(filename: &Path) {
// So sketchy!
- assert !contains(filename, ~" ");
- run::program_output(~"bash", ~[~"-c", ~"rm " + filename]);
+ assert !contains(filename.to_str(), ~" ");
+ run::program_output(~"bash", ~[~"-c", ~"rm " + filename.to_str()]);
}
-fn removeDirIfExists(filename: ~str) {
+fn removeDirIfExists(filename: &Path) {
// So sketchy!
- assert !contains(filename, ~" ");
- run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename]);
+ assert !contains(filename.to_str(), ~" ");
+ run::program_output(~"bash", ~[~"-c", ~"rm -r " + filename.to_str()]);
}
-fn check_running(exe_filename: ~str) -> happiness {
+fn check_running(exe_filename: &Path) -> happiness {
let p = run::program_output(
~"/Users/jruderman/scripts/timed_run_rust_program.py",
- ~[exe_filename]);
+ ~[exe_filename.to_str()]);
let comb = p.out + ~"\n" + p.err;
if str::len(comb) > 1u {
log(error, ~"comb comb comb: " + comb);
@@ -381,11 +383,11 @@ fn check_running(exe_filename: ~str) -> happiness {
}
}
-fn check_compiling(filename: ~str) -> happiness {
+fn check_compiling(filename: &Path) -> happiness {
let p = run::program_output(
~"/Users/jruderman/code/rust/build/x86_64-apple-darwin/\
stage1/bin/rustc",
- ~[filename]);
+ ~[filename.to_str()]);
//error!("Status: %d", p.status);
if p.status == 0 {
@@ -415,11 +417,11 @@ fn check_compiling(filename: ~str) -> happiness {
fn parse_and_print(code: @~str) -> ~str {
- let filename = ~"tmp.rs";
+ let filename = Path("tmp.rs");
let sess = parse::new_parse_sess(option::none);
- write_file(filename, *code);
+ write_file(&filename, *code);
let crate = parse::parse_crate_from_source_str(
- filename, code, ~[], sess);
+ filename.to_str(), code, ~[], sess);
do io::with_str_reader(*code) |rdr| {
as_str(|a|
pprust::print_crate(
@@ -428,7 +430,7 @@ fn parse_and_print(code: @~str) -> ~str {
syntax::parse::token::mk_fake_ident_interner(),
sess.span_diagnostic,
crate,
- filename,
+ filename.to_str(),
rdr, a,
pprust::no_ann(),