fbt_tweaks.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import os
  2. import sys
  3. import traceback
  4. import SCons.Warnings as Warnings
  5. from ansi.color import fg
  6. from SCons.Errors import UserError
  7. # from SCons.Script.Main import find_deepest_user_frame
  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