-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add custom ResponseFile handler #76271
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
Add custom ResponseFile handler #76271
Conversation
8f26f5c to
9773bf5
Compare
Co-authored-by: Jon Sequeira <[email protected]>
9773bf5 to
fc0668e
Compare
|
Crossgen2 that was switched over to S.CommandLine in #72082 as well has the same problem. We don't consistently quote things that go into the response file: https://github.com/dotnet/sdk/blob/cf2fd1e514c393cb12e745ab488b6478320fc232/src/Tasks/Microsoft.NET.Build.Tasks/RunReadyToRunCompiler.cs#L324 |
|
@am11 Could you please move this next to the other command line helpers and use it for crossgen too? |
|
When I was testing it on mac, crossgen2's rsp file had quoted I think this inconsistent use of quotes is not ideal for any tool. Quoting all paths wouldn't surprise anyone and it is the known way to support paths with space. Internal CLI parser's has number of issues as well when dealing with |
| new(new[] { "--reference", "-r" }, result => Helpers.BuildPathDictionay(result.Tokens, false), true, "Reference file(s) for compilation"); | ||
| public Option<string> OutputFilePath { get; } = | ||
| new(new[] { "--out", "-o" }, "Output file path"); | ||
| new(new[] { "--out", "-o" }, result => Helpers.Unquote(result.Tokens), true, "Output file path"); |
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.
Can the unquoting be done in TryReadResponseFile instead of around every single argument?
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.
I tried it first in TryReadResponseFile and it gets complicated. For the starters, we will need to replicate the "argument-value splitting" logic in order to support all these simultaneously:
path with space
/r:path with space
-r:path with space
--reference path with space
// and their quoted variants
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.
Can we strip the first and last quote if the string ends with a quote?
if (s.EndsWith('"'))
{
int firstQuote = s.IndexOf('"');
if (firstQuote >= 0 && firstQuote < s.Length - 1)
s = s[..firstQuote] + s[(firstQuote+1)..^1];
}
It should be good-enough to maintain compatibility with what we had, without the manual stripping of quotes everywhere.
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.
That will work. 👍
I agree. Do you think that it would be better we chase down all places where we write paths to response files and quote them? |
|
Are there examples of command line response files in Linux-native tools? What do they do for paths with spaces? |
I have tried |
Can you show the script, how are you comparing and what is expected? foo.rsp I expect -x to be |
|
The default python argparse handling of response files is geared towards one command line arg per line. It avoid all problems with escaping of quotes, spaces in names, etc. Very simple Unix-like approach. So the response file for your example that gives the expected result would be: I like this as a north-star a lot. I am wondering how we can get closer to it.
Right, it is the shell interpreting all escaping using shell-specific rules. The program that you are invoking does not need to deal with it. |
|
For what it's worth, I think this is actually the most useful response file format. Bypassing shell-specific escaping rules and taking each line as entirely literal is the simplest and most easily understood convention among the many I've looked at. (It just also happened to be less common among Windows tools.) Adding this back as an available option to System.CommandLine is something we could do very easily. |
CommandLine with custom handler (which we are adding in this PR) sets this one as
This will be great. For now we need to implement both, the handler and post-processor, for the mixed response files; some paths are quoted, others are not in the same response file.
I think this is the cleanest solution and default behavior works with it (no custom handler and no extra post-processing required). |
+1 Do you think we can have a mode where this .rsp works? |
|
cc @adamsitnik |
|
The rsp file which crossgen2 is generating today has this mixed format: so a mode "one or the other" wouldn't help. |
My idea was:
|
Let's do this then. Could you please prepare PR to do it? |
|
I would be also ok with merging this PR if the |
|
Sure, I will work on a separate PR for runtime first. I will keep this one open as the discussion is on going.
Just to be clear, for compat, treat the rest of the line as value and trim the quotes from edges (if present). This is because, in a single rsp file generated by the sdk for crossgen2 today, regardless of the operating system:
|
jkotas
left a comment
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.
Thank you!
Fixes #76248.