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.

87 lines
2.4 KiB

  1. from __future__ import print_function
  2. Import("env")
  3. import os
  4. import sys
  5. TRAVIS = os.environ.get("TRAVIS")
  6. PIO_PLATFORM = env.PioPlatform()
  7. class ExtraScriptError(Exception):
  8. pass
  9. # Most portable way, without depending on platformio internals
  10. def subprocess_libdeps(lib_deps, storage=None, silent=True):
  11. import subprocess
  12. args = [env.subst("$PYTHONEXE"), "-mplatformio", "lib"]
  13. if not storage:
  14. args.append("-g")
  15. else:
  16. args.extend(["-d", storage])
  17. args.append("install")
  18. if silent:
  19. args.append("-s")
  20. args.extend(lib_deps)
  21. subprocess.check_call(args)
  22. # Avoid spawning pio lib every time, hook into the LibraryManager API (sort-of internal)
  23. def library_manager_libdeps(lib_deps, storage=None):
  24. from platformio.managers.lib import LibraryManager
  25. from platformio.project.helpers import get_project_global_lib_dir
  26. if not storage:
  27. manager = LibraryManager(get_project_global_lib_dir())
  28. else:
  29. manager = LibraryManager(storage)
  30. for lib in lib_deps:
  31. if manager.get_package_dir(*manager.parse_pkg_uri(lib)):
  32. continue
  33. print("installing: {}".format(lib), file=sys.stderr)
  34. manager.install(lib)
  35. def get_shared_libdeps_dir(section, name):
  36. cfg = env.GetProjectConfig()
  37. if not cfg.has_option(section, name):
  38. raise ExtraScriptError("{}.{} is required to be set".format(section, name))
  39. opt = cfg.get(section, name)
  40. if not opt in env.GetProjectOption("lib_extra_dirs"):
  41. raise ExtraScriptError(
  42. "lib_extra_dirs must contain {}.{}".format(section, name)
  43. )
  44. return os.path.join(env["PROJECT_DIR"], opt)
  45. def ensure_platform_updated():
  46. if PIO_PLATFORM.are_outdated_packages():
  47. print("updating platform packages", file=sys.stderr)
  48. PIO_PLATFORM.update_packages()
  49. # latest toolchain is still optional with PIO (TODO: recheck after 2.6.0!)
  50. ensure_platform_updated()
  51. # to speed-up build process, install libraries in either global or local shared storage
  52. if os.environ.get("ESPURNA_PIO_SHARED_LIBRARIES"):
  53. if TRAVIS:
  54. storage = None
  55. print("using global library storage", file=sys.stderr)
  56. else:
  57. storage = get_shared_libdeps_dir("common", "shared_libdeps_dir")
  58. print("using shared library storage: ", storage, file=sys.stderr)
  59. subprocess_libdeps(env.GetProjectOption("lib_deps"), storage)