Skip to content

Commit

Permalink
Don't graft subdirectories, rely solely on source directory hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dot-asm committed Jul 26, 2022
1 parent a377265 commit 1bf8899
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/lib.rs
Expand Up @@ -971,23 +971,8 @@ impl Build {
let mut objects = Vec::new();
for file in self.files.iter() {
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),
_ => (),
};
}
}
// ... and prefix the `basename` with the `dirname`'s hash
// to ensure name uniqueness.
// If `file` is an absolute path, prefix the `basename`
// with the `dirname`'s hash to ensure name uniqueness.
let basename = file
.file_name()
.ok_or_else(|| Error::new(ErrorKind::InvalidArgument, "file_name() failure"))?
Expand All @@ -998,10 +983,8 @@ impl Build {
.to_string_lossy();
let mut hasher = hash_map::DefaultHasher::new();
hasher.write(dirname.to_string().as_bytes());
if dst.pop() {
dst.push(format!("{:016x}-{}", hasher.finish(), basename));
}
dst.with_extension("o")
dst.join(format!("{:016x}-{}", hasher.finish(), basename))
.with_extension("o")
} else {
dst.join(file).with_extension("o")
};
Expand Down

0 comments on commit 1bf8899

Please sign in to comment.