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.

60 lines
1.8KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Replaces the default formatter by one which understands MSVC output and colorizes it.
  4. # Modified from color_gcc.py
  5. __author__ = __maintainer__ = "Alibek Omarov <a1ba.omarov@gmail.com>"
  6. __copyright__ = "Alibek Omarov, 2019"
  7. import sys
  8. from waflib import Logs
  9. class ColorMSVCFormatter(Logs.formatter):
  10. def __init__(self, colors):
  11. self.colors = colors
  12. Logs.formatter.__init__(self)
  13. def parseMessage(self, line, color):
  14. # Split messaage from 'disk:filepath: type: message'
  15. arr = line.split(':', 3)
  16. if len(arr) < 4:
  17. return line
  18. colored = self.colors.BOLD + arr[0] + ':' + arr[1] + ':' + self.colors.NORMAL
  19. colored += color + arr[2] + ':' + self.colors.NORMAL
  20. colored += arr[3]
  21. return colored
  22. def format(self, rec):
  23. frame = sys._getframe()
  24. while frame:
  25. func = frame.f_code.co_name
  26. if func == 'exec_command':
  27. cmd = frame.f_locals.get('cmd')
  28. if isinstance(cmd, list):
  29. # Fix file case, it may be CL.EXE or cl.exe
  30. argv0 = cmd[0].lower()
  31. if 'cl.exe' in argv0:
  32. lines = []
  33. # This will not work with "localized" versions
  34. # of MSVC
  35. for line in rec.msg.splitlines():
  36. if ': warning ' in line:
  37. lines.append(self.parseMessage(line, self.colors.YELLOW))
  38. elif ': error ' in line:
  39. lines.append(self.parseMessage(line, self.colors.RED))
  40. elif ': fatal error ' in line:
  41. lines.append(self.parseMessage(line, self.colors.RED + self.colors.BOLD))
  42. elif ': note: ' in line:
  43. lines.append(self.parseMessage(line, self.colors.CYAN))
  44. else:
  45. lines.append(line)
  46. rec.msg = "\n".join(lines)
  47. frame = frame.f_back
  48. return Logs.formatter.format(self, rec)
  49. def options(opt):
  50. Logs.log.handlers[0].setFormatter(ColorMSVCFormatter(Logs.colors))