Skip to content

Commit

Permalink
Map source absolute paths to OUT_DIR as relative.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dot-asm committed Jul 11, 2022
1 parent 53fb72c commit 5127304
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,26 @@ impl Build {

let mut objects = Vec::new();
for file in self.files.iter() {
let obj = dst.join(file).with_extension("o");
let obj = if file.has_root() {
// If `file` is an absolute path, try to remove the part
// common with the destination directory, and graft the
// remaining part. Most common outcome would be removal
// of the home directory, next common - removal of the root
// directory.
let mut pre = dst.components();
let mut dst = dst.clone();
for comp in file.components() {
if comp != pre.next().unwrap_or(Component::CurDir) {
match comp {
Component::Normal(c) => dst.push(c),
_ => (),
};
}
}
dst.with_extension("o")
} else {
dst.join(file).with_extension("o")
};
let obj = if !obj.starts_with(&dst) {
dst.join(obj.file_name().ok_or_else(|| {
Error::new(ErrorKind::IOError, "Getting object file details failed.")
Expand Down

0 comments on commit 5127304

Please sign in to comment.