fbt_tweaks.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import SCons.Warnings as Warnings
  2. from SCons.Errors import UserError
  3. # from SCons.Script.Main import find_deepest_user_frame
  4. from ansi.color import fg, bg, fx
  5. import traceback
  6. import sys
  7. import os
  8. def find_deepest_user_frame(tb):
  9. tb.reverse()
  10. # find the deepest traceback frame that is not part
  11. # of SCons:
  12. for frame in tb:
  13. filename = frame[0]
  14. if filename.find("fbt_tweaks") != -1:
  15. continue
  16. if filename.find(os.sep + "SCons" + os.sep) == -1:
  17. return frame
  18. return tb[0]
  19. def fbt_warning(e):
  20. filename, lineno, routine, dummy = find_deepest_user_frame(
  21. traceback.extract_stack()
  22. )
  23. fbt_line = "\nfbt: warning: %s\n" % e.args[0]
  24. sys.stderr.write(fg.boldmagenta(fbt_line))
  25. fbt_line = (
  26. fg.yellow("%s, line %d, " % (routine, lineno)) + 'in file "%s"\n' % filename
  27. )
  28. sys.stderr.write(fg.yellow(fbt_line))
  29. def generate(env):
  30. if env.get("UFBT_WORK_DIR"):
  31. raise UserError(
  32. "You're trying to use a new format SDK on a legacy ufbt version. "
  33. "Please update ufbt to a version from PyPI: https://pypi.org/project/ufbt/"
  34. )
  35. Warnings._warningOut = fbt_warning
  36. def exists():
  37. return True