thirdparty:waf: New files for waf 1.9.10
[Samba.git] / third_party / waf / waflib / extras / color_rvct.py
blob837fca2edf1051988813726ebc8b4dce4e5b5dfb
1 #!/usr/bin/env python
2 # encoding: utf-8
4 # Replaces the default formatter by one which understands RVCT output and colorizes it.
6 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
7 __copyright__ = "Jérôme Carretero, 2012"
9 import sys
10 import atexit
11 from waflib import Logs
13 errors = []
15 def show_errors():
16 for i, e in enumerate(errors):
17 if i > 5:
18 break
19 print("Error: %s" % e)
21 atexit.register(show_errors)
23 class RcvtFormatter(Logs.formatter):
24 def __init__(self, colors):
25 Logs.formatter.__init__(self)
26 self.colors = colors
27 def format(self, rec):
28 frame = sys._getframe()
29 while frame:
30 func = frame.f_code.co_name
31 if func == 'exec_command':
32 cmd = frame.f_locals['cmd']
33 if isinstance(cmd, list) and ('armcc' in cmd[0] or 'armld' in cmd[0]):
34 lines = []
35 for line in rec.msg.splitlines():
36 if 'Warning: ' in line:
37 lines.append(self.colors.YELLOW + line)
38 elif 'Error: ' in line:
39 lines.append(self.colors.RED + line)
40 errors.append(line)
41 elif 'note: ' in line:
42 lines.append(self.colors.CYAN + line)
43 else:
44 lines.append(line)
45 rec.msg = "\n".join(lines)
46 frame = frame.f_back
47 return Logs.formatter.format(self, rec)
49 def options(opt):
50 Logs.log.handlers[0].setFormatter(RcvtFormatter(Logs.colors))