Revert "[Support] Allow the ability to change WithColor's auto detection function"
authorJonas Devlieghere <jonas@devlieghere.com>
Mon, 28 Feb 2022 23:31:54 +0000 (15:31 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Mon, 28 Feb 2022 23:32:15 +0000 (15:32 -0800)
This reverts commit a83cf7a84628a9e3a24cfd33c69f786cf74df4ec because it
breaks a bunch of build bots.

lldb/tools/driver/Driver.cpp
llvm/include/llvm/Support/WithColor.h
llvm/lib/Support/WithColor.cpp

index 53eaf89..31407be 100644 (file)
@@ -186,13 +186,6 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {
   m_debugger.SkipLLDBInitFiles(false);
   m_debugger.SkipAppInitFiles(false);
 
-  if (args.hasArg(OPT_no_use_colors)) {
-    m_debugger.SetUseColor(false);
-    WithColor::setAutoDetectFunction(
-        [](const llvm::raw_ostream &OS) { return false; });
-    m_option_data.m_debug_mode = true;
-  }
-
   if (args.hasArg(OPT_version)) {
     m_option_data.m_print_version = true;
   }
@@ -234,6 +227,11 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {
                                           m_debugger.GetInstanceName());
   }
 
+  if (args.hasArg(OPT_no_use_colors)) {
+    m_debugger.SetUseColor(false);
+    m_option_data.m_debug_mode = true;
+  }
+
   if (auto *arg = args.getLastArg(OPT_file)) {
     auto arg_value = arg->getValue();
     SBFileSpec file(arg_value);
index 2e8e52d..e772ea6 100644 (file)
@@ -11,8 +11,6 @@
 
 #include "llvm/Support/raw_ostream.h"
 
-#include <functional>
-
 namespace llvm {
 
 class Error;
@@ -56,9 +54,6 @@ class WithColor {
   raw_ostream &OS;
   ColorMode Mode;
 
-  using AutoDetectFunctionType = std::function<bool(const raw_ostream &OS)>;
-  static AutoDetectFunctionType AutoDetectFunction;
-
 public:
   /// To be used like this: WithColor(OS, HighlightColor::String) << "text";
   /// @param OS The output stream
@@ -137,13 +132,6 @@ public:
   /// Implement default handling for Warning.
   /// Print "warning: " to stderr.
   static void defaultWarningHandler(Error Warning);
-
-  /// Retrieve the default color auto detection function.
-  static AutoDetectFunctionType defaultAutoDetectFunction();
-
-  /// Change the global auto detection function.
-  static void
-  setAutoDetectFunction(AutoDetectFunctionType NewAutoDetectFunction);
 };
 
 } // end namespace llvm
index 641ba2a..b1aa709 100644 (file)
@@ -33,9 +33,6 @@ struct CreateUseColor {
 static ManagedStatic<cl::opt<cl::boolOrDefault>, CreateUseColor> UseColor;
 void llvm::initWithColorOptions() { *UseColor; }
 
-WithColor::AutoDetectFunctionType WithColor::AutoDetectFunction =
-    WithColor::defaultAutoDetectFunction();
-
 WithColor::WithColor(raw_ostream &OS, HighlightColor Color, ColorMode Mode)
     : OS(OS), Mode(Mode) {
   // Detect color from terminal type unless the user passed the --color option.
@@ -130,7 +127,8 @@ bool WithColor::colorsEnabled() {
   case ColorMode::Disable:
     return false;
   case ColorMode::Auto:
-    return AutoDetectFunction(OS);
+    return *UseColor == cl::BOU_UNSET ? OS.has_colors()
+                                      : *UseColor == cl::BOU_TRUE;
   }
   llvm_unreachable("All cases handled above.");
 }
@@ -161,15 +159,3 @@ void WithColor::defaultWarningHandler(Error Warning) {
     WithColor::warning() << Info.message() << '\n';
   });
 }
-
-WithColor::AutoDetectFunctionType WithColor::defaultAutoDetectFunction() {
-  return [](const raw_ostream &OS) {
-    return *UseColor == cl::BOU_UNSET ? OS.has_colors()
-                                      : *UseColor == cl::BOU_TRUE;
-  };
-}
-
-void WithColor::setAutoDetectFunction(
-    AutoDetectFunctionType NewAutoDetectFunction) {
-  AutoDetectFunction = std::move(NewAutoDetectFunction);
-}