Skip to content

Commit

Permalink
Fix for diffrent hashes between diffrent build paths
Browse files Browse the repository at this point in the history
when the build paths are diffrent for rust sources, the objects files genarted are having diffrent hash values for each build.

- Updated the hashing mechanism to ensure consistent hash values across different build paths.
- Addressed issues with reproducibility by normalizing directory paths before hashing, preventing discrepancies caused by varying build environments.

Signed-off-by: Harish Sadineni <[email protected]>
  • Loading branch information
Harish Sadineni authored and Harish Sadineni committed Nov 7, 2024
1 parent 2050013 commit 376de13
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ fn wait_on_child(
/// and store them in the output Object.
pub(crate) fn objects_from_files(files: &[Arc<Path>], dst: &Path) -> Result<Vec<Object>, Error> {
let mut objects = Vec::with_capacity(files.len());
let target_substring = ["rustc"];
for file in files {
let basename = file
.file_name()
Expand All @@ -308,10 +309,29 @@ pub(crate) fn objects_from_files(files: &[Arc<Path>], dst: &Path) -> Result<Vec<
})?
.to_string_lossy();

// Function to find the position of the first occurrence of the target substring
fn find_target_position(s: &str, targets: &[&str]) -> Option<usize> {
let mut pos = None;
for target in targets {
if let Some(index) = s.find(target) {
//If a target is found and pos is None, set it
if pos.is_none() || index < pos.unwrap() {
pos = Some(index);
}
}
}
pos
}
let filtered_dirname = if let Some(pos) = find_target_position(&dirname, &target_substring)
{
dirname[pos..].to_string() //Keep everything from the target substring onwards
} else {
dirname.to_string() //If target substring is not found, keep the original dirname
};
// Hash the dirname. This should prevent conflicts if we have multiple
// object files with the same filename in different subfolders.
let mut hasher = hash_map::DefaultHasher::new();
hasher.write(dirname.to_string().as_bytes());
hasher.write(filtered_dirname.as_bytes());
let obj = dst
.join(format!("{:016x}-{}", hasher.finish(), basename))
.with_extension("o");
Expand Down

0 comments on commit 376de13

Please sign in to comment.