Skip to content
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
53 changes: 53 additions & 0 deletions src/coreclr/tools/Common/CommandLineHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,58 @@ private static void AppendExpandedPaths(Dictionary<string, string> dictionary, s
}
}
}

/// <summary>
/// Read the response file line by line and treat each line as a single token.
/// Skip the comment lines that start with `#`.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <remarks>
/// This method does not support:
/// * referencing another response file.
/// * inline `#` comments.
/// </remarks>
public static bool TryReadResponseFile(string filePath, out IReadOnlyList<string> newTokens, out string error)
{
try
{
var tokens = new List<string>();
foreach (string line in File.ReadAllLines(filePath))
{
string token = line.Trim();
if (token.Length > 0 && token[0] != '#')
{
if (token.EndsWith('"'))
{
int firstQuotePosition = token.IndexOf('"');

// strip leading and trailing quotes from value.
if (firstQuotePosition >= 0 && firstQuotePosition < token.Length - 1 &&
(firstQuotePosition == 0 || token[firstQuotePosition - 1] != '\\'))
{
token = token[..firstQuotePosition] + token[(firstQuotePosition + 1)..^1];
}
}

tokens.Add(token);
}
}

newTokens = tokens;
error = null;
return true;
}
catch (FileNotFoundException)
{
error = $"Response file not found: '{filePath}'";
}
catch (IOException e)
{
error = $"Error reading response file '{filePath}': {e}";
}

newTokens = null;
return false;
}
}
}
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ private static IEnumerable<int> ProcessWarningCodes(IEnumerable<string> warningC

private static int Main(string[] args) =>
new CommandLineBuilder(new ILCompilerRootCommand(args))
.UseTokenReplacer(Helpers.TryReadResponseFile)
.UseVersionOption("-v")
.UseHelp(context => context.HelpBuilder.CustomizeLayout(ILCompilerRootCommand.GetExtendedHelp))
.UseParseErrorReporting()
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ internal static bool IsValidPublicKey(byte[] blob)

private static int Main(string[] args) =>
new CommandLineBuilder(new Crossgen2RootCommand(args))
.UseTokenReplacer(Helpers.TryReadResponseFile)
.UseVersionOption("-v")
.UseHelp(context => context.HelpBuilder.CustomizeLayout(Crossgen2RootCommand.GetExtendedHelp))
.UseParseErrorReporting()
Expand Down