Skip to content

Commit 20cbba7

Browse files
committed
Auto merge of #29945 - nrc:save-crate-name, r=alexcrichton
r? @alexcrichton This prevents outputting csv files with the same name and thus overwriting each other when indexing Cargo projects with a bin crate (and some other cases).
2 parents 6a6b97c + de8467c commit 20cbba7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustc_trans/save/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ use std::fs::{self, File};
1717
use std::path::{Path, PathBuf};
1818

1919
use rustc_front;
20-
use rustc::front::map::NodeItem;
2120
use rustc_front::{hir, lowering};
21+
use rustc::front::map::NodeItem;
22+
use rustc::session::config::CrateType::CrateTypeExecutable;
2223

2324
use syntax::ast::{self, NodeId};
2425
use syntax::ast_util;
@@ -744,7 +745,14 @@ pub fn process_crate<'l, 'tcx>(tcx: &'l ty::ctxt<'tcx>,
744745
}
745746

746747
// Create output file.
747-
let mut out_name = cratename.to_owned();
748+
let executable = tcx.sess.crate_types.borrow().iter().any(|ct| *ct == CrateTypeExecutable);
749+
let mut out_name = if executable {
750+
"".to_owned()
751+
} else {
752+
"lib".to_owned()
753+
};
754+
out_name.push_str(&cratename);
755+
out_name.push_str(&tcx.sess.opts.cg.extra_filename);
748756
out_name.push_str(".csv");
749757
root_path.push(&out_name);
750758
let output_file = match File::create(&root_path) {

0 commit comments

Comments
 (0)