Fork of the espurna firmware for `mhsw` switches
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.

68 lines
2.1 KiB

  1. #!/usr/bin/env python
  2. from subprocess import call
  3. import os
  4. import time
  5. Import("env")
  6. # ------------------------------------------------------------------------------
  7. # Utils
  8. # ------------------------------------------------------------------------------
  9. class Color(object):
  10. BLACK = '\x1b[1;30m'
  11. RED = '\x1b[1;31m'
  12. GREEN = '\x1b[1;32m'
  13. YELLOW = '\x1b[1;33m'
  14. BLUE = '\x1b[1;34m'
  15. MAGENTA = '\x1b[1;35m'
  16. CYAN = '\x1b[1;36m'
  17. WHITE = '\x1b[1;37m'
  18. LIGHT_GREY = '\x1b[0;30m'
  19. LIGHT_RED = '\x1b[0;31m'
  20. LIGHT_GREEN = '\x1b[0;32m'
  21. LIGHT_YELLOW = '\x1b[0;33m'
  22. LIGHT_BLUE = '\x1b[0;34m'
  23. LIGHT_MAGENTA = '\x1b[0;35m'
  24. LIGHT_CYAN = '\x1b[0;36m'
  25. LIGHT_WHITE = '\x1b[0;37m'
  26. def clr(color, text):
  27. return color + str(text) + '\x1b[0m'
  28. # ------------------------------------------------------------------------------
  29. # Callbacks
  30. # ------------------------------------------------------------------------------
  31. def cpp_check(source, target, env):
  32. print("Started cppcheck...\n")
  33. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  34. print("Finished cppcheck...\n")
  35. def check_size(source, target, env):
  36. time.sleep(2)
  37. size = target[0].get_size()
  38. print clr(Color.LIGHT_BLUE, "Binary size: %s bytes" % size)
  39. #if size > 512000:
  40. # print clr(Color.LIGHT_RED, "File too large for OTA!")
  41. # Exit(1)
  42. def add_build_flags(source, target, env):
  43. build_h = "espurna/config/build.h"
  44. build_flags = env['BUILD_FLAGS'][0]
  45. lines = open(build_h).readlines()
  46. with open(build_h, "w") as fh:
  47. for line in lines:
  48. if "APP_BUILD_FLAGS" in line:
  49. fh.write("#define APP_BUILD_FLAGS \"%s\"" % build_flags)
  50. else:
  51. fh.write(line)
  52. # ------------------------------------------------------------------------------
  53. # Hooks
  54. # ------------------------------------------------------------------------------
  55. #env.AddPreAction("buildprog", cpp_check)
  56. env.AddPreAction("$BUILD_DIR/src/espurna.ino.o", add_build_flags)
  57. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)