Skip to content

Commit cac2b33

Browse files
committed
lld-link: Add --color-diagnostics(={always,never,auto})?, --no-color-diagnostics flags.
This is most useful when using lld-link on a non-Win host (but it might become useful on Windows too if lld also grows a fansi-escape-codes flag). Also make the help for --color-diagnostic mention the valid values in ELF and wasm, and print the flag name with two dashes in diags, since the one-dash form is seen as a list of many one-letter flags in some contexts. https://reviews.llvm.org/D46693 llvm-svn: 332012
1 parent d6beb32 commit cac2b33

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

lld/COFF/DriverUtils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,28 @@ static const llvm::opt::OptTable::Info InfoTable[] = {
756756

757757
COFFOptTable::COFFOptTable() : OptTable(InfoTable, true) {}
758758

759+
// Set color diagnostics according to --color-diagnostics={auto,always,never}
760+
// or --no-color-diagnostics flags.
761+
static void handleColorDiagnostics(opt::InputArgList &Args) {
762+
auto *Arg = Args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
763+
OPT_no_color_diagnostics);
764+
if (!Arg)
765+
return;
766+
if (Arg->getOption().getID() == OPT_color_diagnostics) {
767+
errorHandler().ColorDiagnostics = true;
768+
} else if (Arg->getOption().getID() == OPT_no_color_diagnostics) {
769+
errorHandler().ColorDiagnostics = false;
770+
} else {
771+
StringRef S = Arg->getValue();
772+
if (S == "always")
773+
errorHandler().ColorDiagnostics = true;
774+
else if (S == "never")
775+
errorHandler().ColorDiagnostics = false;
776+
else if (S != "auto")
777+
error("unknown option: --color-diagnostics=" + S);
778+
}
779+
}
780+
759781
static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &Args) {
760782
if (auto *Arg = Args.getLastArg(OPT_rsp_quoting)) {
761783
StringRef S = Arg->getValue();
@@ -799,6 +821,9 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> Argv) {
799821

800822
if (MissingCount)
801823
fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument");
824+
825+
handleColorDiagnostics(Args);
826+
802827
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
803828
warn("ignoring unknown argument: " + Arg->getSpelling());
804829
return Args;

lld/COFF/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def align : P<"align", "Section alignment">;
2020
def aligncomm : P<"aligncomm", "Set common symbol alignment">;
2121
def alternatename : P<"alternatename", "Define weak alias">;
2222
def base : P<"base", "Base address of the program">;
23+
def color_diagnostics: Flag<["--"], "color-diagnostics">,
24+
HelpText<"Use colors in diagnostics">;
25+
def color_diagnostics_eq: Joined<["--"], "color-diagnostics=">,
26+
HelpText<"Use colors in diagnostics; one of 'always', 'never', 'auto'">;
2327
def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
2428
def delayload : P<"delayload", "Delay loaded DLL name">;
2529
def entry : P<"entry", "Name of entry point symbol">;
@@ -46,6 +50,8 @@ def opt : P<"opt", "Control optimizations">;
4650
def order : P<"order", "Put functions in order">;
4751
def out : P<"out", "Path to file to write output">;
4852
def natvis : P<"natvis", "Path to natvis file to embed in the PDB">;
53+
def no_color_diagnostics: F<"no-color-diagnostics">,
54+
HelpText<"Do not use colors in diagnostics">;
4955
def pdb : P<"pdb", "PDB file path">;
5056
def pdbaltpath : P<"pdbaltpath", "PDB file path to embed in the image">;
5157
def section : P<"section", "Specify section attributes">;

lld/ELF/DriverUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ static void handleColorDiagnostics(opt::InputArgList &Args) {
5959
OPT_no_color_diagnostics);
6060
if (!Arg)
6161
return;
62-
else if (Arg->getOption().getID() == OPT_color_diagnostics)
62+
if (Arg->getOption().getID() == OPT_color_diagnostics) {
6363
errorHandler().ColorDiagnostics = true;
64-
else if (Arg->getOption().getID() == OPT_no_color_diagnostics)
64+
} else if (Arg->getOption().getID() == OPT_no_color_diagnostics) {
6565
errorHandler().ColorDiagnostics = false;
66-
else {
66+
} else {
6767
StringRef S = Arg->getValue();
6868
if (S == "always")
6969
errorHandler().ColorDiagnostics = true;
7070
else if (S == "never")
7171
errorHandler().ColorDiagnostics = false;
7272
else if (S != "auto")
73-
error("unknown option: -color-diagnostics=" + S);
73+
error("unknown option: --color-diagnostics=" + S);
7474
}
7575
}
7676

lld/ELF/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def color_diagnostics: F<"color-diagnostics">,
7676
HelpText<"Use colors in diagnostics">;
7777

7878
def color_diagnostics_eq: J<"color-diagnostics=">,
79-
HelpText<"Use colors in diagnostics">;
79+
HelpText<"Use colors in diagnostics; one of 'always', 'never', 'auto'">;
8080

8181
defm cref: B<"cref",
8282
"Output cross reference table",

lld/wasm/Driver.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,18 @@ static void handleColorDiagnostics(opt::InputArgList &Args) {
111111
OPT_no_color_diagnostics);
112112
if (!Arg)
113113
return;
114-
115-
if (Arg->getOption().getID() == OPT_color_diagnostics)
114+
if (Arg->getOption().getID() == OPT_color_diagnostics) {
116115
errorHandler().ColorDiagnostics = true;
117-
else if (Arg->getOption().getID() == OPT_no_color_diagnostics)
116+
} else if (Arg->getOption().getID() == OPT_no_color_diagnostics) {
118117
errorHandler().ColorDiagnostics = false;
119-
else {
118+
} else {
120119
StringRef S = Arg->getValue();
121120
if (S == "always")
122121
errorHandler().ColorDiagnostics = true;
123-
if (S == "never")
122+
else if (S == "never")
124123
errorHandler().ColorDiagnostics = false;
125-
if (S != "auto")
126-
error("unknown option: -color-diagnostics=" + S);
124+
else if (S != "auto")
125+
error("unknown option: --color-diagnostics=" + S);
127126
}
128127
}
129128

lld/wasm/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def color_diagnostics: F<"color-diagnostics">,
2121
HelpText<"Use colors in diagnostics">;
2222

2323
def color_diagnostics_eq: J<"color-diagnostics=">,
24-
HelpText<"Use colors in diagnostics">;
24+
HelpText<"Use colors in diagnostics; one of 'always', 'never', 'auto'">;
2525

2626
defm demangle: B<"demangle",
2727
"Demangle symbol names",

0 commit comments

Comments
 (0)