about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-05-02 13:50:24 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-05-02 13:50:24 -0700
commitf9c2d0ebfbfa1e3e1b6670c29828e048e1588bae (patch)
treef60ea11fe772c2f989687d63697c277f74fa913a
parentb5d6b07370b665df6b54fa20e971e61041a233b0 (diff)
downloadrust-f9c2d0ebfbfa1e3e1b6670c29828e048e1588bae.tar.gz
rust-f9c2d0ebfbfa1e3e1b6670c29828e048e1588bae.zip
rustc: Use the "real" realpath function
The logic of the custom realpath function in metadata::loader was incorrect, but
the logic in util::fs was correct.

Closes #13890
-rw-r--r--src/librustc/metadata/loader.rs18
-rw-r--r--src/test/run-make/libs-through-symlinks/Makefile14
-rw-r--r--src/test/run-make/libs-through-symlinks/bar.rs13
-rw-r--r--src/test/run-make/libs-through-symlinks/foo.rs12
4 files changed, 42 insertions, 15 deletions
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index 74a1c8c4678..ebe3ce69dab 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -22,6 +22,7 @@ use syntax::codemap::Span;
 use syntax::diagnostic::SpanHandler;
 use syntax::crateid::CrateId;
 use syntax::attr::AttrMetaMethods;
+use util::fs;
 
 use std::c_str::ToCStr;
 use std::cast;
@@ -107,18 +108,6 @@ impl CratePaths {
     }
 }
 
-// FIXME(#11857) this should be a "real" realpath
-fn realpath(p: &Path) -> Path {
-    use std::os;
-    use std::io::fs;
-
-    let path = os::make_absolute(p);
-    match fs::readlink(&path) {
-        Ok(p) => p,
-        Err(..) => path
-    }
-}
-
 impl<'a> Context<'a> {
     pub fn maybe_load_library_crate(&mut self) -> Option<Library> {
         self.find_library_crate()
@@ -209,7 +198,6 @@ impl<'a> Context<'a> {
                 None => return FileDoesntMatch,
                 Some(file) => file,
             };
-            info!("file: {}", file);
             if file.starts_with(rlib_prefix) && file.ends_with(".rlib") {
                 info!("rlib candidate: {}", path.display());
                 match self.try_match(file, rlib_prefix, ".rlib") {
@@ -219,7 +207,7 @@ impl<'a> Context<'a> {
                             (HashSet::new(), HashSet::new())
                         });
                         let (ref mut rlibs, _) = *slot;
-                        rlibs.insert(realpath(path));
+                        rlibs.insert(fs::realpath(path).unwrap());
                         FileMatches
                     }
                     None => {
@@ -236,7 +224,7 @@ impl<'a> Context<'a> {
                             (HashSet::new(), HashSet::new())
                         });
                         let (_, ref mut dylibs) = *slot;
-                        dylibs.insert(realpath(path));
+                        dylibs.insert(fs::realpath(path).unwrap());
                         FileMatches
                     }
                     None => {
diff --git a/src/test/run-make/libs-through-symlinks/Makefile b/src/test/run-make/libs-through-symlinks/Makefile
new file mode 100644
index 00000000000..d19e8f22c05
--- /dev/null
+++ b/src/test/run-make/libs-through-symlinks/Makefile
@@ -0,0 +1,14 @@
+-include ../tools.mk
+
+ifdef IS_WINDOWS
+all:
+else
+
+NAME := $(shell $(RUSTC) --crate-file-name foo.rs)
+
+all:
+	mkdir -p $(TMPDIR)/outdir
+	$(RUSTC) foo.rs -o $(TMPDIR)/outdir/$(NAME)
+	ln -nsf outdir/$(NAME) $(TMPDIR)
+	RUST_LOG=rustc::metadata::loader $(RUSTC) bar.rs
+endif
diff --git a/src/test/run-make/libs-through-symlinks/bar.rs b/src/test/run-make/libs-through-symlinks/bar.rs
new file mode 100644
index 00000000000..6316cfa3bba
--- /dev/null
+++ b/src/test/run-make/libs-through-symlinks/bar.rs
@@ -0,0 +1,13 @@
+// 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.
+
+extern crate foo;
+
+fn main() {}
diff --git a/src/test/run-make/libs-through-symlinks/foo.rs b/src/test/run-make/libs-through-symlinks/foo.rs
new file mode 100644
index 00000000000..6864076d18e
--- /dev/null
+++ b/src/test/run-make/libs-through-symlinks/foo.rs
@@ -0,0 +1,12 @@
+// 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.
+
+#![crate_type = "rlib"]
+#![crate_id = "foo"]