Skip to content

Commit 1faf69d

Browse files
Fea,添加响应文件支持
1 parent fcdc09a commit 1faf69d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Microsoft.Build.CPPTasks/VCToolTask.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ public string AdditionalOptions
115115

116116
public bool UseMsbuildResourceManager { get; set; }
117117

118+
#if __REMOVE
118119
protected override Encoding ResponseFileEncoding => Encoding.Unicode;
120+
#else
121+
// Linux下文件普遍采用没文件头的UTF8,否则容易引入兼容性问题。
122+
private UTF8Encoding UTF8NoBom = new UTF8Encoding(false);
123+
protected override Encoding ResponseFileEncoding => UTF8NoBom;
124+
#endif
119125

120126
protected virtual ArrayList SwitchOrderList => null;
121127

@@ -250,8 +256,7 @@ public string GenerateCommandLineExceptSwitches(string[] switchesToRemove, Comma
250256
return text2;
251257
}
252258

253-
// Linux下对 ResponseFile 支持不好,所以与 CommandLine 调换。
254-
protected virtual string /*GenerateCommandLineCommandsExceptSwitches*/GenerateResponseFileCommandsExceptSwitches(string[] switchesToRemove, CommandLineFormat format = CommandLineFormat.ForBuildLog, EscapeFormat escapeFormat = EscapeFormat.Default)
259+
protected virtual string GenerateCommandLineCommandsExceptSwitches(string[] switchesToRemove, CommandLineFormat format = CommandLineFormat.ForBuildLog, EscapeFormat escapeFormat = EscapeFormat.Default)
255260
{
256261
return string.Empty;
257262
}
@@ -281,7 +286,7 @@ protected virtual bool GenerateCostomCommandsAccordingToType(CommandLineBuilder
281286
return false;
282287
}
283288

284-
protected virtual string /*GenerateResponseFileCommandsExceptSwitches*/GenerateCommandLineCommandsExceptSwitches(string[] switchesToRemove, CommandLineFormat format = CommandLineFormat.ForBuildLog, EscapeFormat escapeFormat = EscapeFormat.Default)
289+
protected virtual string GenerateResponseFileCommandsExceptSwitches(string[] switchesToRemove, CommandLineFormat format = CommandLineFormat.ForBuildLog, EscapeFormat escapeFormat = EscapeFormat.Default)
285290
{
286291
bool flag = false;
287292
AddDefaultsToActiveSwitchList();
@@ -360,6 +365,25 @@ public override bool Execute()
360365

361366
protected override int ExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
362367
{
368+
#if __REMOVE
369+
#else
370+
// 由于创建响应文件速度需要额外IO,所以我们特别判断,如果命令行总长度小于2048(Linux支持2048长度问题不大)则不创建响应文件了。
371+
if(responseFileCommands.Length != 0 && responseFileCommands.Length + commandLineCommands.Length + 1 < 2048)
372+
{
373+
if(commandLineCommands.Length != 0)
374+
{
375+
commandLineCommands += ' ';
376+
commandLineCommands += responseFileCommands;
377+
}
378+
else
379+
{
380+
commandLineCommands = responseFileCommands;
381+
}
382+
383+
responseFileCommands = "";
384+
}
385+
#endif
386+
363387
ResolvedPathToTool = Environment.ExpandEnvironmentVariables(pathToTool);
364388
return base.ExecuteTool(pathToTool, responseFileCommands, commandLineCommands);
365389
}

0 commit comments

Comments
 (0)