jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1KB

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