Skip to content

Commit 2883b76

Browse files
committed
Make --dep-info escape spaces in filenames
Closes #17627
1 parent 8dab56e commit 2883b76

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

src/librustc/driver/driver.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,12 @@ pub fn stop_after_phase_5(sess: &Session) -> bool {
615615
return false;
616616
}
617617

618+
fn escape_dep_filename(filename: &str) -> String {
619+
// Apparently clang and gcc *only* escape spaces:
620+
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
621+
filename.replace(" ", "\\ ")
622+
}
623+
618624
fn write_out_deps(sess: &Session,
619625
input: &Input,
620626
outputs: &OutputFilenames,
@@ -658,7 +664,7 @@ fn write_out_deps(sess: &Session,
658664
// write Makefile-compatible dependency rules
659665
let files: Vec<String> = sess.codemap().files.borrow()
660666
.iter().filter(|fmap| fmap.is_real_file())
661-
.map(|fmap| fmap.name.to_string())
667+
.map(|fmap| escape_dep_filename(fmap.name.as_slice()))
662668
.collect();
663669
let mut file = try!(io::File::create(&deps_filename));
664670
for path in out_filenames.iter() {
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-include ../tools.mk
2+
3+
# FIXME: ignore freebsd/windows
4+
# (windows: see `../dep-info/Makefile`)
5+
ifneq ($(shell uname),FreeBSD)
6+
ifndef IS_WINDOWS
7+
all:
8+
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
9+
sleep 1
10+
touch 'foo foo.rs'
11+
-rm -f $(TMPDIR)/done
12+
$(MAKE) -drf Makefile.foo
13+
rm $(TMPDIR)/done
14+
pwd
15+
$(MAKE) -drf Makefile.foo
16+
rm $(TMPDIR)/done && exit 1 || exit 0
17+
else
18+
all:
19+
20+
endif
21+
22+
else
23+
all:
24+
25+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
LIB := $(shell $(RUSTC) --print-file-name --crate-type=lib lib.rs)
2+
3+
$(TMPDIR)/$(LIB):
4+
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
5+
touch $(TMPDIR)/done
6+
7+
-include $(TMPDIR)/custom-deps-file.d
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 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+
pub fn bar() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 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+
pub fn foo() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 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+
#[path="foo foo.rs"]
12+
pub mod foo;
13+
14+
pub mod bar;

0 commit comments

Comments
 (0)