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.

101 lines
3.2 KiB

6 years ago
6 years ago
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. from platformio import util
  8. import distutils.spawn
  9. Import("env")
  10. # ------------------------------------------------------------------------------
  11. # Utils
  12. # ------------------------------------------------------------------------------
  13. class Color(object):
  14. BLACK = '\x1b[1;30m'
  15. RED = '\x1b[1;31m'
  16. GREEN = '\x1b[1;32m'
  17. YELLOW = '\x1b[1;33m'
  18. BLUE = '\x1b[1;34m'
  19. MAGENTA = '\x1b[1;35m'
  20. CYAN = '\x1b[1;36m'
  21. WHITE = '\x1b[1;37m'
  22. LIGHT_GREY = '\x1b[0;30m'
  23. LIGHT_RED = '\x1b[0;31m'
  24. LIGHT_GREEN = '\x1b[0;32m'
  25. LIGHT_YELLOW = '\x1b[0;33m'
  26. LIGHT_BLUE = '\x1b[0;34m'
  27. LIGHT_MAGENTA = '\x1b[0;35m'
  28. LIGHT_CYAN = '\x1b[0;36m'
  29. LIGHT_WHITE = '\x1b[0;37m'
  30. def clr(color, text):
  31. return color + str(text) + '\x1b[0m'
  32. def print_warning(message, color=Color.LIGHT_YELLOW):
  33. print(clr(color, message), file=sys.stderr)
  34. def print_filler(fill, color=Color.WHITE, err=False):
  35. width, _ = click.get_terminal_size()
  36. if len(fill) > 1:
  37. fill = fill[0]
  38. out = sys.stderr if err else sys.stdout
  39. print(clr(color, fill * width), file=out)
  40. # ------------------------------------------------------------------------------
  41. # Callbacks
  42. # ------------------------------------------------------------------------------
  43. def remove_float_support():
  44. flags = " ".join(env['LINKFLAGS'])
  45. flags = flags.replace("-u _printf_float", "")
  46. flags = flags.replace("-u _scanf_float", "")
  47. newflags = flags.split()
  48. env.Replace(
  49. LINKFLAGS = newflags
  50. )
  51. def cpp_check(source, target, env):
  52. print("Started cppcheck...\n")
  53. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  54. print("Finished cppcheck...\n")
  55. def check_size(source, target, env):
  56. (binary,) = target
  57. path = binary.get_abspath()
  58. size = os.stat(path).st_size
  59. print(clr(Color.LIGHT_BLUE, "Binary size: {} bytes".format(size)))
  60. # Warn 1MB variants about exceeding OTA size limit
  61. flash_size = int(env.BoardConfig().get("upload.maximum_size", 0))
  62. if (flash_size == 1048576) and (size >= 512000):
  63. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  64. print_warning("File is too large for OTA! Here you can find instructions on how to flash it:")
  65. print_warning("https://github.com/xoseperez/espurna/wiki/TwoStepUpdates", color=Color.LIGHT_CYAN)
  66. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  67. def build_webui(env):
  68. if distutils.spawn.find_executable("node"):
  69. config = util.load_project_config()
  70. kv = dict(config.items("env:" + env.get('PIOENV')))
  71. modules = kv["modules"] if "modules" in kv else "all"
  72. env.Execute("WEBUI_MODULES=\"%s\" node node_modules/gulp/bin/gulp.js" % modules)
  73. else:
  74. print_warning("Not building the web UI image ('node' does not exist in the path)")
  75. # ------------------------------------------------------------------------------
  76. # Hooks
  77. # ------------------------------------------------------------------------------
  78. remove_float_support()
  79. build_webui(env)
  80. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)