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.

90 lines
2.8 KiB

6 years ago
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os
  4. import sys
  5. from subprocess import call
  6. import click
  7. Import("env", "projenv")
  8. # ------------------------------------------------------------------------------
  9. # Utils
  10. # ------------------------------------------------------------------------------
  11. class Color(object):
  12. BLACK = '\x1b[1;30m'
  13. RED = '\x1b[1;31m'
  14. GREEN = '\x1b[1;32m'
  15. YELLOW = '\x1b[1;33m'
  16. BLUE = '\x1b[1;34m'
  17. MAGENTA = '\x1b[1;35m'
  18. CYAN = '\x1b[1;36m'
  19. WHITE = '\x1b[1;37m'
  20. LIGHT_GREY = '\x1b[0;30m'
  21. LIGHT_RED = '\x1b[0;31m'
  22. LIGHT_GREEN = '\x1b[0;32m'
  23. LIGHT_YELLOW = '\x1b[0;33m'
  24. LIGHT_BLUE = '\x1b[0;34m'
  25. LIGHT_MAGENTA = '\x1b[0;35m'
  26. LIGHT_CYAN = '\x1b[0;36m'
  27. LIGHT_WHITE = '\x1b[0;37m'
  28. def clr(color, text):
  29. return color + str(text) + '\x1b[0m'
  30. def print_warning(message, color=Color.LIGHT_YELLOW):
  31. print(clr(color, message), file=sys.stderr)
  32. def print_filler(fill, color=Color.WHITE, err=False):
  33. width, _ = click.get_terminal_size()
  34. if len(fill) > 1:
  35. fill = fill[0]
  36. out = sys.stderr if err else sys.stdout
  37. print(clr(color, fill * width), file=out)
  38. # ------------------------------------------------------------------------------
  39. # Callbacks
  40. # ------------------------------------------------------------------------------
  41. def remove_float_support():
  42. flags = " ".join(env['LINKFLAGS'])
  43. flags = flags.replace("-u _printf_float", "")
  44. flags = flags.replace("-u _scanf_float", "")
  45. newflags = flags.split()
  46. env.Replace(
  47. LINKFLAGS = newflags
  48. )
  49. def cpp_check(source, target, env):
  50. print("Started cppcheck...\n")
  51. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  52. print("Finished cppcheck...\n")
  53. def check_size(source, target, env):
  54. (binary,) = target
  55. path = binary.get_abspath()
  56. size = os.stat(path).st_size
  57. print(clr(Color.LIGHT_BLUE, "Binary size: {} bytes".format(size)))
  58. # Warn 1MB variants about exceeding OTA size limit
  59. flash_size = int(env.BoardConfig().get("upload.maximum_size", 0))
  60. if (flash_size == 1048576) and (size >= 512000):
  61. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  62. print_warning("File is too large for OTA! Here you can find instructions on how to flash it:")
  63. print_warning("https://github.com/xoseperez/espurna/wiki/TwoStepUpdates", color=Color.LIGHT_CYAN)
  64. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  65. # ------------------------------------------------------------------------------
  66. # Hooks
  67. # ------------------------------------------------------------------------------
  68. # Always show warnings for project code
  69. projenv.ProcessUnFlags("-w")
  70. remove_float_support()
  71. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)