4 # Replaces the default formatter by one which understands GCC output and colorizes it.
6 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
7 __copyright__ = "Jérôme Carretero, 2012"
10 from waflib import Logs
12 class ColorGCCFormatter(Logs.formatter):
13 def __init__(self, colors):
15 Logs.formatter.__init__(self)
16 def format(self, rec):
17 frame = sys._getframe()
19 func = frame.f_code.co_name
20 if func == 'exec_command':
21 cmd = frame.f_locals.get('cmd')
22 if isinstance(cmd, list) and ('gcc' in cmd[0] or 'g++' in cmd[0]):
24 for line in rec.msg.splitlines():
25 if 'warning: ' in line:
26 lines.append(self.colors.YELLOW + line)
27 elif 'error: ' in line:
28 lines.append(self.colors.RED + line)
29 elif 'note: ' in line:
30 lines.append(self.colors.CYAN + line)
33 rec.msg = "\n".join(lines)
35 return Logs.formatter.format(self, rec)
38 Logs.log.handlers[0].setFormatter(ColorGCCFormatter(Logs.colors))