Skip to content

Commit e92bdb9

Browse files
committed
Specify output filenames for compatibility with Windows
1 parent 9a2f02d commit e92bdb9

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

src/librustc_driver/driver.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn compile_input(trans: Box<TransCrate>,
142142
)?
143143
};
144144

145-
let output_paths = generated_output_paths(sess, &outputs, &crate_name);
145+
let output_paths = generated_output_paths(sess, &outputs, output.is_some(), &crate_name);
146146

147147
// Ensure the source file isn't accidentally overwritten during compilation.
148148
if let Some(ref input_path) = *input_path {
@@ -1111,16 +1111,19 @@ fn escape_dep_filename(filename: &FileName) -> String {
11111111
// Returns all the paths that correspond to generated files.
11121112
fn generated_output_paths(sess: &Session,
11131113
outputs: &OutputFilenames,
1114+
exact_name: bool,
11141115
crate_name: &str) -> Vec<PathBuf> {
11151116
let mut out_filenames = Vec::new();
11161117
for output_type in sess.opts.output_types.keys() {
11171118
let file = outputs.path(*output_type);
11181119
match *output_type {
1119-
OutputType::Exe => {
1120-
for output in sess.crate_types.borrow().iter() {
1120+
// If the filename has been overridden using `-o`, it will not be modified
1121+
// by appending `.rlib`, `.exe`, etc., so we can skip this transformation.
1122+
OutputType::Exe if !exact_name => {
1123+
for crate_type in sess.crate_types.borrow().iter() {
11211124
let p = ::rustc_trans_utils::link::filename_for_input(
11221125
sess,
1123-
*output,
1126+
*crate_type,
11241127
crate_name,
11251128
outputs
11261129
);
@@ -1376,10 +1379,10 @@ pub fn build_output_filenames(input: &Input,
13761379
Some(out_file.clone())
13771380
};
13781381
if *odir != None {
1379-
sess.warn("ignoring --out-dir flag due to -o flag.");
1382+
sess.warn("ignoring --out-dir flag due to -o flag");
13801383
}
13811384
if !sess.opts.cg.extra_filename.is_empty() {
1382-
sess.warn("ignoring -C extra-filename flag due to -o flag.");
1385+
sess.warn("ignoring -C extra-filename flag due to -o flag");
13831386
}
13841387

13851388
let cur_dir = Path::new("");

src/test/run-make/output-filename-conflicts-with-directory/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
all:
44
cp foo.rs $(TMPDIR)/foo.rs
55
mkdir $(TMPDIR)/foo
6-
$(RUSTC) $(TMPDIR)/foo.rs 2>&1 \
6+
$(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo 2>&1 \
77
| $(CGREP) -e "the generated executable for the input file \".*foo\.rs\" conflicts with the existing directory \".*foo\""

src/test/run-make/output-filename-conflicts-with-directory/foo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

src/test/run-make/output-filename-overwrites-input/Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
all:
44
cp foo.rs $(TMPDIR)/foo
5-
$(RUSTC) $(TMPDIR)/foo 2>&1 \
5+
$(RUSTC) $(TMPDIR)/foo -o $(TMPDIR)/foo 2>&1 \
66
| $(CGREP) -e "the input file \".*foo\" would be overwritten by the generated executable"
7+
cp bar.rs $(TMPDIR)/bar.rlib
8+
$(RUSTC) $(TMPDIR)/bar.rlib -o $(TMPDIR)/bar.rlib 2>&1 \
9+
| $(CGREP) -e "the input file \".*bar.rlib\" would be overwritten by the generated executable"
710
$(RUSTC) foo.rs 2>&1 && $(RUSTC) -Z ls $(TMPDIR)/foo 2>&1
811
cp foo.rs $(TMPDIR)/foo.rs
912
$(RUSTC) $(TMPDIR)/foo.rs -o $(TMPDIR)/foo.rs 2>&1 \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type = "lib"]

src/test/run-make/output-filename-overwrites-input/foo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//

0 commit comments

Comments
 (0)