diff --git a/pio-scripts/load_usermods.py b/pio-scripts/load_usermods.py index ab3c6476a..27a4590d1 100644 --- a/pio-scripts/load_usermods.py +++ b/pio-scripts/load_usermods.py @@ -2,16 +2,19 @@ Import('env') import os.path from collections import deque from pathlib import Path # For OS-agnostic path manipulation +from platformio.builder.tools.piolib import LibBuilderBase from platformio.package.manager.library import LibraryPackageManager usermod_dir = Path(env["PROJECT_DIR"]) / "usermods" -all_usermods = [f for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()] +# "usermods" environment: expand list of usermods to everything in the folder if env['PIOENV'] == "usermods": # Add all usermods + all_usermods = [f for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()] env.GetProjectConfig().set(f"env:usermods", 'custom_usermods', " ".join([f.name for f in all_usermods])) -def find_usermod(mod: str): +# Utility functions +def find_usermod(mod: str) -> Path: """Locate this library in the usermods folder. We do this to avoid needing to rename a bunch of folders; this could be removed later @@ -28,6 +31,13 @@ def find_usermod(mod: str): return mp raise RuntimeError(f"Couldn't locate module {mod} in usermods directory!") +def is_wled_module(dep: LibBuilderBase) -> bool: + """Returns true if the specified library is a wled module + """ + return usermod_dir in Path(dep.src_dir).parents or str(dep.name).startswith("wled-") + +## Script starts here +# Process usermod option usermods = env.GetProjectOption("custom_usermods","") if usermods: # Inject usermods in to project lib_deps @@ -82,13 +92,6 @@ old_ConfigureProjectLibBuilder = env.ConfigureProjectLibBuilder # Our new wrapper def wrapped_ConfigureProjectLibBuilder(xenv): - # Update usermod properties - # Set libArchive before build actions are added - for um in (um for um in xenv.GetLibBuilders() if usermod_dir in Path(um.src_dir).parents): - build = um._manifest.get("build", {}) - build["libArchive"] = False - um._manifest["build"] = build - # Call the wrapped function result = old_ConfigureProjectLibBuilder.clone(xenv)() @@ -102,12 +105,18 @@ def wrapped_ConfigureProjectLibBuilder(xenv): for dep in result.depbuilders: cached_add_includes(dep, processed_deps, extra_include_dirs) - for um in [dep for dep in result.depbuilders if usermod_dir in Path(dep.src_dir).parents]: - # Add the wled folder to the include path - um.env.PrependUnique(CPPPATH=wled_dir) - # Add WLED's own dependencies - for dir in extra_include_dirs: - um.env.PrependUnique(CPPPATH=dir) + for dep in result.depbuilders: + if is_wled_module(dep): + # Add the wled folder to the include path + dep.env.PrependUnique(CPPPATH=wled_dir) + # Add WLED's own dependencies + for dir in extra_include_dirs: + dep.env.PrependUnique(CPPPATH=dir) + # Enforce that libArchive is not set; we must link them directly to the executable + if dep.lib_archive: + build = dep._manifest.get("build", {}) + build["libArchive"] = False + dep._manifest["build"] = build return result