@@ -21,8 +21,6 @@ use metadata::filesearch::{FileSearch, FileMatches, FileDoesntMatch};
21
21
use syntax:: abi;
22
22
use syntax:: codemap:: Span ;
23
23
use syntax:: diagnostic:: SpanHandler ;
24
- use syntax:: crateid:: CrateId ;
25
- use syntax:: attr:: AttrMetaMethods ;
26
24
use util:: fs;
27
25
28
26
use std:: c_str:: ToCStr ;
@@ -61,8 +59,7 @@ pub struct Context<'a> {
61
59
pub sess : & ' a Session ,
62
60
pub span : Span ,
63
61
pub ident : & ' a str ,
64
- pub crate_id : & ' a CrateId ,
65
- pub id_hash : & ' a str ,
62
+ pub crate_name : & ' a str ,
66
63
pub hash : Option < & ' a Svh > ,
67
64
pub triple : & ' a str ,
68
65
pub os : abi:: Os ,
@@ -171,15 +168,15 @@ impl<'a> Context<'a> {
171
168
172
169
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
173
170
let dylib_prefix = dypair. map ( |( prefix, _) | {
174
- format ! ( "{}{}- " , prefix, self . crate_id . name )
171
+ format ! ( "{}{}" , prefix, self . crate_name )
175
172
} ) ;
176
- let rlib_prefix = format ! ( "lib{}- " , self . crate_id . name ) ;
173
+ let rlib_prefix = format ! ( "lib{}" , self . crate_name ) ;
177
174
178
175
let mut candidates = HashMap :: new ( ) ;
179
176
180
177
// First, find all possible candidate rlibs and dylibs purely based on
181
178
// 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.
183
180
//
184
181
// During this step, we can filter all found libraries based on the
185
182
// name and id found in the crate id (we ignore the path portion for
@@ -195,49 +192,32 @@ impl<'a> Context<'a> {
195
192
None => return FileDoesntMatch ,
196
193
Some ( file) => file,
197
194
} ;
198
- if file. starts_with ( rlib_prefix. as_slice ( ) ) &&
195
+ let ( hash , rlib ) = if file. starts_with ( rlib_prefix. as_slice ( ) ) &&
199
196
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 )
216
199
} else if dypair. map_or ( false , |( _, suffix) | {
217
200
file. starts_with ( dylib_prefix. get_ref ( ) . as_slice ( ) ) &&
218
201
file. ends_with ( suffix)
219
202
} ) {
220
203
let ( _, suffix) = dypair. unwrap ( ) ;
221
204
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 ( ) ) ;
238
217
} else {
239
- FileDoesntMatch
218
+ dylibs . insert ( fs :: realpath ( path ) . unwrap ( ) ) ;
240
219
}
220
+ FileMatches
241
221
} ) ;
242
222
243
223
// We have now collected all known libraries into a set of candidates
@@ -274,7 +254,7 @@ impl<'a> Context<'a> {
274
254
_ => {
275
255
self . sess . span_err ( self . span ,
276
256
format ! ( "multiple matching crates for `{}`" ,
277
- self . crate_id . name ) . as_slice ( ) ) ;
257
+ self . crate_name ) . as_slice ( ) ) ;
278
258
self . sess . note ( "candidates:" ) ;
279
259
for lib in libraries. iter ( ) {
280
260
match lib. dylib {
@@ -292,50 +272,14 @@ impl<'a> Context<'a> {
292
272
None => { }
293
273
}
294
274
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 ( ) ) ;
297
277
}
298
278
None
299
279
}
300
280
}
301
281
}
302
282
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
-
339
283
// Attempts to extract *one* library from the set `m`. If the set has no
340
284
// elements, `None` is returned. If the set has more than one element, then
341
285
// the errors and notes are emitted about the set of libraries.
@@ -382,7 +326,7 @@ impl<'a> Context<'a> {
382
326
format ! ( "multiple {} candidates for `{}` \
383
327
found",
384
328
flavor,
385
- self . crate_id . name ) . as_slice ( ) ) ;
329
+ self . crate_name ) . as_slice ( ) ) ;
386
330
self . sess . span_note ( self . span ,
387
331
format ! ( r"candidate #1: {}" ,
388
332
ret. get_ref( )
@@ -404,9 +348,9 @@ impl<'a> Context<'a> {
404
348
}
405
349
406
350
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 }
410
354
}
411
355
let hash = match decoder:: maybe_get_crate_hash ( crate_data) {
412
356
Some ( hash) => hash, None => {
@@ -415,7 +359,10 @@ impl<'a> Context<'a> {
415
359
}
416
360
} ;
417
361
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
+ } ;
419
366
if triple. as_slice ( ) != self . triple {
420
367
info ! ( "Rejecting via crate triple: expected {} got {}" , self . triple, triple) ;
421
368
self . rejected_via_triple . push ( CrateMismatch {
@@ -458,8 +405,8 @@ impl<'a> Context<'a> {
458
405
459
406
}
460
407
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 ( ) ) ;
463
410
}
464
411
465
412
impl ArchiveMetadata {
0 commit comments