Skip to content

Commit 5127304

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 53fb72c commit 5127304

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
@@ -969,7 +969,26 @@ impl Build {
969969

970970
let mut objects = Vec::new();
971971
for file in self.files.iter() {
972-
let obj = dst.join(file).with_extension("o");
972+
let obj = if file.has_root() {
973+
// If `file` is an absolute path, try to remove the part
974+
// common with the destination directory, and graft the
975+
// remaining part. Most common outcome would be removal
976+
// of the home directory, next common - removal of the root
977+
// directory.
978+
let mut pre = dst.components();
979+
let mut dst = dst.clone();
980+
for comp in file.components() {
981+
if comp != pre.next().unwrap_or(Component::CurDir) {
982+
match comp {
983+
Component::Normal(c) => dst.push(c),
984+
_ => (),
985+
};
986+
}
987+
}
988+
dst.with_extension("o")
989+
} else {
990+
dst.join(file).with_extension("o")
991+
};
973992
let obj = if !obj.starts_with(&dst) {
974993
dst.join(obj.file_name().ok_or_else(|| {
975994
Error::new(ErrorKind::IOError, "Getting object file details failed.")

0 commit comments

Comments
 (0)