From a5590b3c752f5a7039c8786081c9d6a80267bdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Thu, 14 Aug 2014 23:42:37 +0200 Subject: [PATCH] Properly canonicalize crate paths specified via --extern Crates that are resolved normally have their path canonicalized and all symlinks resolved. This does currently not happen for paths specified using the --extern option to rustc, which can lead to rustc thinking that it encountered two different versions of a crate, when it's actually the same version found through different paths. To fix this, we must store the canonical path for crates found via --extern and also use the canonical path when comparing paths. Fixes #16496 --- src/librustc/metadata/creader.rs | 3 ++- src/librustc/metadata/loader.rs | 4 ++-- src/test/run-make/symlinked-extern/Makefile | 16 ++++++++++++++++ src/test/run-make/symlinked-extern/bar.rs | 16 ++++++++++++++++ src/test/run-make/symlinked-extern/baz.rs | 16 ++++++++++++++++ src/test/run-make/symlinked-extern/foo.rs | 15 +++++++++++++++ 6 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/test/run-make/symlinked-extern/Makefile create mode 100644 src/test/run-make/symlinked-extern/bar.rs create mode 100644 src/test/run-make/symlinked-extern/baz.rs create mode 100644 src/test/run-make/symlinked-extern/foo.rs diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 0445b4d4e9e1f..321eee3d5fcef 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -33,6 +33,7 @@ use syntax::diagnostic::SpanHandler; use syntax::parse::token::InternedString; use syntax::parse::token; use syntax::visit; +use util::fs; struct Env<'a> { sess: &'a Session, @@ -301,7 +302,7 @@ fn existing_match(e: &Env, name: &str, match e.sess.opts.externs.find_equiv(&name) { Some(locs) => { let found = locs.iter().any(|l| { - let l = Some(Path::new(l.as_slice())); + let l = fs::realpath(&Path::new(l.as_slice())).ok(); l == source.dylib || l == source.rlib }); if found { diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index d2e1fca0da75d..58e9e2e61d42d 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -666,9 +666,9 @@ impl<'a> Context<'a> { let mut dylibs = HashSet::new(); for loc in locs { if loc.filename_str().unwrap().ends_with(".rlib") { - rlibs.insert(loc.clone()); + rlibs.insert(fs::realpath(&loc).unwrap()); } else { - dylibs.insert(loc.clone()); + dylibs.insert(fs::realpath(&loc).unwrap()); } } diff --git a/src/test/run-make/symlinked-extern/Makefile b/src/test/run-make/symlinked-extern/Makefile new file mode 100644 index 0000000000000..88dbad51e481a --- /dev/null +++ b/src/test/run-make/symlinked-extern/Makefile @@ -0,0 +1,16 @@ +-include ../tools.mk + +# ignore windows: `ln` is actually `cp` on msys. +ifndef IS_WINDOWS + +all: + $(RUSTC) foo.rs + mkdir -p $(TMPDIR)/other + ln -nsf $(TMPDIR)/libfoo.rlib $(TMPDIR)/other + $(RUSTC) bar.rs -L $(TMPDIR) + $(RUSTC) baz.rs --extern foo=$(TMPDIR)/other/libfoo.rlib -L $(TMPDIR) + +else +all: + +endif diff --git a/src/test/run-make/symlinked-extern/bar.rs b/src/test/run-make/symlinked-extern/bar.rs new file mode 100644 index 0000000000000..79103f2401700 --- /dev/null +++ b/src/test/run-make/symlinked-extern/bar.rs @@ -0,0 +1,16 @@ +// Copyright 2012-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +extern crate foo; + +pub fn bar(_s: foo::S) { +} diff --git a/src/test/run-make/symlinked-extern/baz.rs b/src/test/run-make/symlinked-extern/baz.rs new file mode 100644 index 0000000000000..0f6ba25436823 --- /dev/null +++ b/src/test/run-make/symlinked-extern/baz.rs @@ -0,0 +1,16 @@ +// Copyright 2012-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate bar; +extern crate foo; + +fn main() { + bar::bar(foo::foo()); +} diff --git a/src/test/run-make/symlinked-extern/foo.rs b/src/test/run-make/symlinked-extern/foo.rs new file mode 100644 index 0000000000000..0b8bb64d37572 --- /dev/null +++ b/src/test/run-make/symlinked-extern/foo.rs @@ -0,0 +1,15 @@ +// Copyright 2012-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "rlib"] + +pub struct S; + +pub fn foo() -> S { S }