Skip to content
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

Permit specifying that we should use utf-8 in ToolTask #6188

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ public Exec() { }
[Microsoft.Build.Framework.OutputAttribute]
public string StdOutEncoding { get { throw null; } set { } }
protected override string ToolName { get { throw null; } }
public string UseUtf8Encoding { get { throw null; } set { } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird that the API addition in ToolTask does not show up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in M.B.Utilities.Core, so it's the next file. I was wondering if I should count this as a breaking change because someone could use UseUtf8Encoding for Exec without loading Utilities.Core, but I don't think there's anything that calls into it, so I think it's ok.

public string WorkingDirectory { get { throw null; } set { } }
protected internal override void AddCommandLineCommands(Microsoft.Build.Tasks.CommandLineBuilderExtension commandLine) { }
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ public Exec() { }
[Microsoft.Build.Framework.OutputAttribute]
public string StdOutEncoding { get { throw null; } set { } }
protected override string ToolName { get { throw null; } }
public string UseUtf8Encoding { get { throw null; } set { } }
public string WorkingDirectory { get { throw null; } set { } }
protected internal override void AddCommandLineCommands(Microsoft.Build.Tasks.CommandLineBuilderExtension commandLine) { }
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ protected ToolTask(System.Resources.ResourceManager taskResources, string helpKe
protected abstract string ToolName { get; }
public string ToolPath { get { throw null; } set { } }
public bool UseCommandProcessor { get { throw null; } set { } }
public string UseUtf8Encoding { get { throw null; } set { } }
public bool YieldDuringToolExecution { get { throw null; } set { } }
protected virtual string AdjustCommandsForOperatingSystem(string input) { throw null; }
protected virtual bool CallHostObjectToExecute() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ protected ToolTask(System.Resources.ResourceManager taskResources, string helpKe
protected abstract string ToolName { get; }
public string ToolPath { get { throw null; } set { } }
public bool UseCommandProcessor { get { throw null; } set { } }
public string UseUtf8Encoding { get { throw null; } set { } }
public bool YieldDuringToolExecution { get { throw null; } set { } }
protected virtual string AdjustCommandsForOperatingSystem(string input) { throw null; }
protected virtual bool CallHostObjectToExecute() { throw null; }
Expand Down
8 changes: 0 additions & 8 deletions src/Tasks/Exec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ public string CustomWarningRegularExpression
/// </summary>
protected override Encoding StandardErrorEncoding => _standardErrorEncoding;

/// <summary>
/// Whether or not to use UTF8 encoding for the cmd file and console window.
/// Values: Always, Never, Detect
/// If set to Detect, the current code page will be used unless it cannot represent
/// the Command string. In that case, UTF-8 is used.
/// </summary>
public string UseUtf8Encoding { get; set; }

/// <summary>
/// Project visible property specifying the encoding of the captured task standard output stream
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Utilities/ToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ public virtual string ToolExe
/// <value>Path to tool.</value>
public string ToolPath { set; get; }

/// <summary>
/// Whether or not to use UTF8 encoding for the cmd file and console window.
/// Values: Always, Never, Detect
/// If set to Detect, the current code page will be used unless it cannot represent
/// the Command string. In that case, UTF-8 is used.
/// </summary>
public string UseUtf8Encoding { get; set; } = EncodingUtilities.UseUtf8Detect;

/// <summary>
/// Array of equals-separated pairs of environment
/// variables that should be passed to the spawned executable,
Expand Down Expand Up @@ -1373,7 +1381,7 @@ public override bool Execute()
}
else
{
encoding = EncodingUtilities.BatchFileEncoding(commandLineCommands + _temporaryBatchFile, EncodingUtilities.UseUtf8Detect);
encoding = EncodingUtilities.BatchFileEncoding(commandLineCommands + _temporaryBatchFile, UseUtf8Encoding);

if (encoding.CodePage != EncodingUtilities.CurrentSystemOemEncoding.CodePage)
{
Expand Down