3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
8 # Replaces the default formatter by one which understands GCC output and colorizes it.
10 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
11 __copyright__ = "Jérôme Carretero, 2012"
14 from waflib import Logs
16 class ColorGCCFormatter(Logs.formatter):
17 def __init__(self, colors):
19 Logs.formatter.__init__(self)
20 def format(self, rec):
21 frame = sys._getframe()
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]):
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)
37 rec.msg = "\n".join(lines)
39 return Logs.formatter.format(self, rec)
42 Logs.log.handlers[0].setFormatter(ColorGCCFormatter(Logs.colors))