Mirror of espurna firmware for wireless switches and more
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.

96 lines
2.7 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. CONFIG = env.GetProjectConfig()
  8. class ExtraScriptError(Exception):
  9. pass
  10. # Most portable way, without depending on platformio internals
  11. def subprocess_libdeps(lib_deps, storage=None, silent=True):
  12. import subprocess
  13. args = [env.subst("$PYTHONEXE"), "-mplatformio", "lib"]
  14. if not storage:
  15. args.append("-g")
  16. else:
  17. args.extend(["-d", storage])
  18. args.append("install")
  19. if silent:
  20. args.append("-s")
  21. args.extend(lib_deps)
  22. subprocess.check_call(args)
  23. # Avoid spawning pio lib every time, hook into the LibraryManager API (sort-of internal)
  24. def library_manager_libdeps(lib_deps, storage=None):
  25. from platformio.managers.lib import LibraryManager
  26. from platformio.project.helpers import get_project_global_lib_dir
  27. if not storage:
  28. manager = LibraryManager(get_project_global_lib_dir())
  29. else:
  30. manager = LibraryManager(storage)
  31. for lib in lib_deps:
  32. if manager.get_package_dir(*manager.parse_pkg_uri(lib)):
  33. continue
  34. print("installing: {}".format(lib), file=sys.stderr)
  35. manager.install(lib)
  36. def get_shared_libdeps_dir(section, name):
  37. if not CONFIG.has_option(section, name):
  38. raise ExtraScriptError("{}.{} is required to be set".format(section, name))
  39. opt = CONFIG.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. try:
  47. if PIO_PLATFORM.are_outdated_packages():
  48. print("updating platform packages", file=sys.stderr)
  49. PIO_PLATFORM.update_packages()
  50. except Exception:
  51. print(
  52. "Warning: no connection, cannot check for outdated packages",
  53. file=sys.stderr,
  54. )
  55. # latest toolchain is still optional with PIO (TODO: recheck after 2.6.0!)
  56. # also updates arduino core git to the latest master commit
  57. if TRAVIS and (
  58. env.GetProjectOption("platform") == CONFIG.get("common", "arduino_core_git")
  59. ):
  60. ensure_platform_updated()
  61. # to speed-up build process, install libraries in either global or local shared storage
  62. if os.environ.get("ESPURNA_PIO_SHARED_LIBRARIES"):
  63. if TRAVIS:
  64. storage = None
  65. print("using global library storage", file=sys.stderr)
  66. else:
  67. storage = get_shared_libdeps_dir("common", "shared_libdeps_dir")
  68. print("using shared library storage: ", storage, file=sys.stderr)
  69. subprocess_libdeps(env.GetProjectOption("lib_deps"), storage)