Tighten up error checking of library renames.
This commit is contained in:
parent
a9a6f8c8ed
commit
a23c470433
@ -946,19 +946,51 @@ impl<'a> middle::cstore::CrateLoader for CrateLoader<'a> {
|
||||
}
|
||||
|
||||
// Process libs passed on the command line
|
||||
// First, check for errors
|
||||
let mut renames = FxHashSet();
|
||||
for &(ref name, ref new_name, _) in &self.sess.opts.libs {
|
||||
if let &Some(ref new_name) = new_name {
|
||||
if new_name.is_empty() {
|
||||
self.sess.err(
|
||||
&format!("an empty renaming target was specified for library `{}`",name));
|
||||
} else if !self.cstore.get_used_libraries().borrow().iter()
|
||||
.any(|lib| lib.name == name as &str) {
|
||||
self.sess.err(&format!("renaming of the library `{}` was specified, \
|
||||
however this crate contains no #[link(...)] \
|
||||
attributes referencing this library.", name));
|
||||
} else if renames.contains(name) {
|
||||
self.sess.err(&format!("multiple renamings were specified for library `{}` .",
|
||||
name));
|
||||
} else {
|
||||
renames.insert(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Update kind and, optionally, the name of all native libaries
|
||||
// (there may be more than one) with the specified name.
|
||||
for &(ref name, ref new_name, kind) in &self.sess.opts.libs {
|
||||
// First, try to update existing lib(s) added via #[link(...)]
|
||||
let new_name = new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
|
||||
if !self.cstore.update_used_library(name, new_name, kind) {
|
||||
let mut found = false;
|
||||
for lib in self.cstore.get_used_libraries().borrow_mut().iter_mut() {
|
||||
if lib.name == name as &str {
|
||||
lib.kind = kind;
|
||||
if let &Some(ref new_name) = new_name {
|
||||
lib.name = Symbol::intern(new_name);
|
||||
}
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
// Add if not found
|
||||
let new_name = new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
|
||||
let lib = NativeLibrary {
|
||||
name: Symbol::intern(name),
|
||||
name: Symbol::intern(new_name.unwrap_or(name)),
|
||||
kind: kind,
|
||||
cfg: None,
|
||||
foreign_items: Vec::new(),
|
||||
};
|
||||
register_native_lib(self.sess, self.cstore, None, lib);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.register_statically_included_foreign_items();
|
||||
self.register_dllimport_foreign_items();
|
||||
|
@ -232,23 +232,6 @@ impl CStore {
|
||||
self.used_libraries.borrow_mut().push(lib);
|
||||
}
|
||||
|
||||
// Update kind and, optionally, the name of all native libaries (there may be more than one)
|
||||
// with the specified name.
|
||||
pub fn update_used_library(&self, name: &str, new_name: Option<&str>,
|
||||
new_kind: NativeLibraryKind) -> bool {
|
||||
let mut found = false;
|
||||
for item in self.used_libraries.borrow_mut().iter_mut() {
|
||||
if item.name == name {
|
||||
item.kind = new_kind;
|
||||
if let Some(new_name) = new_name {
|
||||
item.name = Symbol::intern(new_name);
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
pub fn get_used_libraries(&self) -> &RefCell<Vec<NativeLibrary>> {
|
||||
&self.used_libraries
|
||||
}
|
||||
|
14
src/test/compile-fail/rfc1717/missing-link-attr.rs
Normal file
14
src/test/compile-fail/rfc1717/missing-link-attr.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// compile-flags: -l foo:bar
|
||||
// error-pattern: renaming of the library `foo` was specified
|
||||
|
||||
#![crate_type = "lib"]
|
17
src/test/compile-fail/rfc1717/multiple-renames.rs
Normal file
17
src/test/compile-fail/rfc1717/multiple-renames.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// compile-flags: -l foo:bar -l foo:baz
|
||||
// error-pattern: multiple renamings were specified for library
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
#[link(name = "foo")]
|
||||
extern "C" {}
|
17
src/test/compile-fail/rfc1717/rename-to-empty.rs
Normal file
17
src/test/compile-fail/rfc1717/rename-to-empty.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// compile-flags: -l foo:
|
||||
// error-pattern: an empty renaming target was specified for library
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
#[link(name = "foo")]
|
||||
extern "C" {}
|
Loading…
x
Reference in New Issue
Block a user