Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for different hashes between different build paths #1277

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading