@@ -183,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> {
183
183
self . archive . slib_suffix . as_slice ( ) ,
184
184
self . archive . lib_search_paths . as_slice ( ) ,
185
185
self . archive . handler ) ;
186
- self . add_archive ( & location, name, [ ] )
186
+ self . add_archive ( & location, name, |_| false )
187
187
}
188
188
189
189
/// Adds all of the contents of the rlib at the specified path to this
@@ -193,13 +193,20 @@ impl<'a> ArchiveBuilder<'a> {
193
193
/// then the object file also isn't added.
194
194
pub fn add_rlib ( & mut self , rlib : & Path , name : & str ,
195
195
lto : bool ) -> io:: IoResult < ( ) > {
196
- let object = format ! ( "{}.o" , name) ;
197
- let bytecode = format ! ( "{}.bytecode.deflate" , name) ;
198
- let mut ignore = vec ! ( bytecode. as_slice( ) , METADATA_FILENAME ) ;
199
- if lto {
200
- ignore. push ( object. as_slice ( ) ) ;
201
- }
202
- self . add_archive ( rlib, name, ignore. as_slice ( ) )
196
+ // Ignoring obj file starting with the crate name
197
+ // as simple comparison is not enough - there
198
+ // might be also an extra name suffix
199
+ let obj_start = format ! ( "{}" , name) ;
200
+ let obj_start = obj_start. as_slice ( ) ;
201
+ // Ignoring all bytecode files, no matter of
202
+ // name
203
+ let bc_ext = ".bytecode.deflate" ;
204
+
205
+ self . add_archive ( rlib, name. as_slice ( ) , |fname : & str | {
206
+ let skip_obj = lto && fname. starts_with ( obj_start)
207
+ && fname. ends_with ( ".o" ) ;
208
+ skip_obj || fname. ends_with ( bc_ext) || fname == METADATA_FILENAME
209
+ } )
203
210
}
204
211
205
212
/// Adds an arbitrary file to this archive
@@ -273,7 +280,7 @@ impl<'a> ArchiveBuilder<'a> {
273
280
}
274
281
275
282
fn add_archive ( & mut self , archive : & Path , name : & str ,
276
- skip : & [ & str ] ) -> io:: IoResult < ( ) > {
283
+ skip: | & str| -> bool ) -> io:: IoResult < ( ) > {
277
284
let loc = TempDir :: new ( "rsar" ) . unwrap ( ) ;
278
285
279
286
// First, extract the contents of the archive to a temporary directory.
@@ -295,7 +302,7 @@ impl<'a> ArchiveBuilder<'a> {
295
302
let files = try!( fs:: readdir ( loc. path ( ) ) ) ;
296
303
for file in files. iter ( ) {
297
304
let filename = file. filename_str ( ) . unwrap ( ) ;
298
- if skip. iter ( ) . any ( |s| * s == filename) { continue }
305
+ if skip ( filename) { continue }
299
306
if filename. contains ( ".SYMDEF" ) { continue }
300
307
301
308
let filename = format ! ( "r-{}-{}" , name, filename) ;
0 commit comments