site_init.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from SCons.Script import GetBuildFailures
  2. import sys
  3. import os
  4. import atexit
  5. from ansi.color import fg, fx
  6. sys.path.insert(0, os.path.join(os.getcwd(), "scripts"))
  7. sys.path.insert(0, os.path.join(os.getcwd(), "lib/cxxheaderparser"))
  8. def bf_to_str(bf):
  9. """Convert an element of GetBuildFailures() to a string
  10. in a useful way."""
  11. import SCons.Errors
  12. if bf is None: # unknown targets product None in list
  13. return "(unknown tgt)"
  14. elif isinstance(bf, SCons.Errors.StopError):
  15. return fg.yellow(str(bf))
  16. elif bf.node:
  17. return fg.yellow(str(bf.node)) + ": " + bf.errstr
  18. elif bf.filename:
  19. return fg.yellow(bf.filename) + ": " + bf.errstr
  20. return fg.yellow("unknown failure: ") + bf.errstr
  21. def display_build_status():
  22. """Display the build status. Called by atexit.
  23. Here you could do all kinds of complicated things."""
  24. bf = GetBuildFailures()
  25. if bf:
  26. # bf is normally a list of build failures; if an element is None,
  27. # it's because of a target that scons doesn't know anything about.
  28. failures_message = "\n".join([bf_to_str(x) for x in bf if x is not None])
  29. print()
  30. print(fg.brightred(fx.bold("*" * 10 + " FBT ERRORS " + "*" * 10)))
  31. print(failures_message)
  32. atexit.register(display_build_status)