Update usermod deps earlier

When processing usermods, update their include path properties before
the LDF runs, so it can see through wled.h.
This commit is contained in:
Will Miles 2025-01-14 22:16:55 +00:00
parent 0b8721c25e
commit 270d75afe2

View File

@ -1,56 +1,56 @@
Import('env') Import('env')
from pathlib import Path # For OS-agnostic path manipulation from pathlib import Path # For OS-agnostic path manipulation
usermod_dir = Path(env["PROJECT_DIR"]) / "usermods" usermod_dir = Path(env["PROJECT_DIR"]) / "usermods"
def find_usermod(mod: str): def find_usermod(mod: str):
"""Locate this library in the usermods folder. """Locate this library in the usermods folder.
We do this to avoid needing to rename a bunch of folders; We do this to avoid needing to rename a bunch of folders;
this could be removed later this could be removed later
""" """
# Check name match # Check name match
mp = usermod_dir / mod mp = usermod_dir / mod
if mp.exists(): if mp.exists():
return mp return mp
mp = usermod_dir / f"usermod_v2_{mod}" mp = usermod_dir / f"usermod_v2_{mod}"
if mp.exists(): if mp.exists():
return mp return mp
raise RuntimeError(f"Couldn't locate module {mod} in usermods directory!") raise RuntimeError(f"Couldn't locate module {mod} in usermods directory!")
usermods = env.GetProjectOption("custom_usermods","") usermods = env.GetProjectOption("custom_usermods","")
if usermods: if usermods:
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.split(" ")}
usermods = [f"{mod} = symlink://{path}" for mod, path in mod_paths.items()] usermods = [f"{mod} = symlink://{path}" 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)
# Monkey-patch ConfigureProjectLibBuilder to mark up the dependencies # Monkey-patch ConfigureProjectLibBuilder to mark up the dependencies
# Save the old value # Save the old value
cpl = env.ConfigureProjectLibBuilder cpl = env.ConfigureProjectLibBuilder
# Our new wrapper # Our new wrapper
def cpl_wrapper(env): def cpl_wrapper(env):
result = cpl.clone(env)() # Update usermod properties
# Update usermod properties lib_builders = env.GetLibBuilders()
lib_builders = env.GetLibBuilders() um_deps = [dep for dep in lib_builders if usermod_dir in Path(dep.src_dir).parents]
um_deps = [dep for dep in lib_builders if usermod_dir in Path(dep.src_dir).parents] other_deps = [dep for dep in lib_builders if usermod_dir not in Path(dep.src_dir).parents]
other_deps = [dep for dep in lib_builders if usermod_dir not in Path(dep.src_dir).parents] for um in um_deps:
for um in um_deps: # Add include paths for all non-usermod dependencies
# Add include paths for all non-usermod dependencies for dep in other_deps:
for dep in other_deps: for dir in dep.get_include_dirs():
for dir in dep.get_include_dirs(): um.env.PrependUnique(CPPPATH=dir)
um.env.PrependUnique(CPPPATH=dir) # Add the wled folder to the include path
# Add the wled folder to the include path um.env.PrependUnique(CPPPATH=env["PROJECT_SRC_DIR"])
um.env.PrependUnique(CPPPATH=env["PROJECT_SRC_DIR"]) # Make sure we link directly, not through an archive
# Make sure we link directly, not through an archive # Archives drop the .dtor table section we need
# Archives drop the .dtor table section we need build = um._manifest.get("build", {})
build = um._manifest.get("build", {}) build["libArchive"] = False
build["libArchive"] = False um._manifest["build"] = build
um._manifest["build"] = build return cpl.clone(env)()
return result
# Replace the old one with ours # Replace the old one with ours
env.AddMethod(cpl_wrapper, "ConfigureProjectLibBuilder") env.AddMethod(cpl_wrapper, "ConfigureProjectLibBuilder")