Skip to content

Commit d3627d7

Browse files
committed
Fix parsing of dep-info files with absolute Windows paths
1 parent b05a88b commit d3627d7

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

src/compiler/rust.rs

+44-4
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,19 @@ fn parse_dep_info<T>(dep_info: &str, cwd: T) -> Vec<String>
204204
where T: AsRef<Path>
205205
{
206206
let cwd = cwd.as_ref();
207-
let mut deps = dep_info.lines()
208-
// The first line is the dependencies on the dep file itself.
209-
.skip(1)
210-
.filter_map(|l| if l.is_empty() { None } else { l.split(":").next() })
207+
// Just parse the first line, which should have the dep-info file and all
208+
// source files.
209+
let line = match dep_info.lines().next() {
210+
None => return vec![],
211+
Some(l) => l,
212+
};
213+
let pos = match line.find(": ") {
214+
None => return vec![],
215+
Some(p) => p,
216+
};
217+
let mut deps = line[pos + 2..]
218+
.split(' ')
219+
.map(|s| s.trim()).filter(|s| !s.is_empty())
211220
.map(|s| cwd.join(s).to_string_lossy().into_owned())
212221
.collect::<Vec<_>>();
213222
deps.sort();
@@ -805,6 +814,37 @@ bar.rs:
805814
parse_dep_info(&deps, "/bar/"));
806815
}
807816

817+
#[cfg(windows)]
818+
#[test]
819+
fn test_parse_dep_info_cwd() {
820+
let deps = "foo: baz.rs abc.rs bar.rs
821+
822+
baz.rs:
823+
824+
abc.rs:
825+
826+
bar.rs:
827+
";
828+
assert_eq!(stringvec!["foo/abc.rs", "foo/bar.rs", "foo/baz.rs"],
829+
parse_dep_info(&deps, "foo/"));
830+
831+
assert_eq!(stringvec!["c:/foo/bar/abc.rs", "c:/foo/bar/bar.rs", "c:/foo/bar/baz.rs"],
832+
parse_dep_info(&deps, "c:/foo/bar/"));
833+
}
834+
835+
#[cfg(windows)]
836+
#[test]
837+
fn test_parse_dep_info_abs_paths() {
838+
let deps = "c:/foo/foo: c:/foo/baz.rs c:/foo/abc.rs c:/foo/bar.rs
839+
840+
c:/foo/baz.rs: c:/foo/bar.rs
841+
c:/foo/abc.rs:
842+
c:/foo/bar.rs:
843+
";
844+
assert_eq!(stringvec!["c:/foo/abc.rs", "c:/foo/bar.rs", "c:/foo/baz.rs"],
845+
parse_dep_info(&deps, "c:/bar/"));
846+
}
847+
808848
fn mock_dep_info(creator: &Arc<Mutex<MockCommandCreator>>, dep_srcs: &[&str])
809849
{
810850
// Mock the `rustc --emit=dep-info` process by writing

0 commit comments

Comments
 (0)