@@ -191,7 +191,8 @@ pub fn link_binary(sess: &Session,
191
191
let mut out_filenames = Vec :: new ( ) ;
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
- if sess. opts . debugging_opts . no_trans &&
194
+ if ( sess. opts . debugging_opts . no_trans ||
195
+ !sess. opts . output_types . should_trans ( ) ) &&
195
196
crate_type == config:: CrateTypeExecutable {
196
197
continue ;
197
198
}
@@ -200,15 +201,16 @@ pub fn link_binary(sess: &Session,
200
201
bug ! ( "invalid output type `{:?}` for target os `{}`" ,
201
202
crate_type, sess. opts. target_triple) ;
202
203
}
203
- let out_file = link_binary_output ( sess, trans, crate_type, outputs,
204
- 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
- for obj in object_filenames ( trans, outputs) {
211
- remove ( sess, & obj) ;
210
+ if sess. opts . output_types . should_trans ( ) {
211
+ for obj in object_filenames ( trans, outputs) {
212
+ remove ( sess, & obj) ;
213
+ }
212
214
}
213
215
remove ( sess, & outputs. with_extension ( "metadata.o" ) ) ;
214
216
}
@@ -254,18 +256,25 @@ fn is_writeable(p: &Path) -> bool {
254
256
}
255
257
}
256
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
+
257
268
pub fn filename_for_input ( sess : & Session ,
258
269
crate_type : config:: CrateType ,
259
270
crate_name : & str ,
260
271
outputs : & OutputFilenames ) -> PathBuf {
261
272
let libname = format ! ( "{}{}" , crate_name, sess. opts. cg. extra_filename) ;
273
+
262
274
match crate_type {
263
275
config:: CrateTypeRlib => {
264
276
outputs. out_directory . join ( & format ! ( "lib{}.rlib" , libname) )
265
277
}
266
- config:: CrateTypeMetadata => {
267
- outputs. out_directory . join ( & format ! ( "lib{}.rmeta" , libname) )
268
- }
269
278
config:: CrateTypeCdylib |
270
279
config:: CrateTypeProcMacro |
271
280
config:: CrateTypeDylib => {
@@ -323,52 +332,75 @@ pub fn each_linked_rlib(sess: &Session,
323
332
}
324
333
}
325
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
+
326
361
fn link_binary_output ( sess : & Session ,
327
362
trans : & CrateTranslation ,
328
363
crate_type : config:: CrateType ,
329
364
outputs : & OutputFilenames ,
330
- crate_name : & str ) -> PathBuf {
365
+ crate_name : & str ) -> Vec < PathBuf > {
331
366
let objects = object_filenames ( trans, outputs) ;
332
- let default_filename = filename_for_input ( sess, crate_type, crate_name,
333
- outputs) ;
334
- let out_filename = outputs. outputs . get ( & OutputType :: Exe )
335
- . and_then ( |s| s. to_owned ( ) )
336
- . or_else ( || outputs. single_output_file . clone ( ) )
337
- . unwrap_or ( default_filename) ;
338
367
339
- // Make sure files are writeable. Mac, FreeBSD, and Windows system linkers
340
- // check this already -- however, the Linux linker will happily overwrite a
341
- // read-only file. We should be consistent.
342
- for file in objects. iter ( ) . chain ( Some ( & out_filename) ) {
343
- if !is_writeable ( file) {
344
- sess. fatal ( & format ! ( "output file {} is not writeable -- check its \
345
- permissions", file. display( ) ) ) ;
346
- }
368
+ for file in & objects {
369
+ check_file_is_writeable ( file, sess) ;
347
370
}
348
371
349
372
let tmpdir = match TempDir :: new ( "rustc" ) {
350
373
Ok ( tmpdir) => tmpdir,
351
374
Err ( err) => sess. fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ,
352
375
} ;
353
376
354
- match crate_type {
355
- config:: CrateTypeRlib => {
356
- link_rlib ( sess, Some ( trans) , & objects, & out_filename,
357
- tmpdir. path ( ) ) . build ( ) ;
358
- }
359
- config:: CrateTypeStaticlib => {
360
- link_staticlib ( sess, & objects, & out_filename, tmpdir. path ( ) ) ;
361
- }
362
- config:: CrateTypeMetadata => {
363
- emit_metadata ( sess, trans, & out_filename) ;
364
- }
365
- _ => {
366
- link_natively ( sess, crate_type, & objects, & out_filename, trans,
367
- outputs, tmpdir. path ( ) ) ;
377
+ let mut out_filenames = vec ! [ ] ;
378
+
379
+ if outputs. outputs . contains_key ( & OutputType :: Metadata ) {
380
+ let out_filename = filename_for_metadata ( sess, crate_name, outputs) ;
381
+ emit_metadata ( sess, trans, & out_filename) ;
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) ;
387
+ match crate_type {
388
+ config:: CrateTypeRlib => {
389
+ link_rlib ( sess, Some ( trans) , & objects, & out_filename,
390
+ tmpdir. path ( ) ) . build ( ) ;
391
+ }
392
+ config:: CrateTypeStaticlib => {
393
+ link_staticlib ( sess, & objects, & out_filename, tmpdir. path ( ) ) ;
394
+ }
395
+ _ => {
396
+ link_natively ( sess, crate_type, & objects, & out_filename, trans,
397
+ outputs, tmpdir. path ( ) ) ;
398
+ }
368
399
}
400
+ out_filenames. push ( out_filename) ;
369
401
}
370
402
371
- out_filename
403
+ out_filenames
372
404
}
373
405
374
406
fn object_filenames ( trans : & CrateTranslation ,
0 commit comments