mirror of
https://github.com/wled/WLED.git
synced 2025-07-24 19:26:40 +00:00
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.
This commit is contained in:
parent
792a7aa081
commit
75cd411073
@ -9,12 +9,6 @@ from platformio.package.manager.library import LibraryPackageManager
|
|||||||
|
|
||||||
usermod_dir = Path(env["PROJECT_DIR"]).resolve() / "usermods"
|
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
|
# Utility functions
|
||||||
def find_usermod(mod: str) -> Path:
|
def find_usermod(mod: str) -> Path:
|
||||||
"""Locate this library in the usermods folder.
|
"""Locate this library in the usermods folder.
|
||||||
@ -41,38 +35,26 @@ def is_wled_module(dep: LibBuilderBase) -> bool:
|
|||||||
## Script starts here
|
## Script starts here
|
||||||
# Process usermod option
|
# Process usermod option
|
||||||
usermods = env.GetProjectOption("custom_usermods","")
|
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:
|
if usermods:
|
||||||
# Inject usermods in to project lib_deps
|
# Inject usermods in to project lib_deps
|
||||||
proj = env.GetProjectConfig()
|
proj = env.GetProjectConfig()
|
||||||
deps = env.GetProjectOption('lib_deps')
|
deps = env.GetProjectOption('lib_deps')
|
||||||
src_dir = proj.get("platformio", "src_dir")
|
src_dir = proj.get("platformio", "src_dir")
|
||||||
src_dir = src_dir.replace('\\','/')
|
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()]
|
usermods = [f"{mod} = symlink://{path.resolve()}" for mod, path in mod_paths.items()]
|
||||||
proj.set("env:" + env['PIOENV'], 'lib_deps', deps + usermods)
|
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
|
# Utility function for assembling usermod include paths
|
||||||
|
@ -89,5 +89,6 @@ def validate_map_file(source, target, env):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
Import("env")
|
Import("env")
|
||||||
env.Append(LINKFLAGS=[env.subst("-Wl,--Map=${BUILD_DIR}/${PROGNAME}.map")])
|
if not env.GetProjectOption("custom_all_usermods_enabled",""): # TODO: fix handling of platform mismatches
|
||||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", Action(validate_map_file, cmdstr='Checking linked usermods in map file...'))
|
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...'))
|
||||||
|
@ -660,5 +660,5 @@ build_flags = ${common.build_flags} ${esp32_idf_V4.build_flags} -D WLED_RELEASE_
|
|||||||
lib_deps = ${esp32_idf_V4.lib_deps}
|
lib_deps = ${esp32_idf_V4.lib_deps}
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
board_build.flash_mode = dio
|
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
|
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat
|
||||||
|
Loading…
x
Reference in New Issue
Block a user