@@ -138,7 +138,7 @@ fn default_native_lib_naming(sess: session::session, static: bool) ->
138
138
}
139
139
}
140
140
141
- fn find_library_crate( sess: session:: session,
141
+ fn find_library_crate( sess: session:: session, span : span ,
142
142
metas: [ @ast:: meta_item] )
143
143
-> option<{ ident: str , data: @[ u8] } > {
144
144
@@ -163,15 +163,16 @@ fn find_library_crate(sess: session::session,
163
163
164
164
let nn = default_native_lib_naming ( sess, sess. opts . static ) ;
165
165
let x =
166
- find_library_crate_aux ( sess, nn, crate_name,
166
+ find_library_crate_aux ( sess, span , nn, crate_name,
167
167
metas, sess. filesearch ) ;
168
168
if x != none || sess. opts . static { ret x; }
169
169
let nn2 = default_native_lib_naming ( sess, true ) ;
170
- ret find_library_crate_aux ( sess, nn2, crate_name, metas,
170
+ ret find_library_crate_aux ( sess, span , nn2, crate_name, metas,
171
171
sess. filesearch ) ;
172
172
}
173
173
174
174
fn find_library_crate_aux ( sess : session:: session ,
175
+ span : span ,
175
176
nn : { prefix : str , suffix : str } ,
176
177
crate_name : str ,
177
178
metas : [ @ast:: meta_item ] ,
@@ -180,7 +181,8 @@ fn find_library_crate_aux(sess: session::session,
180
181
let prefix: str = nn. prefix + crate_name + "-" ;
181
182
let suffix: str = nn. suffix ;
182
183
183
- ret filesearch:: search ( filesearch, { |path|
184
+ let mut matches = [ ] ;
185
+ filesearch:: search ( filesearch, { |path|
184
186
#debug ( "inspecting file %s" , path) ;
185
187
let f: str = path:: basename ( path) ;
186
188
if !( str:: starts_with ( f, prefix) && str:: ends_with ( f, suffix) ) {
@@ -196,7 +198,8 @@ fn find_library_crate_aux(sess: session::session,
196
198
option:: none
197
199
} else {
198
200
#debug ( "found %s with matching metadata" , path) ;
199
- option:: some ( { ident: path, data: cvec} )
201
+ matches += [ { ident: path, data: cvec} ] ;
202
+ option:: none
200
203
}
201
204
}
202
205
_ {
@@ -206,6 +209,25 @@ fn find_library_crate_aux(sess: session::session,
206
209
}
207
210
}
208
211
} ) ;
212
+
213
+ if matches. is_empty ( ) {
214
+ none
215
+ } else if matches. len ( ) == 1 u {
216
+ some ( matches[ 0 ] )
217
+ } else {
218
+ sess. span_err (
219
+ span, #fmt ( "multiple matching crates for `%s`" , crate_name) ) ;
220
+ sess. note ( "candidates:" ) ;
221
+ for matches. each { |match|
222
+ sess. note( #fmt( "path: %s" , match. ident) ) ;
223
+ let attrs = decoder:: get_crate_attributes( match . data) ;
224
+ for attr:: find_linkage_attrs( attrs) . each { |attr|
225
+ sess. note ( #fmt ( "meta: %s" , pprust:: attr_to_str ( attr) ) ) ;
226
+ }
227
+ }
228
+ sess. abort_if_errors ( ) ;
229
+ none
230
+ }
209
231
}
210
232
211
233
fn get_metadata_section ( sess : session:: session ,
@@ -240,7 +262,7 @@ fn load_library_crate(sess: session::session, ident: ast::ident, span: span,
240
262
-> { ident: str , data: @[ u8] } {
241
263
242
264
243
- alt find_library_crate ( sess, metas) {
265
+ alt find_library_crate ( sess, span , metas) {
244
266
some ( t) { ret t; }
245
267
none {
246
268
sess. span_fatal ( span, #fmt[ "can't find crate for '%s'" , ident] ) ;
0 commit comments