Skip to content

Commit d6d9b92

Browse files
committed
path2: Adjust the API to remove all the _str mutation methods
Add a new trait BytesContainer that is implemented for both byte vectors and strings. Convert Path::from_vec and ::from_str to one function, Path::new(). Remove all the _str-suffixed mutation methods (push, join, with_*, set_*) and modify the non-suffixed versions to use BytesContainer.
1 parent ed539e1 commit d6d9b92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1384
-1485
lines changed

src/compiletest/compiletest.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ pub fn parse_config(args: ~[~str]) -> config {
102102
}
103103

104104
fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
105-
Path::from_str(m.opt_str(nm).unwrap())
105+
Path::new(m.opt_str(nm).unwrap())
106106
}
107107

108108
config {
109109
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
110110
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
111111
rustc_path: opt_path(matches, "rustc-path"),
112-
clang_path: matches.opt_str("clang-path").map(|s| Path::from_str(s)),
113-
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::from_str(s)),
112+
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
113+
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
114114
src_base: opt_path(matches, "src-base"),
115115
build_base: opt_path(matches, "build-base"),
116116
aux_base: opt_path(matches, "aux-base"),
@@ -123,10 +123,10 @@ pub fn parse_config(args: ~[~str]) -> config {
123123
} else {
124124
None
125125
},
126-
logfile: matches.opt_str("logfile").map(|s| Path::from_str(s)),
127-
save_metrics: matches.opt_str("save-metrics").map(|s| Path::from_str(s)),
126+
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
127+
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
128128
ratchet_metrics:
129-
matches.opt_str("ratchet-metrics").map(|s| Path::from_str(s)),
129+
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
130130
ratchet_noise_percent:
131131
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
132132
runtool: matches.opt_str("runtool"),

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
161161

