-
Notifications
You must be signed in to change notification settings - Fork 789
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
Preserve console encoding when using --utf8output switch without swapping console streams #17761
Conversation
|
IIRC the HostedCompiler was relying on stdout redirection, should only be used for some of the legacy test suites (FsharpQA I think). But FSharpQA still runs here, so that keeps working after your change. |
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.
@majocha , @T-Gro --- I'm afraid the savedOut is necessary.
The scenario is this:
- The host application is using a non-UTF8 Encoding, E.g UTF-7 or UTF-32
- The host executes the compilation and passes in the '--utf8output' flag
- This flag changes the Encoding of the Console.Out to UTF which is not what the host app was set to.
- The purpose of the savedOut is to ensure that these changes caused by our compiler do not adversely impact the hosts.
fsharp/src/Compiler/Driver/fsc.fs
Line 276 in 52133d0
if tcConfigB.utf8output then |
It also looks as if unused binding analysis didn't find the unused: I wonder why. |
Might be related to #13849 |
Thanks @KevinRansom, this is important because it seems in the course of recent changes the test for this got lost. Also, I'm wondering, maybe just restoring the encoding (if the Out is still the same during dispose) would be less intrusive. |
I'm frankly confused about this but I suspect that setting OutputEncoding affects the underlying system level stuff and has no effect when console is redirected? |
Anything interesting from the git blame? (I can also take a look later in the day) |
@majocha --- |
I'll write a test to see what the situation is right now. I understand that from the consumer's pov it's important that fsc writes using the correct encoding according to the given switch and that console encoding is restored afterwards. |
It works, but yes a test case in the repo would be useful to ensure that it doesn't get inadvertently ripped out in the future. |
I added some tests for this. |
Thanks a lot! This week we have some internal stuff going on so our capacities are lower, hopefully we'll get to all the PRs early next week. You're doing amazing job (and inspiring me to do some related job). |
No worries, I can imagine this week was quite demanding :) |
I noticed there was code already that restored the Console Encoding in fsi and fsc. I reshufflled it a bit and it seems it works without swapping the whole console streams. To clarify, my intention is to avoid mutating the Console.Out and Console.Error by fsc , because in my parallel testing experiment there are multithreaded TextWriters installed there so we can capture output from many tests at once. |
@KevinRansom please rereview. |
Head branch was pushed to by a user without write access
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.
Looks good.
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.
Just need to look at a few things
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.
okay, this is still good to go.
Previously the
Console.Out
stream was remembered and finally restored in case of using--utf8output
switch in order to restore the original console encoding.With this PR, just the original encoding is preserved and then restored, without swapping the whole
Console.Out
stream. This cooperates better with redirected console.Tests added to ensure both fsc and fsi restore encoding correctly.