Skip to content

Commit

Permalink
Make --dep-info escape spaces in filenames
Browse files Browse the repository at this point in the history
Closes #17627
  • Loading branch information
hydhknn committed Oct 1, 2014
1 parent 8dab56e commit 2883b76
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustc/driver/driver.rs
Expand Up @@ -615,6 +615,12 @@ pub fn stop_after_phase_5(sess: &Session) -> bool {
return false;
}

fn escape_dep_filename(filename: &str) -> String {
// Apparently clang and gcc *only* escape spaces:
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
filename.replace(" ", "\\ ")
}

fn write_out_deps(sess: &Session,
input: &Input,
outputs: &OutputFilenames,
Expand Down Expand Up @@ -658,7 +664,7 @@ fn write_out_deps(sess: &Session,
// write Makefile-compatible dependency rules
let files: Vec<String> = sess.codemap().files.borrow()
.iter().filter(|fmap| fmap.is_real_file())
.map(|fmap| fmap.name.to_string())
.map(|fmap| escape_dep_filename(fmap.name.as_slice()))
.collect();
let mut file = try!(io::File::create(&deps_filename));
for path in out_filenames.iter() {
Expand Down
25 changes: 25 additions & 0 deletions src/test/run-make/dep-info-spaces/Makefile
@@ -0,0 +1,25 @@
-include ../tools.mk

# FIXME: ignore freebsd/windows
# (windows: see `../dep-info/Makefile`)
ifneq ($(shell uname),FreeBSD)
ifndef IS_WINDOWS
all:
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
sleep 1
touch 'foo foo.rs'
-rm -f $(TMPDIR)/done
$(MAKE) -drf Makefile.foo
rm $(TMPDIR)/done
pwd
$(MAKE) -drf Makefile.foo
rm $(TMPDIR)/done && exit 1 || exit 0
else
all:

endif

else
all:

endif
7 changes: 7 additions & 0 deletions src/test/run-make/dep-info-spaces/Makefile.foo
@@ -0,0 +1,7 @@
LIB := $(shell $(RUSTC) --print-file-name --crate-type=lib lib.rs)

$(TMPDIR)/$(LIB):
$(RUSTC) --dep-info $(TMPDIR)/custom-deps-file.d --crate-type=lib lib.rs
touch $(TMPDIR)/done

-include $(TMPDIR)/custom-deps-file.d
11 changes: 11 additions & 0 deletions src/test/run-make/dep-info-spaces/bar.rs
@@ -0,0 +1,11 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn bar() {}
11 changes: 11 additions & 0 deletions src/test/run-make/dep-info-spaces/foo foo.rs
@@ -0,0 +1,11 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn foo() {}
14 changes: 14 additions & 0 deletions src/test/run-make/dep-info-spaces/lib.rs
@@ -0,0 +1,14 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[path="foo foo.rs"]
pub mod foo;

pub mod bar;

5 comments on commit 2883b76

@bors
Copy link
Contributor

@bors bors commented on 2883b76 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at jgallagher@2883b76

@bors
Copy link
Contributor

@bors bors commented on 2883b76 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jgallagher/rust/dep-info-escape-spaces = 2883b76 into auto

@bors
Copy link
Contributor

@bors bors commented on 2883b76 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jgallagher/rust/dep-info-escape-spaces = 2883b76 merged ok, testing candidate = dd7f00d

@bors
Copy link
Contributor

@bors bors commented on 2883b76 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 2883b76 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = dd7f00d

Please sign in to comment.