-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Set .net compilation output stream to utf8 #73865
Set .net compilation output stream to utf8 #73865
Conversation
Set the .net compilation output stream to utf8 to prevent garbled characters in other languages.
(Presumably) Fixes #71326 and #64276 (tho that is milestone 3.6) Upstream fix: dotnet/sdk#29755, but I am not sure how this interacts with this / how or if the encoding of stdin/stdout is propagated on windows; also that fix is just in the .NET 8 previews and a backport candidate for 7.0.300. Didn't / can't test this, on my system other languages work just fine with master (at least it looks ok and google correctly translates the output). |
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.
Usually using UTF-8 for I/O is a good idea, but Windows encoding handling is a huge mess, so I can't tell if it is for everyone.
Also, I'm not sure if it will always work with this part of code:
godot/platform/windows/os_windows.cpp
Lines 565 to 573 in 9e6cb51
// Try to convert from default ANSI code page to Unicode. | |
LocalVector<wchar_t> wchars; | |
int total_wchars = MultiByteToWideChar(CP_ACP, 0, p_bytes, p_size, nullptr, 0); | |
if (total_wchars > 0) { | |
wchars.resize(total_wchars); | |
if (MultiByteToWideChar(CP_ACP, 0, p_bytes, p_size, wchars.ptr(), total_wchars) == 0) { | |
wchars.clear(); | |
} | |
} |
These use cases are in the C# land, using |
@@ -55,7 +56,8 @@ public static string FindDotNetExe() | |||
process.StartInfo = new ProcessStartInfo(dotNetExe, "--list-sdks") | |||
{ | |||
UseShellExecute = false, | |||
RedirectStandardOutput = true | |||
RedirectStandardOutput = true, | |||
StandardOutputEncoding = Encoding.UTF8, |
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.
It doesn't seem necessary here since we later set DOTNET_CLI_UI_LANGUAGE
to en-US
for this command.
After way too much googling, diving into framework sources and some experiments:
TL/DR: It's complicated, but it looks like it goes into the right direction, i'll have a look how much of a pain passing DETACHED_PROCESS actually is. |
As expected an enormous pain since you need to re-implement IO redirection, so it's probably not worth it.
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs b/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs
index d550c36b82..c9b686413c 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/BuildSystem.cs
@@ -38,6 +38,8 @@ namespace GodotTools.Build
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
+ startInfo.StandardOutputEncoding = Encoding.UTF8;
+ startInfo.StandardErrorEncoding = Encoding.UTF8;
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"]
= ((string)editorSettings.GetSetting("interface/editor/editor_language")).Replace('_', '-');
@@ -102,6 +104,8 @@ namespace GodotTools.Build
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
+ startInfo.StandardOutputEncoding = Encoding.UTF8;
+ startInfo.StandardErrorEncoding = Encoding.UTF8;
startInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"]
= ((string)editorSettings.GetSetting("interface/editor/editor_language")).Replace('_', '-');
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs b/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs
index b437c7e742..27b36d9ad1 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/DotNetFinder.cs
@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
+using System.Text;
using JetBrains.Annotations;
using OS = GodotTools.Utils.OS;
@@ -55,7 +56,9 @@ namespace GodotTools.Build
process.StartInfo = new ProcessStartInfo(dotNetExe, "--list-sdks")
{
UseShellExecute = false,
- RedirectStandardOutput = true
+ RedirectStandardOutput = true,
+ StandardOutputEncoding = Encoding.UTF8,
};
process.StartInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"] = "en-US"; Edit: can't be in the last one, because stderr is not redirected.
|
I'm not really familiar with this to update it properly, I just PR'ed it to help @dream-young-soul with Git issues. I'd suggest you take this over in a new PR @RedworkDE if you're interested, as you did a lot of great research. |
Superseded by #74065. |
Set the .net compilation output stream to utf8 to prevent garbled characters in other languages.
Squashed version of #73861 by @dream-young-soul.