Skip to content

Commit a1a5b1f

Browse files
committed
Map source absolute paths to OUT_DIR as relative.
If a source file was specified by absolute path, then the corresponding object file was placed into OUT_DIR. This posed a problem if multiple files with the same base name were specified by absolute paths. Fixes #683.
1 parent ad1f00d commit a1a5b1f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,26 @@ impl Build {
998998

999999
let mut objects = Vec::new();
10001000
for file in self.files.iter() {
1001-
let obj = dst.join(file).with_extension("o");
1001+
let obj = if file.has_root() {
1002+
// If `file` is an absolute path, try to remove the part
1003+
// common with the destination directory, and graft the
1004+
// remaining part. Most common outcome would be removal
1005+
// of the home directory, next common - removal of the root
1006+
// directory.
1007+
let mut pre = dst.components();
1008+
let mut dst = dst.clone();
1009+
for comp in file.components() {
1010+
if comp != pre.next().unwrap_or(Component::CurDir) {
1011+
match comp {
1012+
Component::Normal(c) => dst.push(c),
1013+
_ => (),
1014+
};
1015+
}
1016+
}
1017+
dst.with_extension("o")
1018+
} else {
1019+
dst.join(file).with_extension("o")
1020+
};
10021021
let obj = if !obj.starts_with(&dst) {
10031022
dst.join(obj.file_name().ok_or_else(|| {
10041023
Error::new(ErrorKind::IOError, "Getting object file details failed.")

0 commit comments

Comments
 (0)