auto merge of #11215 : alexcrichton/rust/metadata-filename, r=pcwalton

Right now if you have concurrent builds of two libraries in the same directory
(such as rustc's bootstrapping process), it's possible that two libraries will
stomp over each others' metadata, producing corrupt rlibs.

By placing the metadata file in a tempdir we're guranteed to not conflict with
ay other builds happening concurrently. Normally this isn't a problem because
output filenames are scoped to the name of the crate, but metadata is special in
that it has the same name across all crates.
This commit is contained in:
bors 2013-12-31 22:26:55 -08:00
commit 03b510297c
1 changed files with 5 additions and 2 deletions

View File

@ -879,8 +879,11 @@ fn link_rlib(sess: Session,
match trans {
Some(trans) => {
// Instead of putting the metadata in an object file section, rlibs
// contain the metadata in a separate file.
let metadata = obj_filename.with_filename(METADATA_FILENAME);
// contain the metadata in a separate file. We use a temp directory
// here so concurrent builds in the same directory don't try to use
// the same filename for metadata (stomping over one another)
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
let metadata = tmpdir.path().join(METADATA_FILENAME);
fs::File::create(&metadata).write(trans.metadata);
a.add_file(&metadata, false);
fs::unlink(&metadata);