about summary refs log tree commit diff
path: root/src/librustpkg/path_util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustpkg/path_util.rs')
-rw-r--r--src/librustpkg/path_util.rs110
1 files changed, 57 insertions, 53 deletions
diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs
index fbb2255ad1c..f5b2251a2a6 100644
--- a/src/librustpkg/path_util.rs
+++ b/src/librustpkg/path_util.rs
@@ -53,7 +53,7 @@ pub fn make_dir_rwx_recursive(p: &Path) -> bool { os::mkdir_recursive(p, U_RWX)
 /// True if there's a directory in <workspace> with
 /// pkgid's short name
 pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
-    workspace_contains_package_id_(pkgid, workspace, |p| { p.push("src") }).is_some()
+    workspace_contains_package_id_(pkgid, workspace, |p| p.join("src")).is_some()
 }
 
 pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
@@ -68,10 +68,9 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
     let mut found = None;
     do os::walk_dir(&src_dir) |p| {
         if os::path_is_dir(p) {
-            if *p == src_dir.push_rel(&pkgid.path) || {
-                let pf = p.filename();
-                do pf.iter().any |pf| {
-                    let g = pf.to_str();
+            if *p == src_dir.join(&pkgid.path) || {
+                let pf = p.filename_str();
+                do pf.iter().any |&g| {
                     match split_version_general(g, '-') {
                         None => false,
                         Some((ref might_match, ref vers)) => {
@@ -89,9 +88,9 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
     };
 
     if found.is_some() {
-        debug2!("Found {} in {}", pkgid.to_str(), workspace.to_str());
+        debug2!("Found {} in {}", pkgid.to_str(), workspace.display());
     } else {
-        debug2!("Didn't find {} in {}", pkgid.to_str(), workspace.to_str());
+        debug2!("Didn't find {} in {}", pkgid.to_str(), workspace.display());
     }
     found
 }
@@ -99,20 +98,24 @@ pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
 /// Return the target-specific build subdirectory, pushed onto `base`;
 /// doesn't check that it exists or create it
 pub fn target_build_dir(workspace: &Path) -> Path {
-    workspace.push("build").push(host_triple())
+    let mut dir = workspace.join("build");
+    dir.push(host_triple());
+    dir
 }
 
 /// Return the target-specific lib subdirectory, pushed onto `base`;
 /// doesn't check that it exists or create it
 fn target_lib_dir(workspace: &Path) -> Path {
-    workspace.push("lib").push(host_triple())
+    let mut dir = workspace.join("lib");
+    dir.push(host_triple());
+    dir
 }
 
 /// Return the bin subdirectory, pushed onto `base`;
 /// doesn't check that it exists or create it
 /// note: this isn't target-specific
 fn target_bin_dir(workspace: &Path) -> Path {
-    workspace.push("bin")
+    workspace.join("bin")
 }
 
 /// Figure out what the executable name for <pkgid> in <workspace>'s build
@@ -121,12 +124,12 @@ pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<
     let mut result = target_build_dir(workspace);
     result = mk_output_path(Main, Build, pkgid, result);
     debug2!("built_executable_in_workspace: checking whether {} exists",
-           result.to_str());
+           result.display());
     if os::path_exists(&result) {
         Some(result)
     }
     else {
-        debug2!("built_executable_in_workspace: {} does not exist", result.to_str());
+        debug2!("built_executable_in_workspace: {} does not exist", result.display());
         None
     }
 }
@@ -148,12 +151,12 @@ fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Opt
     // should use a target-specific subdirectory
     result = mk_output_path(what, Build, pkgid, result);
     debug2!("output_in_workspace: checking whether {} exists",
-           result.to_str());
+           result.display());
     if os::path_exists(&result) {
         Some(result)
     }
     else {
-        error2!("output_in_workspace: {} does not exist", result.to_str());
+        error2!("output_in_workspace: {} does not exist", result.display());
         None
     }
 }
@@ -167,7 +170,8 @@ pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Pat
 /// Does the actual searching stuff
 pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Option<Path> {
     // This could break once we're handling multiple versions better -- I should add a test for it
-    match pkg_path.filename() {
+    // FIXME (#9639): This needs to handle non-utf8 paths
+    match pkg_path.filename_str() {
         None => None,
         Some(short_name) => library_in_workspace(pkg_path,
                                                  short_name,
@@ -189,10 +193,10 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
     // contents
 
     debug2!("short_name = {} where = {:?} workspace = {} \
-            prefix = {}", short_name, where, workspace.to_str(), prefix);
+            prefix = {}", short_name, where, workspace.display(), prefix);
 
     let dir_to_search = match where {
-        Build => target_build_dir(workspace).push_rel(path),
+        Build => target_build_dir(workspace).join(path),
         Install => target_lib_dir(workspace)
     };
 
@@ -201,28 +205,24 @@ pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
 
 // rustc doesn't use target-specific subdirectories
 pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
-    library_in(lib_name, &NoVersion, &sysroot.push("lib"))
+    library_in(lib_name, &NoVersion, &sysroot.join("lib"))
 }
 
 fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
-    debug2!("Listing directory {}", dir_to_search.to_str());
+    debug2!("Listing directory {}", dir_to_search.display());
     let dir_contents = os::list_dir(dir_to_search);
     debug2!("dir has {:?} entries", dir_contents.len());
 
     let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name);
-    let lib_filetype = os::consts::DLL_SUFFIX;
+    let lib_filetype = os::consts::DLL_EXTENSION;
 
     debug2!("lib_prefix = {} and lib_filetype = {}", lib_prefix, lib_filetype);
 
     // Find a filename that matches the pattern:
     // (lib_prefix)-hash-(version)(lib_suffix)
-    let paths = do dir_contents.iter().map |p| {
-        Path((*p).clone())
-    };
-
-    let mut libraries = do paths.filter |p| {
-        let extension = p.filetype();
-        debug2!("p = {}, p's extension is {:?}", p.to_str(), extension);
+    let mut libraries = do dir_contents.iter().filter |p| {
+        let extension = p.extension_str();
+        debug2!("p = {}, p's extension is {:?}", p.display(), extension);
         match extension {
             None => false,
             Some(ref s) => lib_filetype == *s
@@ -233,7 +233,7 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
     for p_path in libraries {
         // Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix)
         // and remember what the hash was
-        let mut f_name = match p_path.filestem() {
+        let mut f_name = match p_path.filestem_str() {
             Some(s) => s, None => continue
         };
         // Already checked the filetype above
@@ -267,14 +267,14 @@ fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Opti
 
     if result_filename.is_none() {
         debug2!("warning: library_in_workspace didn't find a library in {} for {}",
-                  dir_to_search.to_str(), short_name);
+                  dir_to_search.display(), short_name);
     }
 
     // Return the filename that matches, which we now know exists
     // (if result_filename != None)
     let abs_path = do result_filename.map |result_filename| {
-        let absolute_path = dir_to_search.push_rel(&result_filename);
-        debug2!("result_filename = {}", absolute_path.to_str());
+        let absolute_path = dir_to_search.join(&result_filename);
+        debug2!("result_filename = {}", absolute_path.display());
         absolute_path
     };
 
@@ -297,7 +297,7 @@ pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
     if !os::path_is_dir(workspace) {
         cond.raise(((*workspace).clone(),
                     format!("Workspace supplied to target_library_in_workspace \
-                             is not a directory! {}", workspace.to_str())));
+                             is not a directory! {}", workspace.display())));
     }
     target_file_in_workspace(pkgid, workspace, Lib, Install)
 }
@@ -329,14 +329,14 @@ fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
     // Artifacts in the build directory live in a package-ID-specific subdirectory,
     // but installed ones don't.
     let result = match (where, what) {
-                (Build, _)         => target_build_dir(workspace).push_rel(&pkgid.path),
-                (Install, Lib)     => target_lib_dir(workspace),
+                (Build, _)      => target_build_dir(workspace).join(&pkgid.path),
+                (Install, Lib)  => target_lib_dir(workspace),
                 (Install, _)    => target_bin_dir(workspace)
     };
     if !os::path_exists(&result) && !mkdir_recursive(&result, U_RWX) {
         cond.raise((result.clone(), format!("target_file_in_workspace couldn't \
             create the {} dir (pkgid={}, workspace={}, what={:?}, where={:?}",
-            subdir, pkgid.to_str(), workspace.to_str(), what, where)));
+            subdir, pkgid.to_str(), workspace.display(), what, where)));
     }
     mk_output_path(what, where, pkgid, result)
 }
@@ -347,8 +347,8 @@ pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
     use conditions::bad_path::cond;
 
     let mut result = target_build_dir(workspace);
-    result = result.push_rel(&pkgid.path);
-    debug2!("Creating build dir {} for package id {}", result.to_str(),
+    result.push(&pkgid.path);
+    debug2!("Creating build dir {} for package id {}", result.display(),
            pkgid.to_str());
     if os::path_exists(&result) || os::mkdir_recursive(&result, U_RWX) {
         result
@@ -370,16 +370,16 @@ pub fn mk_output_path(what: OutputType, where: Target,
         // If we're installing, it just goes under <workspace>...
         Install => workspace,
         // and if we're just building, it goes in a package-specific subdir
-        Build => workspace.push_rel(&pkg_id.path)
+        Build => workspace.join(&pkg_id.path)
     };
     debug2!("[{:?}:{:?}] mk_output_path: short_name = {}, path = {}", what, where,
            if what == Lib { short_name_with_version.clone() } else { pkg_id.short_name.clone() },
-           dir.to_str());
+           dir.display());
     let mut output_path = match what {
         // this code is duplicated from elsewhere; fix this
-        Lib => dir.push(os::dll_filename(short_name_with_version)),
+        Lib => dir.join(os::dll_filename(short_name_with_version)),
         // executable names *aren't* versioned
-        _ => dir.push(format!("{}{}{}", pkg_id.short_name,
+        _ => dir.join(format!("{}{}{}", pkg_id.short_name,
                            match what {
                                Test => "test",
                                Bench => "bench",
@@ -388,9 +388,9 @@ pub fn mk_output_path(what: OutputType, where: Target,
                            os::EXE_SUFFIX))
     };
     if !output_path.is_absolute() {
-        output_path = os::getcwd().push_rel(&output_path).normalize();
+        output_path = os::getcwd().join(&output_path);
     }
-    debug2!("mk_output_path: returning {}", output_path.to_str());
+    debug2!("mk_output_path: returning {}", output_path.display());
     output_path
 }
 
@@ -409,14 +409,14 @@ pub fn uninstall_package_from(workspace: &Path, pkgid: &PkgId) {
     }
     if !did_something {
         warn(format!("Warning: there don't seem to be any files for {} installed in {}",
-             pkgid.to_str(), workspace.to_str()));
+             pkgid.to_str(), workspace.display()));
     }
 
 }
 
 fn dir_has_file(dir: &Path, file: &str) -> bool {
     assert!(dir.is_absolute());
-    os::path_exists(&dir.push(file))
+    os::path_exists(&dir.join(file))
 }
 
 pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {
@@ -425,15 +425,15 @@ pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {
         // Require that the parent directory match the package ID
         // Note that this only matches if the package ID being searched for
         // has a name that's a single component
-        if dir.is_parent_of(&p.path) || dir.is_parent_of(&versionize(&p.path, &p.version)) {
-            debug2!("In find_dir_using_rust_path_hack: checking dir {}", dir.to_str());
+        if dir.ends_with_path(&p.path) || dir.ends_with_path(&versionize(&p.path, &p.version)) {
+            debug2!("In find_dir_using_rust_path_hack: checking dir {}", dir.display());
             if dir_has_file(dir, "lib.rs") || dir_has_file(dir, "main.rs")
                 || dir_has_file(dir, "test.rs") || dir_has_file(dir, "bench.rs") {
-                debug2!("Did find id {} in dir {}", p.to_str(), dir.to_str());
+                debug2!("Did find id {} in dir {}", p.to_str(), dir.display());
                 return Some(dir.clone());
             }
         }
-        debug2!("Didn't find id {} in dir {}", p.to_str(), dir.to_str())
+        debug2!("Didn't find id {} in dir {}", p.to_str(), dir.display())
     }
     None
 }
@@ -449,8 +449,12 @@ pub fn user_set_rust_path() -> bool {
 
 /// Append the version string onto the end of the path's filename
 pub fn versionize(p: &Path, v: &Version) -> Path {
-    let q = p.file_path().to_str();
-    p.with_filename(format!("{}-{}", q, v.to_str()))
+    let q = p.filename().expect("path is a directory");
+    let mut q = q.to_owned();
+    q.push('-' as u8);
+    let vs = v.to_str();
+    q.push_all(vs.as_bytes());
+    p.with_filename(q)
 }
 
 
@@ -458,7 +462,7 @@ pub fn versionize(p: &Path, v: &Version) -> Path {
 pub fn chmod_read_only(p: &Path) -> bool {
     #[fixed_stack_segment];
     unsafe {
-        do p.to_str().with_c_str |src_buf| {
+        do p.with_c_str |src_buf| {
             libc::chmod(src_buf, S_IRUSR as libc::c_int) == 0 as libc::c_int
         }
     }
@@ -468,7 +472,7 @@ pub fn chmod_read_only(p: &Path) -> bool {
 pub fn chmod_read_only(p: &Path) -> bool {
     #[fixed_stack_segment];
     unsafe {
-        do p.to_str().with_c_str |src_buf| {
+        do p.with_c_str |src_buf| {
             libc::chmod(src_buf, S_IRUSR as libc::mode_t) == 0
                 as libc::c_int
         }