[cfe-dev] clang-tidy: controlling color diagnostics

don hinton via cfe-dev cfe-dev at lists.llvm.org
Sun Aug 27 22:56:08 PDT 2017


Okay, so I looked into this and -extra-arg and -extra-arg-before modify the
actual command line from the compilation database.  So, if you had actual
errors in your code, you could toggle the colors for that reporting.

However, this has nothing to do with the diagnostics created by
clang-tidy.  They are actually hard coded to colors if your systems has
them.  Here's the line you should look at.

  ClangTidy:99 DiagOpts->ShowColors =
llvm::sys::Process::StandardOutHasColors();

So, if you wanted to fix this, you could add an additional option to
clang-tidy that controls both.

hth...
don

On Sun, Aug 27, 2017 at 11:35 AM, Riyaz Puthiyapurayil <
Riyaz.Puthiyapurayil at synopsys.com> wrote:

> This seems like a limitation of clang-tidy. It is probably a simple fix.
> But not sure what is the appropriate way.
>
> Should this be supported via -extra-arg=-f[no-]color-diagnostics or
> should it be a clang-tidy option?
>
>
>
> *-Riyaz*
>
>
>
> *From:* don hinton [mailto:hintonda at gmail.com]
> *Sent:* Sunday, August 27, 2017 11:23 AM
>
> *To:* Riyaz Puthiyapurayil <Riyaz.Puthiyapurayil at synopsys.com>
> *Cc:* cfe-dev at lists.llvm.org
> *Subject:* Re: [cfe-dev] clang-tidy: controlling color diagnostics
>
>
>
> Ah, I see.  Not sure about clang-tidy.
>
>
>
>
>
> On Sun, Aug 27, 2017 at 10:23 AM, Riyaz Puthiyapurayil <
> Riyaz.Puthiyapurayil at synopsys.com> wrote:
>
> Thanks for your quick response. I am able to get colors on a terminal. But
> I am unable to control it with a command line option.
>
>
>
> I lose colors when I redirect the output to a file. With clang, I can
> force colors even when redirecting to a file using -fcolor-diagnostics
> option. However, -extra-arg=-fcolor-diagnostics doesn’t work with
> clang-tidy.
>
>
>
> Alternatively, if I want to turn off color onto a terminal, I can use
> -fno-color-diagnostics with clang. With clang-tidy, that also doesn’t work.
>
>
>
> I wonder if the following code in ClangTidy.cpp is the reason:
>
>
>
> class ErrorReporter {
>
>    . . .
>
>    *DiagOpts->ShowColors = llvm::sys::Process::StandardOutHasColors();*
>
> };
>
>
>
> clang does it differently—see parseShowColorArgs in
> CompilerInvocation.cpp:
>
>
>
>     if (O.matches(options::OPT_fcolor_diagnostics) ||
>
>       O.matches(options::OPT_fdiagnostics_color)) {
>
>     ShowColors = Colors_On;
>
>   } . . .
>
>   :
>
>   :
>
>   if (ShowColors == Colors_On ||
>
>      (ShowColors == Colors_Auto && llvm::sys::Process::
> StandardErrHasColors()))
>
>     return true;
>
>
>
> *-Riyaz*
>
>
>
> *From:* don hinton [mailto:hintonda at gmail.com]
> *Sent:* Sunday, August 27, 2017 10:10 AM
> *To:* Riyaz Puthiyapurayil <Riyaz.Puthiyapurayil at synopsys.com>
> *Cc:* cfe-dev at lists.llvm.org
> *Subject:* Re: [cfe-dev] clang-tidy: controlling color diagnostics
>
>
>
> Did you build it yourself?
>
>
>
> There's a test in llvm/cmake/config-ix.cmake that sets HAVE_TERMINFO,
> which needs to be set in order to enable colors.  If it's not set or set to
> 0, then you won't get colors.  Try installing one of the libraries
> mentioned in the test:  tinfo terminfo curses ncurses ncursesw.
>
>
>
> hth...
>
> don
>
>
>
> On Sun, Aug 27, 2017 at 9:45 AM, Riyaz Puthiyapurayil via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
> Is there a way to turn on/off color diagnostics in clang-tidy? Passing
> -f[no]-color-diagnostics via -extra-arg does not seem to have any effect.
>
>
>
> *-Riyaz*
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Ddev&d=DwMFaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=mMZWMrEZcvPMLSsEQSah9FOTwza1UudSDkAneN47U9lD3qu6gt3kpnIb4MWV77cM&m=tX0BuxmCivYFNsAnVEokmG1tKqzkY0aq9NPsWF4FrDY&s=0VTnLNcleH853NCiLDoE2fdaQ-4vaRRGdpmgOqSQVEE&e=>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170827/b94da77e/attachment.html>


More information about the cfe-dev mailing list