Skip to content

Commit 15c8b51

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 2ce2be8 commit 15c8b51

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
@@ -1023,7 +1023,26 @@ impl Build {
10231023

10241024
let mut objects = Vec::new();
10251025
for file in self.files.iter() {
1026-
let obj = dst.join(file).with_extension("o");
1026+
let obj = if file.has_root() {
1027+
// If `file` is an absolute path, try to remove the part
1028+
// common with the destination directory, and graft the
1029+
// remaining part. Most common outcome would be removal
1030+
// of the home directory, next common - removal of the root
1031+
// directory.
1032+
let mut pre = dst.components();
1033+
let mut dst = dst.clone();
1034+
for comp in file.components() {
1035+
if comp != pre.next().unwrap_or(Component::CurDir) {
1036+
match comp {
1037+
Component::Normal(c) => dst.push(c),
1038+
_ => (),
1039+
};
1040+
}
1041+
}
1042+
dst.with_extension("o")
1043+
} else {
1044+
dst.join(file).with_extension("o")
1045+
};
10271046
let obj = if !obj.starts_with(&dst) {
10281047
dst.join(obj.file_name().ok_or_else(|| {
10291048
Error::new(ErrorKind::IOError, "Getting object file details failed.")

0 commit comments

Comments
 (0)