From 75cd411073ad9e6c984b0f9ffc0c4efae8bede33 Mon Sep 17 00:00:00 2001 From: Will Miles Date: Sat, 24 May 2025 14:13:08 -0400 Subject: [PATCH] Improve all-usermod handling Use a magic custom_usermods string instead of a magic environment name; and disable the validation script as it triggers on the non- platform-compatible mods. --- pio-scripts/load_usermods.py | 42 +++++++++----------------------- pio-scripts/validate_usermods.py | 5 ++-- platformio.ini | 2 +- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/pio-scripts/load_usermods.py b/pio-scripts/load_usermods.py index 4e0457a0c..4f986d6fe 100644 --- a/pio-scripts/load_usermods.py +++ b/pio-scripts/load_usermods.py @@ -9,12 +9,6 @@ from platformio.package.manager.library import LibraryPackageManager usermod_dir = Path(env["PROJECT_DIR"]).resolve() / "usermods" -# "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])) - # Utility functions def find_usermod(mod: str) -> Path: """Locate this library in the usermods folder. @@ -41,38 +35,26 @@ def is_wled_module(dep: LibBuilderBase) -> bool: ## Script starts here # Process usermod option usermods = env.GetProjectOption("custom_usermods","") + +# Handle "all usermods" case +if usermods == '*': + usermods = [f.name for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()] + # Update the environment, as many modules use scripts to detect their dependencies + env.GetProjectConfig().set("env:" + env['PIOENV'], 'custom_usermods', " ".join(usermods)) + # Leave a note for the validation script + env.GetProjectConfig().set("env:" + env['PIOENV'], 'custom_all_usermods_enabled', "1") +else: + usermods = usermods.split() + if usermods: # Inject usermods in to project lib_deps proj = env.GetProjectConfig() deps = env.GetProjectOption('lib_deps') src_dir = proj.get("platformio", "src_dir") src_dir = src_dir.replace('\\','/') - mod_paths = {mod: find_usermod(mod) for mod in usermods.split()} + mod_paths = {mod: find_usermod(mod) for mod in usermods} usermods = [f"{mod} = symlink://{path.resolve()}" for mod, path in mod_paths.items()] proj.set("env:" + env['PIOENV'], 'lib_deps', deps + usermods) - # Force usermods to be installed in to the environment build state before the LDF runs - # Otherwise we won't be able to see them until it's too late to change their paths for LDF - # Logic is largely borrowed from PlaformIO internals - not_found_specs = [] - for spec in usermods: - found = False - for storage_dir in env.GetLibSourceDirs(): - #print(f"Checking {storage_dir} for {spec}") - lm = LibraryPackageManager(storage_dir) - if lm.get_package(spec): - #print("Found!") - found = True - break - if not found: - #print("Missing!") - not_found_specs.append(spec) - if not_found_specs: - lm = LibraryPackageManager( - env.subst(os.path.join("$PROJECT_LIBDEPS_DIR", "$PIOENV")) - ) - for spec in not_found_specs: - #print(f"LU: forcing install of {spec}") - lm.install(spec) # Utility function for assembling usermod include paths diff --git a/pio-scripts/validate_usermods.py b/pio-scripts/validate_usermods.py index d3cf5ea8c..a1a1e3c24 100644 --- a/pio-scripts/validate_usermods.py +++ b/pio-scripts/validate_usermods.py @@ -89,5 +89,6 @@ def validate_map_file(source, target, env): return None Import("env") -env.Append(LINKFLAGS=[env.subst("-Wl,--Map=${BUILD_DIR}/${PROGNAME}.map")]) -env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", Action(validate_map_file, cmdstr='Checking linked usermods in map file...')) +if not env.GetProjectOption("custom_all_usermods_enabled",""): # TODO: fix handling of platform mismatches + env.Append(LINKFLAGS=[env.subst("-Wl,--Map=${BUILD_DIR}/${PROGNAME}.map")]) + env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", Action(validate_map_file, cmdstr='Checking linked usermods in map file...')) diff --git a/platformio.ini b/platformio.ini index b713a2d39..e1a5014b0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -660,5 +660,5 @@ build_flags = ${common.build_flags} ${esp32_idf_V4.build_flags} -D WLED_RELEASE_ lib_deps = ${esp32_idf_V4.lib_deps} monitor_filters = esp32_exception_decoder board_build.flash_mode = dio -; custom_usermods = *every folder with library.json* -- injected by pio-scripts/load_usermods.py +custom_usermods = * ; Expands to all usermods in usermods folder board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat