llvm-project/llvm/tools/llvm-rc/WindresOpts.td
Martin Storsjö 2bcc0fdc58 [llvm-windres] Implement the windres flag --use-temp-file
Whether a temp file or a pipe is used for preprocessing is an
internal detail, this flag has a notable effect on the preprocessing
in GNU windres. Without this flag, GNU windres passes command
arguments as-is to popen(), which means they get evaluated by a
shell without being re-escaped for this case. To mimic this,
llvm-windres has manually tried to unescape arguments.

When GNU windres is given the --use-temp-file flag, it uses a
different API for invoking the preprocessor, and this API takes care
of preserving special characters in the command line arguments.
For users of GNU windres, this means that by using --use-temp-file,
they don't need to do the (quite terrible) double escaping of
quotes/spaces etc.

The xz project uses the --use-temp-file flag when invoking
GNU windres, see
6b117d3b1f.
However as llvm-windres didn't implement this flag and just
assumed the GNU windres popen() behaviour, they had to use a
different codepath for llvm-windres.

That separate codepath for llvm-windres broke later when llvm-windres
got slightly more accurate unescaping of lone quotes in
0f4c6b120f21d582ab7c5c4f2b2a475086c34938 /
https://reviews.llvm.org/D146848 (fixing a discrepancy to GNU
windres as found in https://github.com/llvm/llvm-project/issues/57334),
and this was reported in
https://github.com/mstorsjo/llvm-mingw/issues/363.

Not touching the implementation of the --preprocessor option
with respect to the --use-temp-file flag; that option is doubly
tricky as GNU windres changed its behaviour in a backwards incompatible
way recently (and llvm-windres currently matches the old behaviour).
(See
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=21c33bcbe36377abf01614fb1b9be439a3b6de20,
https://sourceware.org/bugzilla/show_bug.cgi?id=27594 and
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=5edb8e3f5ad8d74a83fc0df7f6e4514eed0aa77f;hp=3abbafc2aacc6706fea3e3e326e2f08d107c3672
for the behaviour change.)

Differential Revision: https://reviews.llvm.org/D159223
2023-09-01 19:47:52 +03:00

64 lines
2.2 KiB
TableGen

include "llvm/Option/OptParser.td"
multiclass Long<string name, string help> {
def NAME: Separate<["--"], name>;
def NAME # _eq: Joined<["--"], name # "=">, Alias<!cast<Separate>(NAME)>,
HelpText<help>;
}
multiclass LongAlias<string name, Option orig> {
def NAME: Separate<["--"], name>, Alias<orig>;
def NAME # _eq: Joined<["--"], name # "=">, Alias<orig>;
}
multiclass LongShort<string short, string long, string help> {
def NAME: Separate<["--"], long>;
def NAME # _eq: Joined<["--"], long # "=">, Alias<!cast<Separate>(NAME)>,
HelpText<help>;
def NAME # _short: JoinedOrSeparate<["-"], short>, Alias<!cast<Separate>(NAME)>;
}
multiclass F<string short, string long, string help> {
def NAME: Flag<["-"], short>;
def NAME # _long: Flag<["--"], long>, Alias<!cast<Flag>(NAME)>,
HelpText<help>;
}
defm input : LongShort<"i", "input", "Input file">;
defm output : LongShort<"o", "output", "Output file">;
defm input_format : LongShort<"J", "input-format", "Input format">;
defm output_format : LongShort<"O", "output-format", "Output format">;
defm preprocessor : Long<"preprocessor", "Custom preprocessor command">;
defm preprocessor_arg : Long<"preprocessor-arg", "Preprocessor command argument">;
defm target : LongShort<"F", "target", "Target BFD format name">;
defm include_dir : LongShort<"I", "include-dir", "Include directory">;
defm include_alias : LongAlias<"include", include_dir>;
defm define : LongShort<"D", "define", "Define to pass to the preprocessor">;
defm undef : LongShort<"U", "undefine", "Undefine to pass to the preprocessor">;
defm codepage : LongShort<"c", "codepage", "Default codepage to use">;
defm language : LongShort<"l", "language", "Default language to use (0x0-0xffff)">;
def use_temp_file: Flag<["--"], "use-temp-file">,
HelpText<"Mimic GNU windres preprocessor option handling "
"(don't unescape preprocessor options)">;
defm verbose : F<"v", "verbose", "Enable verbose output">;
defm version : F<"V", "version", "Display version">;
defm help : F<"h", "help", "Display this message and exit">;
// Print (but do not run) the commands to run for preprocessing
def _HASH_HASH_HASH : Flag<["-"], "###">;
def no_preprocess : Flag<["--"], "no-preprocess">;