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.

82 lines
2.4 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 remove_float_support():
  32. flags = " ".join(env['LINKFLAGS'])
  33. print flags
  34. flags = flags.replace("-u _printf_float", "")
  35. flags = flags.replace("-u _scanf_float", "")
  36. newflags = flags.split()
  37. env.Replace(
  38. LINKFLAGS = newflags
  39. )
  40. def cpp_check(source, target, env):
  41. print("Started cppcheck...\n")
  42. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  43. print("Finished cppcheck...\n")
  44. def check_size(source, target, env):
  45. time.sleep(2)
  46. size = target[0].get_size()
  47. print clr(Color.LIGHT_BLUE, "Binary size: %s bytes" % size)
  48. #if size > 512000:
  49. # print clr(Color.LIGHT_RED, "File too large for OTA!")
  50. # Exit(1)
  51. def add_build_flags(source, target, env):
  52. build_h = "espurna/config/build.h"
  53. build_flags = env['BUILD_FLAGS'][0]
  54. lines = open(build_h).readlines()
  55. with open(build_h, "w") as fh:
  56. for line in lines:
  57. if "APP_BUILD_FLAGS" in line:
  58. fh.write("#define APP_BUILD_FLAGS \"%s\"" % build_flags)
  59. else:
  60. fh.write(line)
  61. # ------------------------------------------------------------------------------
  62. # Hooks
  63. # ------------------------------------------------------------------------------
  64. remove_float_support()
  65. #env.AddPreAction("buildprog", cpp_check)
  66. env.AddPreAction("$BUILD_DIR/src/espurna.ino.o", add_build_flags)
  67. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)