Skip to content

Commit a8aaf8b

Browse files
Harish SadineniHarish Sadineni
Harish Sadineni
authored and
Harish Sadineni
committed
Fix for diffrent hashes between diffrent build paths
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 <Harish.Sadineni@windriver.com>
1 parent 2050013 commit a8aaf8b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/command_helpers.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ fn wait_on_child(
288288
/// and store them in the output Object.
289289
pub(crate) fn objects_from_files(files: &[Arc<Path>], dst: &Path) -> Result<Vec<Object>, Error> {
290290
let mut objects = Vec::with_capacity(files.len());
291+
let target_substring = ["rustc"];
291292
for file in files {
292293
let basename = file
293294
.file_name()
@@ -308,10 +309,29 @@ pub(crate) fn objects_from_files(files: &[Arc<Path>], dst: &Path) -> Result<Vec<
308309
})?
309310
.to_string_lossy();
310311

312+
// Function to find the position of the first occurrence of the target substring
313+
fn find_target_position(s: &str, targets: &[&str]) -> Option<usize> {
314+
let mut pos = None;
315+
for target in targets {
316+
if let Some(index) = s.find(target) {
317+
//If a target is found and pos is None, set it
318+
if pos.is_none() || index < pos.unwrap() {
319+
pos = Some(index);
320+
}
321+
}
322+
}
323+
pos
324+
}
325+
326+
let filtered_dirname = if let Some(pos) = find_target_position(&dirname, &target_substring) {
327+
dirname[pos..].to_string() //Keep everything from the target substring onwards
328+
} else {
329+
dirname.to_string() //If target substring is not found, keep the original dirname
330+
};
311331
// Hash the dirname. This should prevent conflicts if we have multiple
312332
// object files with the same filename in different subfolders.
313333
let mut hasher = hash_map::DefaultHasher::new();
314-
hasher.write(dirname.to_string().as_bytes());
334+
hasher.write(filtered_dirname.as_bytes());
315335
let obj = dst
316336
.join(format!("{:016x}-{}", hasher.finish(), basename))
317337
.with_extension("o");

0 commit comments

Comments
 (0)