-
-
Notifications
You must be signed in to change notification settings - Fork 356
tempfile: minor changes to handle tempfile encoding exceptions #4753
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
65379b0
Platform TempFileMunge changes:
jcbrill d8b9e16
Platform TempFileMunge changes: assign file contents to temporary var…
jcbrill 1317657
Platform TempFileMunge changes: add TempFileEncodeError exception and…
jcbrill 2dae19c
Platform TempFileMunge changes: update TempFileEncodeError exception
jcbrill 0b01059
Platform TempFileMunge changes: fix whitespace
jcbrill f05fbdf
Platform TempFileMunge changes: add test/TEMPFILE/TEMPFILEENCODING.py…
jcbrill 0e61b6f
Platform TempFileMunge changes: minor code cleanup and CHANGES.txt an…
jcbrill e7431f9
Platform TempFileMunge changes: TempFileEncodeError derived from SCon…
jcbrill cc47941
Platform TempFileMunge changes: Fix regex in TEMPFILE/TEMPFILEENCODIN…
jcbrill ddc12e8
Platform TempFileMunge changes: Fix test in RELEASE.txt [skip ci]
jcbrill 2ee36b8
Platform TempFileMunge changes: rework TempFileEncodeError exception …
jcbrill a938acf
Platform TempFileMunge changes: replace TempFileEncodeError with cls …
jcbrill 756d7cf
Platform TempFileMunge changes: replace TempFileEncodeError factory m…
jcbrill 7616303
Platform TempFileMunge changes: replace TempFileEncodeError with SCon…
jcbrill 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #!/usr/bin/env python | ||
| # | ||
| # MIT License | ||
| # | ||
| # Copyright The SCons Foundation | ||
| # | ||
| # Permission is hereby granted, free of charge, to any person obtaining | ||
| # a copy of this software and associated documentation files (the | ||
| # "Software"), to deal in the Software without restriction, including | ||
| # without limitation the rights to use, copy, modify, merge, publish, | ||
| # distribute, sublicense, and/or sell copies of the Software, and to | ||
| # permit persons to whom the Software is furnished to do so, subject to | ||
| # the following conditions: | ||
| # | ||
| # The above copyright notice and this permission notice shall be included | ||
| # in all copies or substantial portions of the Software. | ||
| # | ||
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
| # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
| # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
| # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
| # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| """ | ||
| Verify that setting the $TEMPFILEENCODING variable will be used for | ||
| encoding the file contents when writing the generated tempfile used | ||
| for long command lines. | ||
| """ | ||
|
|
||
|
|
||
| import TestSCons | ||
|
|
||
| test = TestSCons.TestSCons() | ||
|
bdbaddog marked this conversation as resolved.
|
||
|
|
||
| SCONSTRUCT_TEMPLATE=""" | ||
| import SCons.Platform | ||
|
|
||
| command = 'xyz ./test€/file.c' | ||
| encoding = {encoding!r} | ||
|
|
||
| tempfileencoding = {tempfileencoding} | ||
| defaultencoding = {defaultencoding} | ||
|
|
||
| DefaultEnvironment() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That is a bug. |
||
|
|
||
| if defaultencoding: | ||
| SCons.Platform.TEMPFILE_DEFAULT_ENCODING = encoding | ||
| print("SCons.Platform.TEMPFILE_DEFAULT_ENCODING = {encoding!r}") | ||
|
|
||
| env = Environment( | ||
| tools=[], | ||
| MAXLINELENGTH=2, | ||
| ) | ||
|
|
||
| if tempfileencoding: | ||
| env['TEMPFILEENCODING'] = encoding | ||
|
|
||
| tfm = SCons.Platform.TempFileMunge(command) | ||
|
|
||
| try: | ||
| tfm(None, None, env, 0) | ||
| except SCons.Platform.TempFileEncodeError as e: | ||
| print(str(e)) | ||
| """ | ||
|
|
||
| expected_pass = """\ | ||
| Using tempfile \\S+ for command line: | ||
| xyz \\S+ | ||
| scons\:.* | ||
| """ | ||
|
|
||
| expected_fail = """\ | ||
| TempFileEncodeError: \[{exception}\] .+ | ||
| TempFileMunge encoding\: env\['TEMPFILEENCODING'\] = {encoding!r} | ||
| scons\:.* | ||
| """ | ||
|
|
||
| expected_pass_default = """\ | ||
| SCons\.Platform\.TEMPFILE_DEFAULT_ENCODING = {encoding!r} | ||
| """ + expected_pass | ||
|
|
||
| expected_fail_default = """\ | ||
| SCons\.Platform\.TEMPFILE_DEFAULT_ENCODING = {encoding!r} | ||
| TempFileEncodeError: \[{exception}\] .+ | ||
| TempFileMunge encoding\: default = {encoding!r} | ||
| scons\:.* | ||
| """ | ||
|
|
||
| for test_encoding, test_tempfileencoding, test_defaultencoding, test_expected in [ | ||
|
|
||
| # expected pass | ||
| ('', False, False, expected_pass), | ||
| ('utf-8', True, False, expected_pass), | ||
| ('utf-8-sig', True, False, expected_pass), | ||
| ('utf-16', True, False, expected_pass), | ||
| ('utf-16', False, True, expected_pass_default.format(encoding='utf-16')), | ||
|
|
||
| # expected fail | ||
| ('ascii', True, False, expected_fail.format(exception='UnicodeEncodeError', encoding='ascii')), | ||
| ('missing', True, False, expected_fail.format(exception='LookupError', encoding='missing')), | ||
| ('', True, False, expected_fail.format(exception='LookupError', encoding='')), | ||
| (None, True, False, expected_fail.format(exception='TypeError', encoding=None)), | ||
| ('ascii', False, True, expected_fail_default.format(exception='UnicodeEncodeError', encoding='ascii')), | ||
|
|
||
| ]: | ||
|
|
||
| sconstruct = SCONSTRUCT_TEMPLATE.format( | ||
| encoding = test_encoding, | ||
| tempfileencoding = test_tempfileencoding, | ||
| defaultencoding = test_defaultencoding, | ||
| ) | ||
|
|
||
| test.write('SConstruct', sconstruct) | ||
|
|
||
| test.run( | ||
| arguments='-n -Q .', | ||
| stdout=test_expected, | ||
| match=TestSCons.match_re, | ||
| ) | ||
|
|
||
| test.pass_test() | ||
|
|
||
| # Local Variables: | ||
| # tab-width:4 | ||
| # indent-tabs-mode:nil | ||
| # End: | ||
| # vim: set expandtab tabstop=4 shiftwidth=4: | ||
Oops, something went wrong.
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.
We're not really consistent on whether to define Error classes near the point of use, or in
Errors.py. That question doesn't have to be resolved here (i.e., consider it a question, not a blocker). The Configure subsystem and the MSVC tool certainly define their own; many are also centralized intoErrors.py.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.
In this particular case, it could just as easily be an instance of
SCons.Errors.UserErrorwith the message/reason prefixed with something along the linestempfile encoding error: [UnicodeError] ...instead of a standalone exception. I'm not sure this is an exception a user is interested in catching as there really is no way to to "fix it".