log.py: improve non-utf-8 input and output#48005
Merged
Conversation
7f0e896 to
85f22ee
Compare
alalazo
approved these changes
Dec 11, 2024
fryeguy52
pushed a commit
to fryeguy52/spack
that referenced
this pull request
Dec 17, 2024
tdrwenski
pushed a commit
to tdrwenski/spack
that referenced
this pull request
Dec 26, 2024
kshea21
pushed a commit
to kshea21/spack
that referenced
this pull request
Dec 26, 2024
haampie
added a commit
that referenced
this pull request
Feb 3, 2025
teaguesterling
pushed a commit
to teaguesterling/spack
that referenced
this pull request
Feb 5, 2025
haampie
added a commit
that referenced
this pull request
Feb 19, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Replaces #48001
The build process is assumed to output utf-8 most of the time: it contains (1) python's own output, which I believe is almost always ascii due to our package name restrictions (but maybe under -d we print non-utf-8 accidentally); and (2) possibly output from build subprocesses, which is usually utf-8 unless a compiler or linker decides to dump a binary to stdout, which happens.
For the unlikely case that the build process does not output utf-8, @alalazo and I agreed that it would be sensible to output valid utf-8 to the main process's stdout, as well as the log file, meaning we escape invalid utf-8 by
?chars. That way users cancatandgrepthe log file safely/easily. Obviously information does get lost here, but if you really need the exact output from a build process to troubleshoot a build, you could also look atstrace -f -s1000output, so technically nothing is lost.However, a related issue is that even though we have valid utf-8 lines from the build process, sys.stdout may not support utf-8. That can happen in principle on any platform with any version of Python. To deal with this edge case, we do a little dance to re-encode the utf-8 as sys.stdout.encoding with errors replaced (so more
?s). That's inefficient, but doesn't error, and is an unlikely code path (most likely only to happen on Python 3.6 without locale set, or default C locale).