Skip to content

Commit 75cd411

Browse files
committed
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.
1 parent 792a7aa commit 75cd411

File tree

3 files changed

+16
-33
lines changed

3 files changed

+16
-33
lines changed

pio-scripts/load_usermods.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@
99

1010
usermod_dir = Path(env["PROJECT_DIR"]).resolve() / "usermods"
1111

12-
# "usermods" environment: expand list of usermods to everything in the folder
13-
if env['PIOENV'] == "usermods":
14-
# Add all usermods
15-
all_usermods = [f for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()]
16-
env.GetProjectConfig().set(f"env:usermods", 'custom_usermods', " ".join([f.name for f in all_usermods]))
17-
1812
# Utility functions
1913
def find_usermod(mod: str) -> Path:
2014
"""Locate this library in the usermods folder.
@@ -41,38 +35,26 @@ def is_wled_module(dep: LibBuilderBase) -> bool:
4135
## Script starts here
4236
# Process usermod option
4337
usermods = env.GetProjectOption("custom_usermods","")
38+
39+
# Handle "all usermods" case
40+
if usermods == '*':
41+
usermods = [f.name for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()]
42+
# Update the environment, as many modules use scripts to detect their dependencies
43+
env.GetProjectConfig().set("env:" + env['PIOENV'], 'custom_usermods', " ".join(usermods))
44+
# Leave a note for the validation script
45+
env.GetProjectConfig().set("env:" + env['PIOENV'], 'custom_all_usermods_enabled', "1")
46+
else:
47+
usermods = usermods.split()
48+
4449
if usermods:
4550
# Inject usermods in to project lib_deps
4651
proj = env.GetProjectConfig()
4752
deps = env.GetProjectOption('lib_deps')
4853
src_dir = proj.get("platformio", "src_dir")
4954
src_dir = src_dir.replace('\\','/')
50-
mod_paths = {mod: find_usermod(mod) for mod in usermods.split()}
55+
mod_paths = {mod: find_usermod(mod) for mod in usermods}
5156
usermods = [f"{mod} = symlink://{path.resolve()}" for mod, path in mod_paths.items()]
5257
proj.set("env:" + env['PIOENV'], 'lib_deps', deps + usermods)
53-
# Force usermods to be installed in to the environment build state before the LDF runs
54-
# Otherwise we won't be able to see them until it's too late to change their paths for LDF
55-
# Logic is largely borrowed from PlaformIO internals
56-
not_found_specs = []
57-
for spec in usermods:
58-
found = False
59-
for storage_dir in env.GetLibSourceDirs():
60-
#print(f"Checking {storage_dir} for {spec}")
61-
lm = LibraryPackageManager(storage_dir)
62-
if lm.get_package(spec):
63-
#print("Found!")
64-
found = True
65-
break
66-
if not found:
67-
#print("Missing!")
68-
not_found_specs.append(spec)
69-
if not_found_specs:
70-
lm = LibraryPackageManager(
71-
env.subst(os.path.join("$PROJECT_LIBDEPS_DIR", "$PIOENV"))
72-
)
73-
for spec in not_found_specs:
74-
#print(f"LU: forcing install of {spec}")
75-
lm.install(spec)
7658

7759

7860
# Utility function for assembling usermod include paths

pio-scripts/validate_usermods.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,6 @@ def validate_map_file(source, target, env):
8989
return None
9090

9191
Import("env")
92-
env.Append(LINKFLAGS=[env.subst("-Wl,--Map=${BUILD_DIR}/${PROGNAME}.map")])
93-
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", Action(validate_map_file, cmdstr='Checking linked usermods in map file...'))
92+
if not env.GetProjectOption("custom_all_usermods_enabled",""): # TODO: fix handling of platform mismatches
93+
env.Append(LINKFLAGS=[env.subst("-Wl,--Map=${BUILD_DIR}/${PROGNAME}.map")])
94+
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", Action(validate_map_file, cmdstr='Checking linked usermods in map file...'))

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,5 +660,5 @@ build_flags = ${common.build_flags} ${esp32_idf_V4.build_flags} -D WLED_RELEASE_
660660
lib_deps = ${esp32_idf_V4.lib_deps}
661661
monitor_filters = esp32_exception_decoder
662662
board_build.flash_mode = dio
663-
; custom_usermods = *every folder with library.json* -- injected by pio-scripts/load_usermods.py
663+
custom_usermods = * ; Expands to all usermods in usermods folder
664664
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat

0 commit comments

Comments
 (0)