-
Notifications
You must be signed in to change notification settings - Fork 725
Strip basedirs from cmdline args and direct-mode hash key #2711
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
Open
solarispika
wants to merge
3
commits into
mozilla:main
Choose a base branch
from
solarispika:basedirs-cover-args-and-direct-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+320
−4
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a maintainer nor a contributor, but I am a user of sccache.
I am wondering if we should use
OsString::as_encoded_byteshere withstrip_basedirsandself.basedirs.arg_byteshere seems to be bytes with platform specific encoding, whileself.basedirsis in UTF-8, and can cause problems on Windows.This is the doc for
OsString::as_encoded_bytes:self.basedirsis initialized bystorage.basedirs(). Let's follow how<DiskCache as Storage>::basedirsis implemented and initialized, we can tell it's ultimately fromconfig.basedirs. CheckingConfig::from_env_and_file_configs, we can tellbasedirsare populated frombasedirs_rawby converting the path toUtf8TypedPathBufbefore normalization and converting to bytes. Therefore,basedirsare encoded in UTF-8 not in a platform specific way.I am wondering if the following is better:
The same applies to the similar change in
src/compiler/preprocessor_cache.rs. Thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@06393993 Good catch on the encoding mismatch. On Windows
OsString::as_encoded_bytes()is WTF-8 andself.basedirsis plain UTF-8, so formally they don't agree. In practice I don't think it bites, and the rewrite has costs that aren't obvious:strip_basedirsalready normalises the input on Windows (lowercases ASCII,\→/) and the non-ASCII branch decodes UTF-8 with an explicit fall-through for invalid sequences (src/util.rs:1090-1095). An unpaired surrogate just fails to match; it doesn't mis-match.String(file) orto_string_lossy()(env) intoUtf8TypedPathBuf(src/config.rs:1175), so the needle is guaranteed UTF-8 and cannot match an ill-formed segment of the haystack on either path. Whatever mismatch the rewrite "fixes" isn't fixable at this layer anyway.OsString'sHashimpl writes a length prefix; the current code writes raw bytes plus a null separator. Not behaviour-preserving, so it'd needCACHE_VERSION/FORMAT_VERSIONbumps to avoid silent cache corruption.If we want to be defensive about it without paying that price, the narrowest version I can see is:
Same bytes for valid Unicode, current behaviour otherwise. I'm not convinced it earns the extra ceremony, since the basedirs side already constrains what can ever match.
@sylvestre what do you prefer — leave it as-is, or take the
to_str()fallback?