4

b2 release link=static toolset=clang works, but it does not show the nice colors that I find useful in clang's output.

TemplateRex
  • 69,038
  • 19
  • 164
  • 304
Humble Debugger
  • 4,439
  • 11
  • 39
  • 56

2 Answers2

2

Disclaimer: this is not an answer solving your problem, but it takes too much space to put this in a comment.

Here's a brief Holmesian elimination process. First, according to the Clang documentation, color is enabled only when a color-capable terminal is detected. And secondly, according to the Boost.Jam documentation, all environment variables are automatically imported into its built-in .ENVIRON module. Finally, you do indeed have a color-capable terminal. Yet it does not work. Even forcing the issue with an explicit Clang command line argument

./b2 install --toolset=clang --cxxflag=-fcolor-diagnostics

fails to display colored diagnostics. My only conclusion is that somehow b2 does not launch its build inside a color coded terminal. Upon further digging based on your comments, I found a related problem on another build system:

The reason for this is that ninja sets subprocess stdout/stderr to a pipe (Subprocess::Start(), subprocess.cc), and clang checks if StandardErrHasColors() (tools/clang/lib/Driver/Tools.cpp), which is false if !isatty(2) (lib/Support/Unix/Process.inc).

I looked around a bit, and the way to do this seems to be to call fork_pty() to run the child in a pseudo terminal. I don't know if this would impact subprocess creation time, and if opening ~4000 pseudo ttys (a chrome build at -j10000) is considered good form.

(It's possible to force clang to always emit color escaped codes using "-Xclang -fcolor-diagnostics", but that's pretty hacky. make doesn't seem to override stderr on unix as far as I can tell, child_execute_job() in job.c)

Conclusion: you might have to dig into the b2 internals to see if there is some output redirection taking place that prevents the color-coding. Alternatively, you could ask on the Boost.Build mailinglist. Hopefully this helps you along a bit further.

Update: there is a long standing ticket on the Boost SVN site that deals with this.

TemplateRex
  • 69,038
  • 19
  • 164
  • 304
  • Thanks, but I knew this part. $TERM is xterm-256color. Invoking clang from command line displays colors. I am not able to use the SCons question directly. I guess I need to add something to user-config.jam but I don't know what. – Humble Debugger May 01 '13 at 13:34
  • @HumbleDebugger if you `echo` your `TERM` variable from inside your `user-config.jam`, what output do you get? – TemplateRex May 01 '13 at 13:38
  • @HumbleDebugger I'm not at a build machine right now, but could you try `b2 -s"TERM=xterm-256color"` followed by your other build arguments? – TemplateRex May 01 '13 at 13:56
  • @HumbleDebugger I did some more digging and rewrote my findings. Sorry to say there is no solution. I am keeping this answer for future reference. – TemplateRex May 01 '13 at 18:27
  • @HumbleDebugger Found an ticket on the Boost SVN site, see updated answer. – TemplateRex May 02 '13 at 06:54
  • Thanks for the effort. I did not think it would go this deep. – Humble Debugger May 03 '13 at 16:55
  • @TemplateRex After I added -fcolor-diagnostics to Jamfile I get coloured output. Maybe it has been fixed since your original comment? I am using Boost.Build 2014.03-svn in the KDE Konsole terminal emulator. – Jan Šimek Nov 07 '14 at 22:33
  • @JanŠimek Glad to hear it got fixed. – TemplateRex Nov 08 '14 at 19:51
1

Seems the core issue was somehow solved, but there's a little more explaining to be done regarding it.

If you want colors, you can use this in user-config.jam:

using clang : : : <compileflags>-fcolor-diagnostics ;

However, my personal preference is to handle this in my Jamroot by using project requirements so others don't need to deal with it:

project my_project : requirements
  <toolset>clang:<cflags>-fcolor-diagnostics
  <toolset>clang:<cxxflags>-fcolor-diagnostics
;
kirbyfan64sos
  • 10,377
  • 6
  • 54
  • 75