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

Use relative directory for obj files hash #1270

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Changes from 4 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
16 changes: 15 additions & 1 deletion src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,21 @@ pub(crate) fn objects_from_files(files: &[Arc<Path>], dst: &Path) -> Result<Vec<
// 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());

// Make the dirname relative (if possible) to avoid full system paths influencing the sha
// and making the output system-dependent
//
// NOTE: Here we allow using std::env::var (instead of Build::getenv) because
// CARGO_* variables always trigger a rebuild when changed
#[allow(clippy::disallowed_methods)]
let dirname = if let Some(root) = std::env::var_os("CARGO_MANIFEST_DIR") {
let root = root.to_string_lossy();
crate::Cow::Borrowed(dirname.strip_prefix(&*root).unwrap_or(&dirname))
nmattia marked this conversation as resolved.
Show resolved Hide resolved
} else {
dirname
};

hasher.write(dirname.as_bytes());
let obj = dst
.join(format!("{:016x}-{}", hasher.finish(), basename))
.with_extension("o");
Expand Down