162162
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
163163
match parse_name_value_directive(line, ~"pp-exact") {
164-
Some(s) => Some(Path::from_str(s)),
164+
Some(s) => Some(Path::new(s)),
165165
None => {
166166
if parse_name_directive(line, "pp-exact") {
167167
testfile.file_path()

src/compiletest/runtest.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn run_metrics(config: config, testfile: ~str, mm: &mut MetricMap) {
6262
// We're going to be dumping a lot of info. Start on a new line.
6363
io::stdout().write_str("\n\n");
6464
}
65-
let testfile = Path::from_str(testfile);
65+
let testfile = Path::new(testfile);
6666
debug2!("running {}", testfile.display());
6767
let props = load_props(&testfile);
6868
debug2!("loaded props");
@@ -594,7 +594,7 @@ fn compose_and_run_compiler(
594594
let extra_link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()];
595595

596596
for rel_ab in props.aux_builds.iter() {
597-
let abs_ab = config.aux_base.join_str(*rel_ab);
597+
let abs_ab = config.aux_base.join(rel_ab.as_slice());
598598
let aux_args =
599599
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,
600600
|a,b| make_lib_name(a, b, testfile), &abs_ab);
@@ -662,7 +662,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
662662

663663
fn make_exe_name(config: &config, testfile: &Path) -> Path {
664664
let mut f = output_base_name(config, testfile);
665-
f.add_extension_str(os::EXE_EXTENSION);
665+
f.add_extension(os::EXE_EXTENSION);
666666
f
667667
}
668668

@@ -742,23 +742,23 @@ fn dump_output_file(config: &config, testfile: &Path,
742742
}
743743

744744
fn make_out_name(config: &config, testfile: &Path, extension: &str) -> Path {
745-
output_base_name(config, testfile).with_extension_str(extension)
745+
output_base_name(config, testfile).with_extension(extension)
746746
}
747747

748748
fn aux_output_dir_name(config: &config, testfile: &Path) -> Path {
749749
let mut f = output_base_name(config, testfile);
750-
f.add_extension_str("libaux");
750+
f.add_extension("libaux");
751751
f
752752
}
753753

754754
fn output_testname(testfile: &Path) -> Path {
755-
Path::from_vec(testfile.filestem().unwrap())
755+
Path::new(testfile.filestem().unwrap())
756756
}
757757

758758
fn output_base_name(config: &config, testfile: &Path) -> Path {
759759
config.build_base
760760
.join_path(&output_testname(testfile))
761-
.with_extension_str(config.stage_id)
761+
.with_extension(config.stage_id.as_slice())
762762
}
763763

764764
fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) {
@@ -916,7 +916,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
916916
// codegen tests (vs. clang)
917917

918918
fn make_o_name(config: &config, testfile: &Path) -> Path {
919-
output_base_name(config, testfile).with_extension_str("o")
919+
output_base_name(config, testfile).with_extension("o")
920920
}
921921

922922
fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
@@ -942,9 +942,9 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps,
942942

943943
fn compile_cc_with_clang_and_save_bitcode(config: &config, _props: &TestProps,
944944
testfile: &Path) -> ProcRes {
945-
let bitcodefile = output_base_name(config, testfile).with_extension_str("bc");
945+
let bitcodefile = output_base_name(config, testfile).with_extension("bc");
946946
let bitcodefile = append_suffix_to_stem(&bitcodefile, "clang");
947-
let testcc = testfile.with_extension_str("cc");
947+
let testcc = testfile.with_extension("cc");
948948
let ProcArgs = ProcArgs {
949949
// FIXME (#9639): This needs to handle non-utf8 paths
950950
prog: config.clang_path.get_ref().as_str().unwrap().to_owned(),
@@ -959,10 +959,10 @@ fn compile_cc_with_clang_and_save_bitcode(config: &config, _props: &TestProps,
959959
fn extract_function_from_bitcode(config: &config, _props: &TestProps,
960960
fname: &str, testfile: &Path,
961961
suffix: &str) -> ProcRes {
962-
let bitcodefile = output_base_name(config, testfile).with_extension_str("bc");
962+
let bitcodefile = output_base_name(config, testfile).with_extension("bc");
963963
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
964964
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
965-
let prog = config.llvm_bin_path.get_ref().join_str("llvm-extract");
965+
let prog = config.llvm_bin_path.get_ref().join("llvm-extract");
966966
let ProcArgs = ProcArgs {
967967
// FIXME (#9639): This needs to handle non-utf8 paths
968968
prog: prog.as_str().unwrap().to_owned(),
@@ -975,11 +975,11 @@ fn extract_function_from_bitcode(config: &config, _props: &TestProps,
975975

976976
fn disassemble_extract(config: &config, _props: &TestProps,
977977
testfile: &Path, suffix: &str) -> ProcRes {
978-
let bitcodefile = output_base_name(config, testfile).with_extension_str("bc");
978+
let bitcodefile = output_base_name(config, testfile).with_extension("bc");
979979
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
980980
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
981-
let extracted_ll = extracted_bc.with_extension_str("ll");
982-
let prog = config.llvm_bin_path.get_ref().join_str("llvm-dis");
981+
let extracted_ll = extracted_bc.with_extension("ll");
982+
let prog = config.llvm_bin_path.get_ref().join("llvm-dis");
983983
let ProcArgs = ProcArgs {
984984
// FIXME (#9639): This needs to handle non-utf8 paths
985985
prog: prog.as_str().unwrap().to_owned(),
@@ -991,7 +991,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
991991

992992

993993
fn count_extracted_lines(p: &Path) -> uint {
994-
let x = io::read_whole_file_str(&p.with_extension_str("ll")).unwrap();
994+
let x = io::read_whole_file_str(&p.with_extension("ll")).unwrap();
995995
x.line_iter().len()
996996
}
997997

src/libextra/fileinput.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ instance. `stdin_hyphen` controls whether `-` represents `stdin` or
358358
a literal `-`.
359359
*/
360360
pub fn make_path_option_vec(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
361-
vec.iter().map(|str| {
362-
if stdin_hyphen && "-" == *str {
361+
vec.iter().map(|s| {
362+
if stdin_hyphen && "-" == *s {
363363
None
364364
} else {
365-
Some(Path::from_str(*str))
365+
Some(Path::new(s.as_slice()))
366366
}
367367
}).collect()
368368
}
@@ -435,14 +435,14 @@ mod test {
435435
fn test_make_path_option_vec() {
436436
let strs = [~"some/path",
437437
~"some/other/path"];
438-
let paths = ~[Some(Path::from_str("some/path")),
439-
Some(Path::from_str("some/other/path"))];
438+
let paths = ~[Some(Path::new("some/path")),
439+
Some(Path::new("some/other/path"))];
440440

441441
assert_eq!(make_path_option_vec(strs, true), paths.clone());
442442
assert_eq!(make_path_option_vec(strs, false), paths);
443443

444444
assert_eq!(make_path_option_vec([~"-"], true), ~[None]);
445-
assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path::from_str("-"))]);
445+
assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path::new("-"))]);
446446
}
447447
448448
#[test]
@@ -567,9 +567,9 @@ mod test {
567567
#[test]
568568
fn test_no_trailing_newline() {
569569
let f1 =
570-
Some(Path::from_str("tmp/lib-fileinput-test-no-trailing-newline-1.tmp"));
570+
Some(Path::new("tmp/lib-fileinput-test-no-trailing-newline-1.tmp"));
571571
let f2 =
572-
Some(Path::from_str("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
572+
Some(Path::new("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
573573
574574
{
575575
let mut wr = file::open(f1.get_ref(), io::CreateOrTruncate,

src/libextra/glob.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
9191
9292
// calculate root this way to handle volume-relative Windows paths correctly
9393
let mut root = os::getcwd();
94-
let pat_root = Path::from_str(pattern).root_path();
94+
let pat_root = Path::new(pattern).root_path();
9595
if pat_root.is_some() {
9696
if check_windows_verbatim(pat_root.get_ref()) {
9797
// XXX: How do we want to handle verbatim paths? I'm inclined to return nothing,
@@ -548,7 +548,7 @@ mod test {
548548
assert!(glob("//").next().is_none());
549549
550550
// check windows absolute paths with host/device components
551-
let root_with_device = os::getcwd().root_path().unwrap().join_str("*");
551+
let root_with_device = os::getcwd().root_path().unwrap().join("*");
552552
// FIXME (#9639): This needs to handle non-utf8 paths
553553
assert!(glob(root_with_device.as_str().unwrap()).next().is_some());
554554
}
@@ -772,9 +772,9 @@ mod test {
772772
773773
#[test]
774774
fn test_matches_path() {
775-
// on windows, (Path::from_str("a/b").as_str().unwrap() == "a\\b"), so this
775+
// on windows, (Path::new("a/b").as_str().unwrap() == "a\\b"), so this
776776
// tests that / and \ are considered equivalent on windows
777-
assert!(Pattern::new("a/b").matches_path(&Path::from_str("a/b")));
777+
assert!(Pattern::new("a/b").matches_path(&Path::new("a/b")));
778778
}
779779
}
780780

src/libextra/tempfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl TempDir {
3535

3636
let mut r = rand::rng();
3737
for _ in range(0u, 1000) {
38-
let p = tmpdir.join_str(r.gen_ascii_str(16) + suffix);
38+
let p = tmpdir.join(r.gen_ascii_str(16) + suffix);
3939
if os::make_dir(&p, 0x1c0) { // 700
4040
return Some(TempDir { path: Some(p) });
4141
}

src/libextra/terminfo/searcher.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
2828

2929
// Find search directory
3030
match getenv("TERMINFO") {
31-
Some(dir) => dirs_to_search.push(Path::from_str(dir)),
31+
Some(dir) => dirs_to_search.push(Path::new(dir)),
3232
None => {
3333
if homedir.is_some() {
3434
// ncurses compatability;
35-
dirs_to_search.push(homedir.unwrap().join_str(".terminfo"))
35+
dirs_to_search.push(homedir.unwrap().join(".terminfo"))
3636
}
3737
match getenv("TERMINFO_DIRS") {
3838
Some(dirs) => for i in dirs.split_iter(':') {
3939
if i == "" {
40-
dirs_to_search.push(Path::from_str("/usr/share/terminfo"));
40+
dirs_to_search.push(Path::new("/usr/share/terminfo"));
4141
} else {
42-
dirs_to_search.push(Path::from_str(i.to_owned()));
42+
dirs_to_search.push(Path::new(i.to_owned()));
4343
}
4444
},
4545
// Found nothing, use the default paths
4646
// /usr/share/terminfo is the de facto location, but it seems
4747
// Ubuntu puts it in /lib/terminfo
4848
None => {
49-
dirs_to_search.push(Path::from_str("/usr/share/terminfo"));
50-
dirs_to_search.push(Path::from_str("/lib/terminfo"));
49+
dirs_to_search.push(Path::new("/usr/share/terminfo"));
50+
dirs_to_search.push(Path::new("/lib/terminfo"));
5151
}
5252
}
5353
}
@@ -57,13 +57,13 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> {
5757
for p in dirs_to_search.iter() {
5858
if os::path_exists(p) {
5959
let f = str::from_char(first_char);
60-
let newp = p.join_many_str([f.as_slice(), term]);
60+
let newp = p.join_many([f.as_slice(), term]);
6161
if os::path_exists(&newp) {
6262
return Some(~newp);
6363
}
6464
// on some installations the dir is named after the hex of the char (e.g. OS X)
6565
let f = format!("{:x}", first_char as uint);
66-
let newp = p.join_many_str([f.as_slice(), term]);
66+
let newp = p.join_many([f.as_slice(), term]);
6767
if os::path_exists(&newp) {
6868
return Some(~newp);
6969
}

src/libextra/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,20 @@ pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
271271
let run_ignored = matches.opt_present("ignored");
272272

273273
let logfile = matches.opt_str("logfile");
274-
let logfile = logfile.map(|s| Path::from_str(s));
274+
let logfile = logfile.map(|s| Path::new(s));
275275

276276
let run_benchmarks = matches.opt_present("bench");
277277
let run_tests = ! run_benchmarks ||
278278
matches.opt_present("test");
279279

280280
let ratchet_metrics = matches.opt_str("ratchet-metrics");
281-
let ratchet_metrics = ratchet_metrics.map(|s| Path::from_str(s));
281+
let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s));
282282

283283
let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
284284
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap());
285285

286286
let save_metrics = matches.opt_str("save-metrics");
287-
let save_metrics = save_metrics.map(|s| Path::from_str(s));
287+
let save_metrics = save_metrics.map(|s| Path::new(s));
288288

289289
let test_shard = matches.opt_str("test-shard");
290290
let test_shard = opt_shard(test_shard);
@@ -1440,7 +1440,7 @@ mod tests {
14401440
pub fn ratchet_test() {
14411441
14421442
let dpth = TempDir::new("test-ratchet").expect("missing test for ratchet");
1443-
let pth = dpth.path().join_str("ratchet.json");
1443+
let pth = dpth.path().join("ratchet.json");
14441444
14451445
let mut m1 = MetricMap::new();
14461446
m1.insert_metric("runtime", 1000.0, 2.0);

src/libextra/workcache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn test() {
498498
// Create a path to a new file 'filename' in the directory in which
499499
// this test is running.
500500
fn make_path(filename: ~str) -> Path {
501-
let pth = os::self_exe_path().expect("workcache::test failed").with_filename_str(filename);
501+
let pth = os::self_exe_path().expect("workcache::test failed").with_filename(filename);
502502
if os::path_exists(&pth) {
503503
os::remove_file(&pth);
504504
}

src/librustc/back/link.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub mod write {
249249
llvm::LLVMInitializeMipsAsmParser();
250250

251251
if sess.opts.save_temps {
252-
do output.with_extension_str("no-opt.bc").with_c_str |buf| {
252+
do output.with_extension("no-opt.bc").with_c_str |buf| {
253253
llvm::LLVMWriteBitcodeToFile(llmod, buf);
254254
}
255255
}
@@ -317,7 +317,7 @@ pub mod write {
317317
llvm::LLVMDisposePassManager(mpm);
318318

319319
if sess.opts.save_temps {
320-
do output.with_extension_str("bc").with_c_str |buf| {
320+
do output.with_extension("bc").with_c_str |buf| {
321321
llvm::LLVMWriteBitcodeToFile(llmod, buf);
322322
}
323323
}
@@ -921,7 +921,7 @@ pub fn link_binary(sess: Session,
921921
let out_dirname = out_filename.dir_path();
922922
debug2!("dirname(out_filename): {}", out_dirname.display());
923923

924-
out_filename.with_filename_str(long_libname)
924+
out_filename.with_filename(long_libname)
925925
} else {
926926
out_filename.clone()
927927
};
@@ -977,7 +977,7 @@ pub fn link_args(sess: Session,
977977

978978
let output = if *sess.building_library {
979979
let long_libname = output_dll_filename(sess.targ_cfg.os, lm);
980-
out_filename.with_filename_str(long_libname)
980+
out_filename.with_filename(long_libname)
981981
} else {
982982
out_filename.clone()
983983
};

0 commit comments

Comments
 (0)