fbt_tweaks.py 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import SCons.Warnings as Warnings
  2. # from SCons.Script.Main import find_deepest_user_frame
  3. from ansi.color import fg, bg, fx
  4. import traceback
  5. import sys
  6. import os
  7. def find_deepest_user_frame(tb):
  8. tb.reverse()
  9. # find the deepest traceback frame that is not part
  10. # of SCons:
  11. for frame in tb:
  12. filename = frame[0]
  13. if filename.find("fbt_tweaks") != -1:
  14. continue
  15. if filename.find(os.sep + "SCons" + os.sep) == -1:
  16. return frame
  17. return tb[0]
  18. def fbt_warning(e):
  19. filename, lineno, routine, dummy = find_deepest_user_frame(
  20. traceback.extract_stack()
  21. )
  22. fbt_line = "\nfbt: warning: %s\n" % e.args[0]
  23. sys.stderr.write(fg.boldmagenta(fbt_line))
  24. fbt_line = (
  25. fg.yellow("%s, line %d, " % (routine, lineno)) + 'in file "%s"\n' % filename
  26. )
  27. sys.stderr.write(fg.yellow(fbt_line))
  28. def generate(env):
  29. Warnings._warningOut = fbt_warning
  30. def exists():
  31. return True