Skip to content

Commit 15ddf7f

Browse files
committed
---
yaml --- r: 131580 b: refs/heads/dist-snap c: cc3c8bb h: refs/heads/master v: v3
1 parent c0cd60e commit 15ddf7f

File tree

18 files changed

+445
-16
lines changed

18 files changed

+445
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: df4ea9c39a355e4cff425cca7d58e7758cb3461c
9+
refs/heads/dist-snap: cc3c8bbfaf5af19caf3deb131a995a65ca4674f9
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/back/link.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,11 @@ pub fn find_crate_name(sess: Option<&Session>,
588588
}), None)
589589
}
590590

591-
pub fn build_link_meta(krate: &ast::Crate, name: String) -> LinkMeta {
591+
pub fn build_link_meta(sess: &Session, krate: &ast::Crate,
592+
name: String) -> LinkMeta {
592593
let r = LinkMeta {
593594
crate_name: name,
594-
crate_hash: Svh::calculate(krate),
595+
crate_hash: Svh::calculate(sess, krate),
595596
};
596597
info!("{}", r);
597598
return r;

branches/dist-snap/src/librustc/back/svh.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ use std::iter::range_step;
5353
use syntax::ast;
5454
use syntax::visit;
5555

56+
use driver::session::Session;
57+
5658
#[deriving(Clone, PartialEq)]
5759
pub struct Svh {
5860
hash: String,
@@ -68,7 +70,7 @@ impl Svh {
6870
self.hash.as_slice()
6971
}
7072

71-
pub fn calculate(krate: &ast::Crate) -> Svh {
73+
pub fn calculate(sess: &Session, krate: &ast::Crate) -> Svh {
7274
// FIXME (#14132): This is better than it used to be, but it still not
7375
// ideal. We now attempt to hash only the relevant portions of the
7476
// Crate AST as well as the top-level crate attributes. (However,
@@ -80,6 +82,10 @@ impl Svh {
8082
// avoid collisions.
8183
let mut state = SipState::new();
8284

85+
for data in sess.opts.cg.metadata.iter() {
86+
data.hash(&mut state);
87+
}
88+
8389
{
8490
let mut visit = svh_visitor::make(&mut state);
8591
visit::walk_crate(&mut visit, krate, ());

branches/dist-snap/src/librustc/driver/config.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use syntax::diagnostic::{ColorConfig, Auto, Always, Never};
3030
use syntax::parse;
3131
use syntax::parse::token::InternedString;
3232

33-
use std::collections::HashSet;
33+
use std::collections::{HashSet, HashMap};
3434
use getopts::{optopt, optmulti, optflag, optflagopt};
3535
use getopts;
3636
use lib::llvm::llvm;
@@ -95,6 +95,7 @@ pub struct Options {
9595
pub print_metas: (bool, bool),
9696
pub cg: CodegenOptions,
9797
pub color: ColorConfig,
98+
pub externs: HashMap<String, Vec<String>>,
9899
}
99100

100101
/// Some reasonable defaults
@@ -120,6 +121,7 @@ pub fn basic_options() -> Options {
120121
print_metas: (false, false),
121122
cg: basic_codegen_options(),
122123
color: Auto,
124+
externs: HashMap::new(),
123125
}
124126
}
125127

@@ -551,7 +553,9 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
551553
optopt("", "color", "Configure coloring of output:
552554
auto = colorize, if output goes to a tty (default);
553555
always = always colorize output;
554-
never = never colorize output", "auto|always|never")
556+
never = never colorize output", "auto|always|never"),
557+
optmulti("", "extern", "Specify where an external rust library is located",
558+
"PATH"),
555559
)
556560
}
557561

@@ -730,6 +734,21 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
730734
}
731735
};
732736

737+
let mut externs = HashMap::new();
738+
for arg in matches.opt_strs("extern").iter() {
739+
let mut parts = arg.as_slice().splitn('=', 1);
740+
let name = match parts.next() {
741+
Some(s) => s,
742+
None => early_error("--extern value must not be empty"),
743+
};
744+
let location = match parts.next() {
745+
Some(s) => s,
746+
None => early_error("--extern value must be of the format `foo=bar`"),
747+
};
748+
let locs = externs.find_or_insert(name.to_string(), Vec::new());
749+
locs.push(location.to_string());
750+
}
751+
733752
Options {
734753
crate_types: crate_types,
735754
gc: gc,
@@ -750,7 +769,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
750769
write_dependency_info: write_dependency_info,
751770
print_metas: print_metas,
752771
cg: cg,
753-
color: color
772+
color: color,
773+
externs: externs,
754774
}
755775
}
756776

branches/dist-snap/src/librustc/metadata/creader.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,32 @@ fn existing_match(e: &Env, name: &str,
280280
hash: Option<&Svh>) -> Option<ast::CrateNum> {
281281
let mut ret = None;
282282
e.sess.cstore.iter_crate_data(|cnum, data| {
283-
if data.name().as_slice() == name {
284-
let other_hash = data.hash();
285-
match hash {
286-
Some(hash) if *hash != other_hash => {}
287-
Some(..) | None => { ret = Some(cnum); }
283+
if data.name().as_slice() != name { return }
284+
285+
match hash {
286+
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
287+
Some(..) => return,
288+
None => {}
289+
}
290+
291+
// When the hash is None we're dealing with a top-level dependency in
292+
// which case we may have a specification on the command line for this
293+
// library. Even though an upstream library may have loaded something of
294+
// the same name, we have to make sure it was loaded from the exact same
295+
// location as well.
296+
let source = e.sess.cstore.get_used_crate_source(cnum).unwrap();
297+
let dylib = source.dylib.as_ref().map(|p| p.as_vec());
298+
let rlib = source.rlib.as_ref().map(|p| p.as_vec());
299+
match e.sess.opts.externs.find_equiv(&name) {
300+
Some(locs) => {
301+
let found = locs.iter().any(|l| {
302+
Some(l.as_bytes()) == dylib || Some(l.as_bytes()) == rlib
303+
});
304+
if found {
305+
ret = Some(cnum);
306+
}
288307
}
308+
None => ret = Some(cnum),
289309
}
290310
});
291311
return ret;
@@ -361,6 +381,7 @@ fn resolve_crate<'a>(e: &mut Env,
361381
root: root,
362382
rejected_via_hash: vec!(),
363383
rejected_via_triple: vec!(),
384+
should_match_name: true,
364385
};
365386
let library = load_ctxt.load_library_crate();
366387
register_crate(e, root, ident, name, span, library)
@@ -422,6 +443,7 @@ impl<'a> PluginMetadataReader<'a> {
422443
root: &None,
423444
rejected_via_hash: vec!(),
424445
rejected_via_triple: vec!(),
446+
should_match_name: true,
425447
};
426448
let library = match load_ctxt.maybe_load_library_crate() {
427449
Some (l) => l,

0 commit comments

Comments
 (0)