diff --git a/src/command_helpers.rs b/src/command_helpers.rs index 9f83e38c..3b62bfd0 100644 --- a/src/command_helpers.rs +++ b/src/command_helpers.rs @@ -288,6 +288,7 @@ fn wait_on_child( /// and store them in the output Object. pub(crate) fn objects_from_files(files: &[Arc], dst: &Path) -> Result, Error> { let mut objects = Vec::with_capacity(files.len()); + let target_substring = ["rustc"]; for file in files { let basename = file .file_name() @@ -308,10 +309,29 @@ pub(crate) fn objects_from_files(files: &[Arc], dst: &Path) -> Result Option { + 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");