@@ -21,8 +21,6 @@ use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
2121use syntax:: abi;
2222use syntax:: codemap:: Span ;
2323use syntax:: diagnostic:: SpanHandler ;
24- use syntax:: crateid:: CrateId ;
25- use syntax:: attr:: AttrMetaMethods ;
2624use util:: fs;
2725
2826use std:: c_str:: ToCStr ;
@@ -61,8 +59,7 @@ pub struct Context<'a> {
6159 pub sess : & ' a Session ,
6260 pub span : Span ,
6361 pub ident : & ' a str ,
64- pub crate_id : & ' a CrateId ,
65- pub id_hash : & ' a str ,
62+ pub crate_name : & ' a str ,
6663 pub hash : Option < & ' a Svh > ,
6764 pub triple : & ' a str ,
6865 pub os : abi:: Os ,
@@ -171,15 +168,15 @@ impl<'a> Context<'a> {
171168
172169 // want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
173170 let dylib_prefix = dypair. map ( |( prefix, _) | {
174- format ! ( "{}{}- " , prefix, self . crate_id . name )
171+ format ! ( "{}{}" , prefix, self . crate_name )
175172 } ) ;
176- let rlib_prefix = format ! ( "lib{}- " , self . crate_id . name ) ;
173+ let rlib_prefix = format ! ( "lib{}" , self . crate_name ) ;
177174
178175 let mut candidates = HashMap :: new ( ) ;
179176
180177 // First, find all possible candidate rlibs and dylibs purely based on
181178 // the name of the files themselves. We're trying to match against an
182- // exact crate_id and a possibly an exact hash.
179+ // exact crate name and a possibly an exact hash.
183180 //
184181 // During this step, we can filter all found libraries based on the
185182 // name and id found in the crate id (we ignore the path portion for
@@ -195,49 +192,32 @@ impl<'a> Context<'a> {
195192 None => return FileDoesntMatch ,
196193 Some ( file) => file,
197194 } ;
198- if file. starts_with ( rlib_prefix. as_slice ( ) ) &&
195+ let ( hash , rlib ) = if file. starts_with ( rlib_prefix. as_slice ( ) ) &&
199196 file. ends_with ( ".rlib" ) {
200- info ! ( "rlib candidate: {}" , path. display( ) ) ;
201- match self . try_match ( file, rlib_prefix. as_slice ( ) , ".rlib" ) {
202- Some ( hash) => {
203- info ! ( "rlib accepted, hash: {}" , hash) ;
204- let slot = candidates. find_or_insert_with ( hash, |_| {
205- ( HashSet :: new ( ) , HashSet :: new ( ) )
206- } ) ;
207- let ( ref mut rlibs, _) = * slot;
208- rlibs. insert ( fs:: realpath ( path) . unwrap ( ) ) ;
209- FileMatches
210- }
211- None => {
212- info ! ( "rlib rejected" ) ;
213- FileDoesntMatch
214- }
215- }
197+ ( file. slice ( rlib_prefix. len ( ) , file. len ( ) - ".rlib" . len ( ) ) ,
198+ true )
216199 } else if dypair. map_or ( false , |( _, suffix) | {
217200 file. starts_with ( dylib_prefix. get_ref ( ) . as_slice ( ) ) &&
218201 file. ends_with ( suffix)
219202 } ) {
220203 let ( _, suffix) = dypair. unwrap ( ) ;
221204 let dylib_prefix = dylib_prefix. get_ref ( ) . as_slice ( ) ;
222- info ! ( "dylib candidate: {}" , path. display( ) ) ;
223- match self . try_match ( file, dylib_prefix, suffix) {
224- Some ( hash) => {
225- info ! ( "dylib accepted, hash: {}" , hash) ;
226- let slot = candidates. find_or_insert_with ( hash, |_| {
227- ( HashSet :: new ( ) , HashSet :: new ( ) )
228- } ) ;
229- let ( _, ref mut dylibs) = * slot;
230- dylibs. insert ( fs:: realpath ( path) . unwrap ( ) ) ;
231- FileMatches
232- }
233- None => {
234- info ! ( "dylib rejected" ) ;
235- FileDoesntMatch
236- }
237- }
205+ ( file. slice ( dylib_prefix. len ( ) , file. len ( ) - suffix. len ( ) ) ,
206+ false )
207+ } else {
208+ return FileDoesntMatch
209+ } ;
210+ info ! ( "lib candidate: {}" , path. display( ) ) ;
211+ let slot = candidates. find_or_insert_with ( hash. to_string ( ) , |_| {
212+ ( HashSet :: new ( ) , HashSet :: new ( ) )
213+ } ) ;
214+ let ( ref mut rlibs, ref mut dylibs) = * slot;
215+ if rlib {
216+ rlibs. insert ( fs:: realpath ( path) . unwrap ( ) ) ;
238217 } else {
239- FileDoesntMatch
218+ dylibs . insert ( fs :: realpath ( path ) . unwrap ( ) ) ;
240219 }
220+ FileMatches
241221 } ) ;
242222
243223 // We have now collected all known libraries into a set of candidates
@@ -274,7 +254,7 @@ impl<'a> Context<'a> {
274254 _ => {
275255 self . sess . span_err ( self . span ,
276256 format ! ( "multiple matching crates for `{}`" ,
277- self . crate_id . name ) . as_slice ( ) ) ;
257+ self . crate_name ) . as_slice ( ) ) ;
278258 self . sess . note ( "candidates:" ) ;
279259 for lib in libraries. iter ( ) {
280260 match lib. dylib {
@@ -292,50 +272,14 @@ impl<'a> Context<'a> {
292272 None => { }
293273 }
294274 let data = lib. metadata . as_slice ( ) ;
295- let crate_id = decoder:: get_crate_id ( data) ;
296- note_crateid_attr ( self . sess . diagnostic ( ) , & crate_id ) ;
275+ let name = decoder:: get_crate_name ( data) ;
276+ note_crate_name ( self . sess . diagnostic ( ) , name . as_slice ( ) ) ;
297277 }
298278 None
299279 }
300280 }
301281 }
302282
303- // Attempts to match the requested version of a library against the file
304- // specified. The prefix/suffix are specified (disambiguates between
305- // rlib/dylib).
306- //
307- // The return value is `None` if `file` doesn't look like a rust-generated
308- // library, or if a specific version was requested and it doesn't match the
309- // apparent file's version.
310- //
311- // If everything checks out, then `Some(hash)` is returned where `hash` is
312- // the listed hash in the filename itself.
313- fn try_match ( & self , file : & str , prefix : & str , suffix : & str ) -> Option < String > {
314- let middle = file. slice ( prefix. len ( ) , file. len ( ) - suffix. len ( ) ) ;
315- debug ! ( "matching -- {}, middle: {}" , file, middle) ;
316- let mut parts = middle. splitn ( '-' , 1 ) ;
317- let hash = match parts. next ( ) { Some ( h) => h, None => return None } ;
318- debug ! ( "matching -- {}, hash: {} (want {})" , file, hash, self . id_hash) ;
319- let vers = match parts. next ( ) { Some ( v) => v, None => return None } ;
320- debug ! ( "matching -- {}, vers: {} (want {})" , file, vers,
321- self . crate_id. version) ;
322- match self . crate_id . version {
323- Some ( ref version) if version. as_slice ( ) != vers => return None ,
324- Some ( ..) => { } // check the hash
325-
326- // hash is irrelevant, no version specified
327- None => return Some ( hash. to_string ( ) )
328- }
329- debug ! ( "matching -- {}, vers ok" , file) ;
330- // hashes in filenames are prefixes of the "true hash"
331- if self . id_hash == hash. as_slice ( ) {
332- debug ! ( "matching -- {}, hash ok" , file) ;
333- Some ( hash. to_string ( ) )
334- } else {
335- None
336- }
337- }
338-
339283 // Attempts to extract *one* library from the set `m`. If the set has no
340284 // elements, `None` is returned. If the set has more than one element, then
341285 // the errors and notes are emitted about the set of libraries.
@@ -382,7 +326,7 @@ impl<'a> Context<'a> {
382326 format ! ( "multiple {} candidates for `{}` \
383327 found",
384328 flavor,
385- self . crate_id . name ) . as_slice ( ) ) ;
329+ self . crate_name ) . as_slice ( ) ) ;
386330 self . sess . span_note ( self . span ,
387331 format ! ( r"candidate #1: {}" ,
388332 ret. get_ref( )
@@ -404,9 +348,9 @@ impl<'a> Context<'a> {
404348 }
405349
406350 fn crate_matches ( & mut self , crate_data : & [ u8 ] , libpath : & Path ) -> bool {
407- match decoder:: maybe_get_crate_id ( crate_data) {
408- Some ( ref id ) if self . crate_id . matches ( id ) => { }
409- _ => { info ! ( "Rejecting via crate_id " ) ; return false }
351+ match decoder:: maybe_get_crate_name ( crate_data) {
352+ Some ( ref name ) if self . crate_name == name . as_slice ( ) => { }
353+ _ => { info ! ( "Rejecting via crate name " ) ; return false }
410354 }
411355 let hash = match decoder:: maybe_get_crate_hash ( crate_data) {
412356 Some ( hash) => hash, None => {
@@ -415,7 +359,10 @@ impl<'a> Context<'a> {
415359 }
416360 } ;
417361
418- let triple = decoder:: get_crate_triple ( crate_data) ;
362+ let triple = match decoder:: get_crate_triple ( crate_data) {
363+ None => { debug ! ( "triple not present" ) ; return false }
364+ Some ( t) => t,
365+ } ;
419366 if triple. as_slice ( ) != self . triple {
420367 info ! ( "Rejecting via crate triple: expected {} got {}" , self . triple, triple) ;
421368 self . rejected_via_triple . push ( CrateMismatch {
@@ -458,8 +405,8 @@ impl<'a> Context<'a> {
458405
459406}
460407
461- pub fn note_crateid_attr ( diag : & SpanHandler , crateid : & CrateId ) {
462- diag. handler ( ) . note ( format ! ( "crate_id : {}" , crateid . to_str ( ) ) . as_slice ( ) ) ;
408+ pub fn note_crate_name ( diag : & SpanHandler , name : & str ) {
409+ diag. handler ( ) . note ( format ! ( "crate name : {}" , name ) . as_slice ( ) ) ;
463410}
464411
465412impl ArchiveMetadata {
0 commit comments