@@ -192,7 +192,7 @@ pub fn link_binary(sess: &Session,
192
192
for & crate_type in sess. crate_types . borrow ( ) . iter ( ) {
193
193
// Ignore executable crates if we have -Z no-trans, as they will error.
194
194
if ( sess. opts . debugging_opts . no_trans ||
195
- sess. opts . output_types . contains_key ( & OutputType :: Metadata ) ) &&
195
+ ! sess. opts . output_types . should_trans ( ) ) &&
196
196
crate_type == config:: CrateTypeExecutable {
197
197
continue ;
198
198
}
@@ -201,13 +201,13 @@ pub fn link_binary(sess: &Session,
201
201
bug ! ( "invalid output type `{:?}` for target os `{}`" ,
202
202
crate_type, sess. opts. target_triple) ;
203
203
}
204
- let out_file = link_binary_output ( sess, trans, crate_type, outputs, crate_name) ;
205
- out_filenames. push ( out_file ) ;
204
+ let mut out_files = link_binary_output ( sess, trans, crate_type, outputs, crate_name) ;
205
+ out_filenames. append ( & mut out_files ) ;
206
206
}
207
207
208
208
// Remove the temporary object file and metadata if we aren't saving temps
209
209
if !sess. opts . cg . save_temps {
210
- if ! sess. opts . output_types . contains_key ( & OutputType :: Metadata ) {
210
+ if sess. opts . output_types . should_trans ( ) {
211
211
for obj in object_filenames ( trans, outputs) {
212
212
remove ( sess, & obj) ;
213
213
}
@@ -256,16 +256,21 @@ fn is_writeable(p: &Path) -> bool {
256
256
}
257
257
}
258
258
259
+ fn filename_for_metadata ( sess : & Session , crate_name : & str , outputs : & OutputFilenames ) -> PathBuf {
260
+ let out_filename = outputs. single_output_file . clone ( )
261
+ . unwrap_or ( outputs
262
+ . out_directory
263
+ . join ( & format ! ( "lib{}{}.rmeta" , crate_name, sess. opts. cg. extra_filename) ) ) ;
264
+ check_file_is_writeable ( & out_filename, sess) ;
265
+ out_filename
266
+ }
267
+
259
268
pub fn filename_for_input ( sess : & Session ,
260
269
crate_type : config:: CrateType ,
261
270
crate_name : & str ,
262
271
outputs : & OutputFilenames ) -> PathBuf {
263
272
let libname = format ! ( "{}{}" , crate_name, sess. opts. cg. extra_filename) ;
264
273
265
- if outputs. outputs . contains_key ( & OutputType :: Metadata ) {
266
- return outputs. out_directory . join ( & format ! ( "lib{}.rmeta" , libname) ) ;
267
- }
268
-
269
274
match crate_type {
270
275
config:: CrateTypeRlib => {
271
276
outputs. out_directory . join ( & format ! ( "lib{}.rlib" , libname) )
@@ -327,37 +332,58 @@ pub fn each_linked_rlib(sess: &Session,
327
332
}
328
333
}
329
334
335
+ fn out_filename ( sess : & Session ,
336
+ crate_type : config:: CrateType ,
337
+ outputs : & OutputFilenames ,
338
+ crate_name : & str )
339
+ -> PathBuf {
340
+ let default_filename = filename_for_input ( sess, crate_type, crate_name, outputs) ;
341
+ let out_filename = outputs. outputs . get ( & OutputType :: Exe )
342
+ . and_then ( |s| s. to_owned ( ) )
343
+ . or_else ( || outputs. single_output_file . clone ( ) )
344
+ . unwrap_or ( default_filename) ;
345
+
346
+ check_file_is_writeable ( & out_filename, sess) ;
347
+
348
+ out_filename
349
+ }
350
+
351
+ // Make sure files are writeable. Mac, FreeBSD, and Windows system linkers
352
+ // check this already -- however, the Linux linker will happily overwrite a
353
+ // read-only file. We should be consistent.
354
+ fn check_file_is_writeable ( file : & Path , sess : & Session ) {
355
+ if !is_writeable ( file) {
356
+ sess. fatal ( & format ! ( "output file {} is not writeable -- check its \
357
+ permissions", file. display( ) ) ) ;
358
+ }
359
+ }
360
+
330
361
fn link_binary_output ( sess : & Session ,
331
362
trans : & CrateTranslation ,
332
363
crate_type : config:: CrateType ,
333
364
outputs : & OutputFilenames ,
334
- crate_name : & str ) -> PathBuf {
365
+ crate_name : & str ) -> Vec < PathBuf > {
335
366
let objects = object_filenames ( trans, outputs) ;
336
- let default_filename = filename_for_input ( sess, crate_type, crate_name,
337
- outputs) ;
338
- let out_filename = outputs. outputs . get ( & OutputType :: Exe )
339
- . and_then ( |s| s. to_owned ( ) )
340
- . or_else ( || outputs. single_output_file . clone ( ) )
341
- . unwrap_or ( default_filename) ;
342
367
343
- // Make sure files are writeable. Mac, FreeBSD, and Windows system linkers
344
- // check this already -- however, the Linux linker will happily overwrite a
345
- // read-only file. We should be consistent.
346
- for file in objects. iter ( ) . chain ( Some ( & out_filename) ) {
347
- if !is_writeable ( file) {
348
- sess. fatal ( & format ! ( "output file {} is not writeable -- check its \
349
- permissions", file. display( ) ) ) ;
350
- }
368
+ for file in & objects {
369
+ check_file_is_writeable ( file, sess) ;
351
370
}
352
371
353
372
let tmpdir = match TempDir :: new ( "rustc" ) {
354
373
Ok ( tmpdir) => tmpdir,
355
374
Err ( err) => sess. fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ,
356
375
} ;
357
376
377
+ let mut out_filenames = vec ! [ ] ;
378
+
358
379
if outputs. outputs . contains_key ( & OutputType :: Metadata ) {
380
+ let out_filename = filename_for_metadata ( sess, crate_name, outputs) ;
359
381
emit_metadata ( sess, trans, & out_filename) ;
360
- } else {
382
+ out_filenames. push ( out_filename) ;
383
+ }
384
+
385
+ if outputs. outputs . should_trans ( ) {
386
+ let out_filename = out_filename ( sess, crate_type, outputs, crate_name) ;
361
387
match crate_type {
362
388
config:: CrateTypeRlib => {
363
389
link_rlib ( sess, Some ( trans) , & objects, & out_filename,
@@ -371,9 +397,10 @@ fn link_binary_output(sess: &Session,
371
397
outputs, tmpdir. path ( ) ) ;
372
398
}
373
399
}
400
+ out_filenames. push ( out_filename) ;
374
401
}
375
402
376
- out_filename
403
+ out_filenames
377
404
}
378
405
379
406
fn object_filenames ( trans : & CrateTranslation ,
0 commit comments