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.

73 lines
2.0 KiB

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