Skip to content

Normalize -f*-prefix-map args via SCCACHE_BASEDIRS - #2673

Open
larseggert wants to merge 2 commits into
mozilla:mainfrom
larseggert:fix-normalize_prefix_map_arg
Open

larseggert wants to merge 2 commits into
mozilla:mainfrom
larseggert:fix-normalize_prefix_map_arg

Conversation

@larseggert

Copy link
Copy Markdown

These compound flags embed absolute paths that strip_basedirs cannot reach via preprocessor-output normalization, causing cache misses when the same sources are built from different directories. Extract the OLD path component and strip basedir prefixes from it before hashing.

@codecov-commenter

codecov-commenter commented Apr 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.28%. Comparing base (00c8126) to head (0ad2706).
⚠️ Report is 91 commits behind head on main.

Files with missing lines Patch % Lines
src/util.rs 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2673      +/-   ##
==========================================
+ Coverage   74.26%   74.28%   +0.02%     
==========================================
  Files          70       70              
  Lines       39325    39366      +41     
==========================================
+ Hits        29204    29244      +40     
- Misses      10121    10122       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

These compound flags embed absolute paths that `strip_basedirs` cannot
reach via preprocessor-output normalization, causing cache misses when
the same sources are built from different directories. Extract the `OLD`
path component and strip basedir prefixes from it before hashing.
@larseggert
larseggert force-pushed the fix-normalize_prefix_map_arg branch from 0310045 to e1ba867 Compare April 13, 2026 10:26
@sylvestre

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

experimenting!

Comment thread src/compiler/c.rs
m.update(self.language.as_str().as_bytes());
for arg in self.arguments {
arg.hash(&mut HashToDigest { digest: &mut m });
normalize_prefix_map_arg(arg, self.basedirs).hash(&mut HashToDigest { digest: &mut m });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preprocessor_cache_entry_hash_key() still hashes the raw args, so in preprocessor cache mode we keep missing. please handle both (and dedup).

Comment thread src/util.rs
Cow::Owned(result)
}

const PREFIX_MAP_FLAGS: &[&[u8]] = &[

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about -fcoverage-prefix-map= and -fprofile-prefix-map=?

Comment thread src/util.rs
b"-ffile-prefix-map=",
];

/// Normalize a `-f{debug,macro,file}-prefix-map=OLD=NEW` compiler argument for cache key

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nobody will read a 10 lines doc comment :) 2 lines is enough

Comment thread src/util.rs
.iter()
.find_map(|&flag| Some((flag, bytes.strip_prefix(flag)?)))?;
// Format is OLD=NEW; split on the first '='
let sep = rest.iter().position(|&b| b == b'=')?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if OLD contains a '='? gcc splits on the last one iirc

Comment thread src/util.rs
// Strip the longest matching basedir prefix from OLD
let stripped_old = basedirs
.iter()
.filter(|dir| old.starts_with(dir.as_slice()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on windows basedirs are lowercased and slash-normalized (config.rs) while the arg isn't, so this never matches - strip_basedirs normalizes the haystack first, could you do the same here?

Comment thread src/util.rs
@@ -1670,6 +1710,41 @@ mod tests {
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test in c.rs that two identical builds from different dirs give the same hash key — that's the actual bug here.

@sylvestre

Copy link
Copy Markdown
Collaborator

are you still interested in this one? if not, i will close it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants