This is an archive of the discontinued LLVM Phabricator instance.

[Support] Allow the ability to change WithColor's auto detection function
ClosedPublic

Authored by JDevlieghere on Feb 25 2022, 3:14 PM.

Details

Summary

WithColor has an "auto detection mode" which looks whether the corresponding whether the corresponding cl::opt is enabled or not. While this is great when opting into cl::opt, it's not so great for downstream users of this utility, which might have their own competing options to enable or disable colors. The WithColor constructor takes a color mode, but the big benefit of the class are its static error and warning helpers and default error handlers.

In order to allow users of this utility to enable or disable colors globally, this patch adds the ability to specify a global auto detection function. By default, the auto detection function behaves the way that it does today. The benefit of this patch lies in that it can be overwritten. In addition to a ability to change the auto detection function, I've also made it possible to get your hands on the default auto detection function, so you swap it back if if you so desire.

This patch allow downstream users (like LLDB) to globally disable colors with its own command line flag.

Diff Detail

Event Timeline

JDevlieghere created this revision.Feb 25 2022, 3:14 PM
JDevlieghere requested review of this revision.Feb 25 2022, 3:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 25 2022, 3:14 PM
aprantl accepted this revision.Feb 28 2022, 9:56 AM
This revision is now accepted and ready to land.Feb 28 2022, 9:56 AM
This revision was landed with ongoing or failed builds.Feb 28 2022, 3:03 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2022, 3:03 PM
tmatheson added inline comments.
llvm/include/llvm/Support/WithColor.h
142

This introduces a global constructor call into libSupport, which it should not. See https://reviews.llvm.org/rG5eb2e9aa64b7be7cd8ed7f36de19c2c9bdf1977c