]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Move util::fs to rustc_back
authorBrian Anderson <banderson@mozilla.com>
Mon, 7 Jul 2014 05:13:55 +0000 (22:13 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 14 Jul 2014 19:27:07 +0000 (12:27 -0700)
src/librustc/lib.rs
src/librustc/util/fs.rs [deleted file]
src/librustc_back/fs.rs [new file with mode: 0644]
src/librustc_back/lib.rs

index cf6852438a72a604d0883146251e1b6c91a31cd1..016af688c50fbbe2c6572dbe315a0e45937f6f7d 100644 (file)
@@ -125,11 +125,12 @@ pub mod front {
 pub mod lint;
 
 pub mod util {
+    pub use rustc_back::fs;
+
     pub mod common;
     pub mod ppaux;
     pub mod sha2;
     pub mod nodemap;
-    pub mod fs;
 }
 
 pub mod lib {
diff --git a/src/librustc/util/fs.rs b/src/librustc/util/fs.rs
deleted file mode 100644 (file)
index c051b8e..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::io;
-use std::io::fs;
-use std::os;
-
-/// Returns an absolute path in the filesystem that `path` points to. The
-/// returned path does not contain any symlinks in its hierarchy.
-pub fn realpath(original: &Path) -> io::IoResult<Path> {
-    static MAX_LINKS_FOLLOWED: uint = 256;
-    let original = os::make_absolute(original);
-
-    // Right now lstat on windows doesn't work quite well
-    if cfg!(windows) {
-        return Ok(original)
-    }
-
-    let result = original.root_path();
-    let mut result = result.expect("make_absolute has no root_path");
-    let mut followed = 0;
-
-    for part in original.components() {
-        result.push(part);
-
-        loop {
-            if followed == MAX_LINKS_FOLLOWED {
-                return Err(io::standard_error(io::InvalidInput))
-            }
-
-            match fs::lstat(&result) {
-                Err(..) => break,
-                Ok(ref stat) if stat.kind != io::TypeSymlink => break,
-                Ok(..) => {
-                    followed += 1;
-                    let path = try!(fs::readlink(&result));
-                    result.pop();
-                    result.push(path);
-                }
-            }
-        }
-    }
-
-    return Ok(result);
-}
-
-#[cfg(not(windows), test)]
-mod test {
-    use std::io;
-    use std::io::fs::{File, symlink, mkdir, mkdir_recursive};
-    use super::realpath;
-    use std::io::TempDir;
-
-    #[test]
-    fn realpath_works() {
-        let tmpdir = TempDir::new("rustc-fs").unwrap();
-        let tmpdir = realpath(tmpdir.path()).unwrap();
-        let file = tmpdir.join("test");
-        let dir = tmpdir.join("test2");
-        let link = dir.join("link");
-        let linkdir = tmpdir.join("test3");
-
-        File::create(&file).unwrap();
-        mkdir(&dir, io::UserRWX).unwrap();
-        symlink(&file, &link).unwrap();
-        symlink(&dir, &linkdir).unwrap();
-
-        assert!(realpath(&tmpdir).unwrap() == tmpdir);
-        assert!(realpath(&file).unwrap() == file);
-        assert!(realpath(&link).unwrap() == file);
-        assert!(realpath(&linkdir).unwrap() == dir);
-        assert!(realpath(&linkdir.join("link")).unwrap() == file);
-    }
-
-    #[test]
-    fn realpath_works_tricky() {
-        let tmpdir = TempDir::new("rustc-fs").unwrap();
-        let tmpdir = realpath(tmpdir.path()).unwrap();
-
-        let a = tmpdir.join("a");
-        let b = a.join("b");
-        let c = b.join("c");
-        let d = a.join("d");
-        let e = d.join("e");
-        let f = a.join("f");
-
-        mkdir_recursive(&b, io::UserRWX).unwrap();
-        mkdir_recursive(&d, io::UserRWX).unwrap();
-        File::create(&f).unwrap();
-        symlink(&Path::new("../d/e"), &c).unwrap();
-        symlink(&Path::new("../f"), &e).unwrap();
-
-        assert!(realpath(&c).unwrap() == f);
-        assert!(realpath(&e).unwrap() == f);
-    }
-}
diff --git a/src/librustc_back/fs.rs b/src/librustc_back/fs.rs
new file mode 100644 (file)
index 0000000..c051b8e
--- /dev/null
@@ -0,0 +1,103 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::io;
+use std::io::fs;
+use std::os;
+
+/// Returns an absolute path in the filesystem that `path` points to. The
+/// returned path does not contain any symlinks in its hierarchy.
+pub fn realpath(original: &Path) -> io::IoResult<Path> {
+    static MAX_LINKS_FOLLOWED: uint = 256;
+    let original = os::make_absolute(original);
+
+    // Right now lstat on windows doesn't work quite well
+    if cfg!(windows) {
+        return Ok(original)
+    }
+
+    let result = original.root_path();
+    let mut result = result.expect("make_absolute has no root_path");
+    let mut followed = 0;
+
+    for part in original.components() {
+        result.push(part);
+
+        loop {
+            if followed == MAX_LINKS_FOLLOWED {
+                return Err(io::standard_error(io::InvalidInput))
+            }
+
+            match fs::lstat(&result) {
+                Err(..) => break,
+                Ok(ref stat) if stat.kind != io::TypeSymlink => break,
+                Ok(..) => {
+                    followed += 1;
+                    let path = try!(fs::readlink(&result));
+                    result.pop();
+                    result.push(path);
+                }
+            }
+        }
+    }
+
+    return Ok(result);
+}
+
+#[cfg(not(windows), test)]
+mod test {
+    use std::io;
+    use std::io::fs::{File, symlink, mkdir, mkdir_recursive};
+    use super::realpath;
+    use std::io::TempDir;
+
+    #[test]
+    fn realpath_works() {
+        let tmpdir = TempDir::new("rustc-fs").unwrap();
+        let tmpdir = realpath(tmpdir.path()).unwrap();
+        let file = tmpdir.join("test");
+        let dir = tmpdir.join("test2");
+        let link = dir.join("link");
+        let linkdir = tmpdir.join("test3");
+
+        File::create(&file).unwrap();
+        mkdir(&dir, io::UserRWX).unwrap();
+        symlink(&file, &link).unwrap();
+        symlink(&dir, &linkdir).unwrap();
+
+        assert!(realpath(&tmpdir).unwrap() == tmpdir);
+        assert!(realpath(&file).unwrap() == file);
+        assert!(realpath(&link).unwrap() == file);
+        assert!(realpath(&linkdir).unwrap() == dir);
+        assert!(realpath(&linkdir.join("link")).unwrap() == file);
+    }
+
+    #[test]
+    fn realpath_works_tricky() {
+        let tmpdir = TempDir::new("rustc-fs").unwrap();
+        let tmpdir = realpath(tmpdir.path()).unwrap();
+
+        let a = tmpdir.join("a");
+        let b = a.join("b");
+        let c = b.join("c");
+        let d = a.join("d");
+        let e = d.join("e");
+        let f = a.join("f");
+
+        mkdir_recursive(&b, io::UserRWX).unwrap();
+        mkdir_recursive(&d, io::UserRWX).unwrap();
+        File::create(&f).unwrap();
+        symlink(&Path::new("../d/e"), &c).unwrap();
+        symlink(&Path::new("../f"), &e).unwrap();
+
+        assert!(realpath(&c).unwrap() == f);
+        assert!(realpath(&e).unwrap() == f);
+    }
+}
index b4c4118c76d56d778288c382b1f643a88cd97948..00791b39bcaace91b60f99cfb1da5ee34ed89df3 100644 (file)
@@ -45,6 +45,7 @@
 pub mod abi;
 pub mod archive;
 pub mod arm;
+pub mod fs;
 pub mod mips;
 pub mod mipsel;
 pub mod rpath;