A man with a mission...

Highlight Warnings in Make

Curtis just gave me this incredibly handy piece of code that higlights errors and warnings in make output. Now, when I’m building, all the warnings are highlighted in yellow, and the errors in red. Just put the following in your bash profile script:

make()
{
  pathpat="(/[^/]*)+:[0-9]+"
  ccred=$(echo -e "\033[0;31m")
  ccyellow=$(echo -e "\033[0;33m")
  ccend=$(echo -e "\033[0m")
  /usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend%g"
  return ${PIPESTATUS[0]}
}

Of course, improvements and more ideas welcome! Thanks goes to Curtis for this!

comments

10 Responses to “Highlight Warnings in Make”

  1. David Humphrey on December 3rd, 2008

    Absolutely delicious. Thank you!

  2. Hanspeter on December 3rd, 2008

    Looks nice, but wordpress seems to have messed many of the quote characters.

  3. Shawn Wilsher on December 3rd, 2008

    @Hanspeter
    I think if you drag and copy, you should be good. I don’t see any escape issues – just some layout truncation issues.

  4. Daniel Holbert on December 3rd, 2008

    On Linux, you can just install the ‘colormake’ package and use that in place of make.

    (colormake should work on non-Linux platforms, too — you’d just need to download the perl & bash scripts and put them in the right places yourself)

    More info:
    http://bre.klaki.net/programs/colormake/

  5. Hanspeter on December 3rd, 2008

    Nope. It’s giving me curly quotes for the terminating quote on the first line, the opening quote on the 2nd line, and the ones around warning in the 2nd to last line. If you look at the source code of this page, wordpress is converting the quote characters into & # 8221; and & # 8220; (hopefully I spaced that out enough that it won’t convert them into the actual characters here…)

    (on windows, but obviously the wordpress output is system agnostic)

  6. Mike Beltzner on December 4th, 2008

    Any way we can get this styling applied to the buildlogs submitted to tinderbox so that it’s easier to spot the problems when investigating a failed build?

  7. blog.no-panic.at » Colorful make output on December 4th, 2008

    [...] via shawnwilsher.com [...]

  8. Shawn Wilsher on December 4th, 2008

    @Mike
    I honestly don’t know.

  9. adw on February 10th, 2009

    \o/

  10. Brad on May 29th, 2009

    for sed, -E appears to be an OSX only flag. I think the linux equivalent is -r, so:

    make()
    {
      pathpat="(/[^/]*)+:[0-9]+"
      ccred=$(echo -e "33[0;31m")
      ccyellow=$(echo -e "33[0;33m")
      ccend=$(echo -e "33[0m")
      /usr/bin/make "$@" 2>&1 | sed -r -e "/[Ee]rror[: ]/ s%$pathpat%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%$pathpat%$ccyellow&$ccend%g"
      return ${PIPESTATUS[0]}
    }