third_party:waf: update to upstream 2.0.4 release
[bbaumbach/samba-autobuild/.git] / third_party / waf / waflib / extras / color_gcc.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #!/usr/bin/env python
6 # encoding: utf-8
7
8 # Replaces the default formatter by one which understands GCC output and colorizes it.
9
10 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
11 __copyright__ = "Jérôme Carretero, 2012"
12
13 import sys
14 from waflib import Logs
15
16 class ColorGCCFormatter(Logs.formatter):
17         def __init__(self, colors):
18                 self.colors = colors
19                 Logs.formatter.__init__(self)
20         def format(self, rec):
21                 frame = sys._getframe()
22                 while frame:
23                         func = frame.f_code.co_name
24                         if func == 'exec_command':
25                                 cmd = frame.f_locals.get('cmd')
26                                 if isinstance(cmd, list) and ('gcc' in cmd[0] or 'g++' in cmd[0]):
27                                         lines = []
28                                         for line in rec.msg.splitlines():
29                                                 if 'warning: ' in line:
30                                                         lines.append(self.colors.YELLOW + line)
31                                                 elif 'error: ' in line:
32                                                         lines.append(self.colors.RED + line)
33                                                 elif 'note: ' in line:
34                                                         lines.append(self.colors.CYAN + line)
35                                                 else:
36                                                         lines.append(line)
37                                         rec.msg = "\n".join(lines)
38                         frame = frame.f_back
39                 return Logs.formatter.format(self, rec)
40
41 def options(opt):
42         Logs.log.handlers[0].setFormatter(ColorGCCFormatter(Logs.colors))
43