aboutsummaryrefslogtreecommitdiff
path: root/lld/MachO
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-11-17 12:15:42 -0500
committerNico Weber <thakis@chromium.org>2020-11-17 12:58:30 -0500
commitbaa2aa28f56259de7fa012178ada9e5ba07ec76c (patch)
treed9debb2e7a5239c32b1e96ad4ffc1c9dfb74a560 /lld/MachO
parentbedaad44953a99138bda0ee08ceeb5dfeec3c35c (diff)
downloadllvm-project-baa2aa28f56259de7fa012178ada9e5ba07ec76c.tar.gz
lld: Add --color-diagnostic to MachO port, harmonize others
This adds `--[no-]color-diagnostics[=auto,never,always]` to the MachO port and harmonizes the flag in the other ports: - Consistently use MetaVarName - Consistently document the non-eq version as alias of the eq version - Use B<> in the ports that have it (no-op, shorter) - Fix oversight in COFF port that made the --no flag have the wrong prefix Differential Revision: https://reviews.llvm.org/D91640
Diffstat (limited to 'lld/MachO')
-rw-r--r--lld/MachO/Driver.cpp24
-rw-r--r--lld/MachO/Options.td12
2 files changed, 36 insertions, 0 deletions
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 6735611666a9..a693cf6c8033 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -69,6 +69,28 @@ static const opt::OptTable::Info optInfo[] = {
MachOOptTable::MachOOptTable() : OptTable(optInfo) {}
+// Set color diagnostics according to --color-diagnostics={auto,always,never}
+// or --no-color-diagnostics flags.
+static void handleColorDiagnostics(opt::InputArgList &args) {
+ auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
+ OPT_no_color_diagnostics);
+ if (!arg)
+ return;
+ if (arg->getOption().getID() == OPT_color_diagnostics) {
+ lld::errs().enable_colors(true);
+ } else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
+ lld::errs().enable_colors(false);
+ } else {
+ StringRef s = arg->getValue();
+ if (s == "always")
+ lld::errs().enable_colors(true);
+ else if (s == "never")
+ lld::errs().enable_colors(false);
+ else if (s != "auto")
+ error("unknown option: --color-diagnostics=" + s);
+ }
+}
+
opt::InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
// Make InputArgList from string vectors.
unsigned missingIndex;
@@ -80,6 +102,8 @@ opt::InputArgList MachOOptTable::parse(ArrayRef<const char *> argv) {
if (missingCount)
error(Twine(args.getArgString(missingIndex)) + ": missing argument");
+ handleColorDiagnostics(args);
+
for (opt::Arg *arg : args.filtered(OPT_UNKNOWN))
error("unknown argument: " + arg->getSpelling());
return args;
diff --git a/lld/MachO/Options.td b/lld/MachO/Options.td
index cdbdbb26702e..3695bd1e2868 100644
--- a/lld/MachO/Options.td
+++ b/lld/MachO/Options.td
@@ -1,8 +1,20 @@
include "llvm/Option/OptParser.td"
+// Flags that lld/MachO understands but ld64 doesn't. These take
+// '--' instead of '-' and use dashes instead of underscores, so
+// they don't collide with the ld64 compat options.
+
def help : Flag<["-", "--"], "help">;
def help_hidden : Flag<["--"], "help-hidden">,
HelpText<"Display help for hidden options">;
+def color_diagnostics: Flag<["--"], "color-diagnostics">,
+ HelpText<"Alias for --color-diagnostics=always">;
+def no_color_diagnostics: Flag<["--"], "no-color-diagnostics">,
+ HelpText<"Alias for --color-diagnostics=never">;
+def color_diagnostics_eq: Joined<["--"], "color-diagnostics=">,
+ HelpText<"Use colors in diagnostics (default: auto)">,
+ MetaVarName<"[auto,always,never]">;
+
// This is a complete Options.td compiled from Apple's ld(1) manpage
// dated 2018-03-07 and cross checked with ld64 source code in repo