Skip to content

Parse escaped spaces in makefile dependencies #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/cargo/ops/cargo_rustc/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,18 @@ fn calculate_target_fresh(pkg: &Package, dep_info: &Path) -> CargoResult<bool> {
}));
let deps = line.slice_from(pos + 2);

for file in deps.split(' ').map(|s| s.trim()).filter(|s| !s.is_empty()) {
match fs::stat(&pkg.get_root().join(file)) {
let mut deps = deps.split(' ').map(|s| s.trim()).filter(|s| !s.is_empty());
loop {
let mut file = match deps.next() {
Some(s) => s.to_string(),
None => break,
};
while file.as_slice().ends_with("\\") {
Copy link
Member

Choose a reason for hiding this comment

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

What about foo\\ bar? (I.e. theoretically that's two deps foo\ and bar.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently it looks like a backslash doesn't need escaping in makefiles:

$ touch foo\\.c
$ gcc foo\\.c -MMD
$ cat foo\\.d
foo\.o: foo\.c

I do think that this conversion is a little lossy, but I also think that it correctly parses any rustc-generated dependency file.

file.pop();
file.push(' ');
file.push_str(deps.next().unwrap())
}
match fs::stat(&pkg.get_root().join(file.as_slice())) {
Ok(stat) if stat.modified <= mtime => {}
Ok(stat) => {
debug!("stale: {} -- {} vs {}", file, stat.modified, mtime);
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,3 +1643,22 @@ test!(dep_no_libs {
.with_stderr("\
Package `bar v0.0.0 ([..])` has no library targets"));
})

test!(recompile_space_in_name {
let foo = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.0"
authors = []

[lib]
name = "foo"
path = "src/my lib.rs"
"#)
.file("src/my lib.rs", "");
assert_that(foo.cargo_process("build"), execs().with_status(0));
foo.root().move_into_the_past().assert();
assert_that(foo.process(cargo_dir().join("cargo")).arg("build"),
execs().with_status(0).with_stdout(""));
})