pio: consistent shared libs location

Do not install libraries globally in CI, use the specified PIO .ini option.
Similar to the other package installers, prefer package cache to the actual library storage contents.
This commit is contained in:
Maxim Prokhorov
2021-06-19 12:46:39 +03:00
parent 1600fcc133
commit f18f128e4b

View File

@@ -21,7 +21,7 @@ from SCons.Script import ARGUMENTS
from espurna_utils.build import merge_cpp
CI = "true" == os.environ.get("CI")
CI = "true" == os.environ.get("CI", "false")
PIO_PLATFORM = env.PioPlatform()
CONFIG = env.GetProjectConfig()
VERBOSE = "1" == ARGUMENTS.get("PIOVERBOSE", "0")
@@ -37,42 +37,18 @@ def log(message, verbose=False, file=sys.stderr):
# Most portable way, without depending on platformio internals
def subprocess_libdeps(lib_deps, storage=None, verbose=False):
def subprocess_libdeps(lib_deps, storage, verbose=False):
import subprocess
args = [env.subst("$PYTHONEXE"), "-mplatformio", "lib"]
if not storage:
args.append("-g")
else:
args.extend(["-d", storage])
args.append("install")
args = [env.subst("$PYTHONEXE"), "-mplatformio", "lib", "-d", storage, "install"]
if not verbose:
args.append("-s")
args.extend(lib_deps)
subprocess.check_call(args)
# Avoid spawning pio lib every time, hook into the LibraryManager API (sort-of internal)
def library_manager_libdeps(lib_deps, storage=None):
from platformio.managers.lib import LibraryManager
from platformio.project.helpers import get_project_global_lib_dir
if not storage:
manager = LibraryManager(get_project_global_lib_dir())
else:
manager = LibraryManager(storage)
for lib in lib_deps:
if manager.get_package_dir(*manager.parse_pkg_uri(lib)):
continue
log("installing: {}".format(lib))
manager.install(lib)
def get_shared_libdeps_dir(section, name):
if not CONFIG.has_option(section, name):
raise ExtraScriptError("{}.{} is required to be set".format(section, name))
@@ -133,15 +109,9 @@ if CI:
ensure_platform_updated()
break
# to speed-up build process, install libraries in either global or local shared storage
if os.environ.get("ESPURNA_PIO_SHARED_LIBRARIES"):
if CI:
storage = None
log("using global library storage")
else:
storage = get_shared_libdeps_dir("common", "shared_libdeps_dir")
log("using shared library storage: {}".format(storage))
# to speed-up build process, install libraries in a way they are shared between our envs
if "1" == os.environ.get("ESPURNA_PIO_SHARED_LIBRARIES", "0"):
storage = get_shared_libdeps_dir("common", "shared_libdeps_dir")
subprocess_libdeps(env.GetProjectOption("lib_deps"), storage, verbose=VERBOSE)
# tweak build system to ignore espurna.ino, but include user code
@@ -168,15 +138,3 @@ if "1" == os.environ.get("ESPURNA_BUILD_SINGLE_SOURCE", "0"):
relpath = os.path.relpath(abspath, "espurna")
cpp_files.append(relpath)
merge_cpp(cpp_files, "espurna/espurna_single_source.cpp")
# make sure to register as a valid command. however, it is always called right here
# (--list-targets is a kind-of inefficient for finding this, though, since it *will* install libs into .pio/ anyways...)
def install_libs_dummy(target, source, env):
pass
env.AddCustomTarget("install-libs", None, install_libs_dummy)
from SCons.Script import COMMAND_LINE_TARGETS
if "install-libs" in COMMAND_LINE_TARGETS:
storage = get_shared_libdeps_dir("common", "shared_libdeps_dir")
subprocess_libdeps(env.GetProjectOption("lib_deps"), storage, verbose=VERBOSE)
sys.exit(0)