Skip to content

Commit bab7eb2

Browse files
committed
path2: Update based on more review feedback
Standardize the is_sep() functions to be the same in both posix and windows, and re-export from path. Update extra::glob to use this. Remove the usage of either, as it's going away. Move the WindowsPath-specific methods out of WindowsPath and make them top-level functions of path::windows instead. This way you cannot accidentally write code that will fail to compile on non-windows architectures without typing ::windows anywhere. Remove GenericPath::from_c_str() and just impl BytesContainer for CString instead. Remove .join_path() and .push_path() and just implement BytesContainer for Path instead. Remove FilenameDisplay and add a boolean flag to Display instead. Remove .each_parent(). It only had one caller, so just inline its definition there.
1 parent c01a97b commit bab7eb2

File tree

17 files changed

+274
-390
lines changed

17 files changed

+274
-390
lines changed

src/compiletest/runtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
189189

190190
let mut expected = match props.pp_exact {
191191
Some(ref file) => {
192-
let filepath = testfile.dir_path().join_path(file);
192+
let filepath = testfile.dir_path().join(file);
193193
io::read_whole_file_str(&filepath).unwrap()
194194
}
195195
None => { srcs[srcs.len() - 2u].clone() }
@@ -657,7 +657,7 @@ fn make_lib_name(config: &config, auxfile: &Path, testfile: &Path) -> Path {
657657
// what we return here is not particularly important, as it
658658
// happens; rustc ignores everything except for the directory.
659659
let auxname = output_testname(auxfile);
660-
aux_output_dir_name(config, testfile).join_path(&auxname)
660+
aux_output_dir_name(config, testfile).join(&auxname)
661661
}
662662

663663
fn make_exe_name(config: &config, testfile: &Path) -> Path {
@@ -757,7 +757,7 @@ fn output_testname(testfile: &Path) -> Path {
757757

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

src/libextra/glob.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
use std::{os, path};
27+
use std::path::is_sep;
2728

2829
use sort;
2930

@@ -81,11 +82,7 @@ pub fn glob(pattern: &str) -> GlobIterator {
8182
*/
8283
pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
8384
#[cfg(windows)]
84-
use is_sep = std::path::windows::is_sep2;
85-
#[cfg(not(windows))]
86-
fn is_sep(c: char) -> bool { c <= '\x7F' && ::std::path::posix::is_sep(&(c as u8)) }
87-
#[cfg(windows)]
88-
fn check_windows_verbatim(p: &Path) -> bool { p.is_verbatim() }
85+
fn check_windows_verbatim(p: &Path) -> bool { path::windows::is_verbatim(p) }
8986
#[cfg(not(windows))]
9087
fn check_windows_verbatim(_: &Path) -> bool { false }
9188
@@ -98,7 +95,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
9895
// since we can't very well find all UNC shares with a 1-letter server name.
9996
return GlobIterator { root: root, dir_patterns: ~[], options: options, todo: ~[] };
10097
}
101-
root.push_path(pat_root.get_ref());
98+
root.push(pat_root.get_ref());
10299
}
103100
104101
let root_len = pat_root.map_move_default(0u, |p| p.as_vec().len());
@@ -462,7 +459,7 @@ fn in_char_specifiers(specifiers: &[CharSpecifier], c: char, options: MatchOptio
462459
463460
/// A helper function to determine if two chars are (possibly case-insensitively) equal.
464461
fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
465-
if cfg!(windows) && path::windows::is_sep2(a) && path::windows::is_sep2(b) {
462+
if cfg!(windows) && path::windows::is_sep(a) && path::windows::is_sep(b) {
466463
true
467464
} else if !case_sensitive && a.is_ascii() && b.is_ascii() {
468465
// FIXME: work with non-ascii chars properly (issue #1347)
@@ -472,16 +469,6 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
472469
}
473470
}
474471
475-
/// A helper function to determine if a char is a path separator on the current platform.
476-
fn is_sep(c: char) -> bool {
477-
if cfg!(windows) {
478-
path::windows::is_sep2(c)
479-
} else {
480-
c <= '\x7F' && path::posix::is_sep(&(c as u8))
481-
}
482-
}
483-
484-
485472
/**
486473
* Configuration options to modify the behaviour of `Pattern::matches_with(..)`
487474
*/

src/librustc/back/rpath.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
4545

4646
fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
4747
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
48-
let mut p = sess.filesearch.sysroot().join_path(&r);
48+
let mut p = sess.filesearch.sysroot().join(&r);
4949
p.push(os::dll_filename("rustrt"));
5050
p
5151
}
@@ -148,7 +148,7 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
148148

149149
let tlib = filesearch::relative_target_lib_path(target_triple);
150150
let mut path = Path::new(install_prefix);
151-
path.push_path(&tlib);
151+
path.push(&tlib);
152152
let path = os::make_absolute(&path);
153153
// FIXME (#9639): This needs to handle non-utf8 paths
154154
path.as_str().expect("non-utf8 component in rpath").to_owned()

src/librustc/metadata/filesearch.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
100100
}
101101
fn get_target_lib_file_path(&self, file: &Path) -> Path {
102102
let mut p = self.get_target_lib_path();
103-
p.push_path(file);
103+
p.push(file);
104104
p
105105
}
106106
}
@@ -148,7 +148,7 @@ pub fn relative_target_lib_path(target_triple: &str) -> Path {
148148

149149
fn make_target_lib_path(sysroot: &Path,
150150
target_triple: &str) -> Path {
151-
sysroot.join_path(&relative_target_lib_path(target_triple))
151+
sysroot.join(&relative_target_lib_path(target_triple))
152152
}
153153

154154
fn make_rustpkg_target_lib_path(dir: &Path,
@@ -196,7 +196,7 @@ pub fn rust_path() -> ~[Path] {
196196
}
197197
None => ~[]
198198
};
199-
let cwd = os::getcwd();
199+
let mut cwd = os::getcwd();
200200
// now add in default entries
201201
let cwd_dot_rust = cwd.join(".rust");
202202
if !env_rust_path.contains(&cwd_dot_rust) {
@@ -205,30 +205,27 @@ pub fn rust_path() -> ~[Path] {
205205
if !env_rust_path.contains(&cwd) {
206206
env_rust_path.push(cwd.clone());
207207
}
208-
do cwd.each_parent() |p| {
209-
if !env_rust_path.contains(&p.join(".rust")) {
210-
push_if_exists(&mut env_rust_path, p);
208+
loop {
209+
let f = cwd.pop();
210+
if f.is_none() || bytes!("..") == f.unwrap() {
211+
break;
211212
}
212-
true
213-
};
213+
cwd.push(".rust");
214+
if !env_rust_path.contains(&cwd) && os::path_exists(&cwd) {
215+
env_rust_path.push(cwd.clone());
216+
}
217+
cwd.pop();
218+
}
214219
let h = os::homedir();
215220
for h in h.iter() {
216-
if !env_rust_path.contains(&h.join(".rust")) {
217-
push_if_exists(&mut env_rust_path, h);
221+
let p = h.join(".rust");
222+
if !env_rust_path.contains(&p) && os::path_exists(&p) {
223+
env_rust_path.push(p);
218224
}
219225
}
220226
env_rust_path
221227
}
222228

223-
224-
/// Adds p/.rust into vec, only if it exists
225-
fn push_if_exists(vec: &mut ~[Path], p: &Path) {
226-
let maybe_dir = p.join(".rust");
227-
if os::path_exists(&maybe_dir) {
228-
vec.push(maybe_dir);
229-
}
230-
}
231-
232229
// The name of the directory rustc expects libraries to be located.
233230
// On Unix should be "lib", on windows "bin"
234231
pub fn libdir() -> ~str {

src/librustpkg/package_source.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,20 @@ impl PkgSrc {
9595
// We search for sources under both src/ and build/ , because build/ is where
9696
// automatically-checked-out sources go.
9797
let mut result = source_workspace.join("src");
98-
result.push_path(&id.path.dir_path());
98+
result.push(&id.path.dir_path());
9999
result.push(format!("{}-{}", id.short_name, id.version.to_str()));
100100
to_try.push(result);
101101
let mut result = source_workspace.join("src");
102-
result.push_path(&id.path);
102+
result.push(&id.path);
103103
to_try.push(result);
104104

105105
let mut result = build_dir.join("src");
106-
result.push_path(&id.path.dir_path());
106+
result.push(&id.path.dir_path());
107107
result.push_str(format!("{}-{}", id.short_name, id.version.to_str()));
108108
to_try.push(result.clone());
109109
output_names.push(result);
110110
let mut other_result = build_dir.join("src");
111-
other_result.push_path(&id.path);
111+
other_result.push(&id.path);
112112
to_try.push(other_result.clone());
113113
output_names.push(other_result);
114114

@@ -146,7 +146,7 @@ impl PkgSrc {
146146
source_workspace: source.clone(),
147147
build_in_destination: build_in_destination,
148148
destination_workspace: destination,
149-
start_dir: start.join_path(&suffix),
149+
start_dir: start.join(&suffix),
150150
id: id,
151151
libs: ~[],
152152
mains: ~[],
@@ -371,7 +371,7 @@ impl PkgSrc {
371371
cfgs: &[~str],
372372
what: OutputType) {
373373
for crate in crates.iter() {
374-
let path = self.start_dir.join_path(&crate.file);
374+
let path = self.start_dir.join(&crate.file);
375375
debug2!("build_crates: compiling {}", path.display());
376376
let cfgs = crate.cfgs + cfgs;
377377

@@ -416,7 +416,7 @@ impl PkgSrc {
416416
debug2!("In declare inputs, self = {}", self.to_str());
417417
for cs in to_do.iter() {
418418
for c in cs.iter() {
419-
let path = self.start_dir.join_path(&c.file);
419+
let path = self.start_dir.join(&c.file);
420420
debug2!("Declaring input: {}", path.display());
421421
// FIXME (#9639): This needs to handle non-utf8 paths
422422
prep.declare_input("file", path.as_str().unwrap(),

src/librustpkg/path_util.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
6868
let mut found = None;
6969
do os::walk_dir(&src_dir) |p| {
7070
if os::path_is_dir(p) {
71-
if *p == src_dir.join_path(&pkgid.path) || {
71+
if *p == src_dir.join(&pkgid.path) || {
7272
let pf = p.filename_str();
7373
do pf.iter().any |&g| {
7474
match split_version_general(g, '-') {
@@ -196,7 +196,7 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
196196
prefix = {}", short_name, where, workspace.display(), prefix);
197197

198198
let dir_to_search = match where {
199-
Build => target_build_dir(workspace).join_path(path),
199+
Build => target_build_dir(workspace).join(path),
200200
Install => target_lib_dir(workspace)
201201
};
202202

@@ -273,7 +273,7 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
273273
// Return the filename that matches, which we now know exists
274274
// (if result_filename != None)
275275
let abs_path = do result_filename.map |result_filename| {
276-
let absolute_path = dir_to_search.join_path(&result_filename);
276+
let absolute_path = dir_to_search.join(&result_filename);
277277
debug2!("result_filename = {}", absolute_path.display());
278278
absolute_path
279279
};
@@ -329,7 +329,7 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
329329
// Artifacts in the build directory live in a package-ID-specific subdirectory,
330330
// but installed ones don't.
331331
let result = match (where, what) {
332-
(Build, _) => target_build_dir(workspace).join_path(&pkgid.path),
332+
(Build, _) => target_build_dir(workspace).join(&pkgid.path),
333333
(Install, Lib) => target_lib_dir(workspace),
334334
(Install, _) => target_bin_dir(workspace)
335335
};
@@ -347,7 +347,7 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
347347
use conditions::bad_path::cond;
348348

349349
let mut result = target_build_dir(workspace);
350-
result.push_path(&pkgid.path);
350+
result.push(&pkgid.path);
351351
debug2!("Creating build dir {} for package id {}", result.display(),
352352
pkgid.to_str());
353353
if os::path_exists(&result) || os::mkdir_recursive(&result, U_RWX) {
@@ -370,7 +370,7 @@ pub fn mk_output_path(what: OutputType, where: Target,
370370
// If we're installing, it just goes under <workspace>...
371371
Install => workspace,
372372
// and if we're just building, it goes in a package-specific subdir
373-
Build => workspace.join_path(&pkg_id.path)
373+
Build => workspace.join(&pkg_id.path)
374374
};
375375
debug2!("[{:?}:{:?}] mk_output_path: short_name = {}, path = {}", what, where,
376376
if what == Lib { short_name_with_version.clone() } else { pkg_id.short_name.clone() },
@@ -388,7 +388,7 @@ pub fn mk_output_path(what: OutputType, where: Target,
388388
os::EXE_SUFFIX))
389389
};
390390
if !output_path.is_absolute() {
391-
output_path = os::getcwd().join_path(&output_path);
391+
output_path = os::getcwd().join(&output_path);
392392
}
393393
debug2!("mk_output_path: returning {}", output_path.display());
394394
output_path

src/librustpkg/rustpkg.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,15 @@ impl CtxMethods for BuildContext {
416416

417417
debug2!("build: workspace = {} (in Rust path? {:?} is git dir? {:?} \
418418
pkgid = {} pkgsrc start_dir = {}", workspace.display(),
419-
in_rust_path(&workspace), is_git_dir(&workspace.join_path(&pkgid.path)),
419+
in_rust_path(&workspace), is_git_dir(&workspace.join(&pkgid.path)),
420420
pkgid.to_str(), pkg_src.start_dir.display());
421421

422422
// If workspace isn't in the RUST_PATH, and it's a git repo,
423423
// then clone it into the first entry in RUST_PATH, and repeat
424-
if !in_rust_path(&workspace) && is_git_dir(&workspace.join_path(&pkgid.path)) {
424+
if !in_rust_path(&workspace) && is_git_dir(&workspace.join(&pkgid.path)) {
425425
let mut out_dir = default_workspace().join("src");
426-
out_dir.push_path(&pkgid.path);
427-
let git_result = source_control::safe_git_clone(&workspace.join_path(&pkgid.path),
426+
out_dir.push(&pkgid.path);
427+
let git_result = source_control::safe_git_clone(&workspace.join(&pkgid.path),
428428
&pkgid.version,
429429
&out_dir);
430430
match git_result {
@@ -494,7 +494,7 @@ impl CtxMethods for BuildContext {
494494
// We expect that p is relative to the package source's start directory,
495495
// so check that assumption
496496
debug2!("JustOne: p = {}", p.display());
497-
assert!(os::path_exists(&pkg_src.start_dir.join_path(p)));
497+
assert!(os::path_exists(&pkg_src.start_dir.join(p)));
498498
if is_lib(p) {
499499
PkgSrc::push_crate(&mut pkg_src.libs, 0, p);
500500
} else if is_main(p) {
@@ -553,7 +553,7 @@ impl CtxMethods for BuildContext {
553553
debug2!("In declare inputs for {}", id.to_str());
554554
for cs in to_do.iter() {
555555
for c in cs.iter() {
556-
let path = pkg_src.start_dir.join_path(&c.file);
556+
let path = pkg_src.start_dir.join(&c.file);
557557
debug2!("Recording input: {}", path.display());
558558
// FIXME (#9639): This needs to handle non-utf8 paths
559559
inputs.push((~"file", path.as_str().unwrap().to_owned()));

src/librustpkg/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &st
156156
fn init_git_repo(p: &Path) -> TempDir {
157157
assert!(p.is_relative());
158158
let tmp = TempDir::new("git_local").expect("couldn't create temp dir");
159-
let work_dir = tmp.path().join_path(p);
159+
let work_dir = tmp.path().join(p);
160160
let work_dir_for_opts = work_dir.clone();
161161
assert!(os::mkdir_recursive(&work_dir, U_RWX));
162162
debug2!("Running: git init in {}", work_dir.display());
@@ -793,7 +793,7 @@ fn test_package_request_version() {
793793
== repo.join_many([".rust", "bin", "test_pkg_version"]));
794794
795795
let mut dir = target_build_dir(&repo.join(".rust"));
796-
dir.push_path(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3"));
796+
dir.push(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3"));
797797
debug2!("dir = {}", dir.display());
798798
assert!(os::path_is_dir(&dir));
799799
assert!(os::path_exists(&dir.join("version-0.3-file.txt")));

src/librustpkg/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub fn compile_input(context: &BuildContext,
177177
// not sure if we should support anything else
178178

179179
let mut out_dir = target_build_dir(workspace);
180-
out_dir.push_path(&pkg_id.path);
180+
out_dir.push(&pkg_id.path);
181181
// Make the output directory if it doesn't exist already
182182
assert!(os::mkdir_recursive(&out_dir, U_RWX));
183183

src/librustpkg/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn parse_vers(vers: ~str) -> result::Result<semver::Version, ~str> {
9898
pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
9999
let rustpath = rust_path();
100100
for rp in rustpath.iter() {
101-
let local_path = rp.join_path(local_path);
101+
let local_path = rp.join(local_path);
102102
let git_dir = local_path.join(".git");
103103
if !os::path_is_dir(&git_dir) {
104104
continue;

0 commit comments

Comments
 (0)