third_party/waf: upgrade to waf 2.0.8
[vlendec/samba-autobuild/.git] / third_party / waf / waflib / extras / color_gcc.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3
4 # Replaces the default formatter by one which understands GCC output and colorizes it.
5
6 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
7 __copyright__ = "Jérôme Carretero, 2012"
8
9 import sys
10 from waflib import Logs
11
12 class ColorGCCFormatter(Logs.formatter):
13         def __init__(self, colors):
14                 self.colors = colors
15                 Logs.formatter.__init__(self)
16         def format(self, rec):
17                 frame = sys._getframe()
18                 while frame:
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]):
23                                         lines = []
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)
31                                                 else:
32                                                         lines.append(line)
33                                         rec.msg = "\n".join(lines)
34                         frame = frame.f_back
35                 return Logs.formatter.format(self, rec)
36
37 def options(opt):
38         Logs.log.handlers[0].setFormatter(ColorGCCFormatter(Logs.colors))
39