color_rvct.py (1317B)
1 #!/usr/bin/env python 2 # encoding: utf-8 3 4 # Replaces the default formatter by one which understands RVCT 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 import atexit 11 from waflib import Logs 12 13 errors = [] 14 15 def show_errors(): 16 for i, e in enumerate(errors): 17 if i > 5: 18 break 19 print("Error: %s" % e) 20 21 atexit.register(show_errors) 22 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) 48 49 def options(opt): 50 Logs.log.handlers[0].setFormatter(RcvtFormatter(Logs.colors)) 51