Skip to content

Commit 7998650

Browse files
committed
Fix up usermod libArchive settings
The ConfigureProjectLibBuilder process will flush and reload the library settings from the on-disk manifests if any new library is installed at that stage. This has the side effect of reverting the libArchive setting applied to usermods which was performed prior to that call. Apply the setting afterwards, instead. Fixes wled#4597
1 parent d10714d commit 7998650

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

pio-scripts/load_usermods.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
import os.path
33
from collections import deque
44
from pathlib import Path # For OS-agnostic path manipulation
5+
from platformio.builder.tools.piolib import LibBuilderBase
56
from platformio.package.manager.library import LibraryPackageManager
67

78
usermod_dir = Path(env["PROJECT_DIR"]) / "usermods"
8-
all_usermods = [f for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()]
99

10+
# "usermods" environment: expand list of usermods to everything in the folder
1011
if env['PIOENV'] == "usermods":
1112
# Add all usermods
13+
all_usermods = [f for f in usermod_dir.iterdir() if f.is_dir() and f.joinpath('library.json').exists()]
1214
env.GetProjectConfig().set(f"env:usermods", 'custom_usermods', " ".join([f.name for f in all_usermods]))
1315

14-
def find_usermod(mod: str):
16+
# Utility functions
17+
def find_usermod(mod: str) -> Path:
1518
"""Locate this library in the usermods folder.
1619
We do this to avoid needing to rename a bunch of folders;
1720
this could be removed later
@@ -28,6 +31,13 @@ def find_usermod(mod: str):
2831
return mp
2932
raise RuntimeError(f"Couldn't locate module {mod} in usermods directory!")
3033

34+
def is_wled_module(dep: LibBuilderBase) -> bool:
35+
"""Returns true if the specified library is a wled module
36+
"""
37+
return usermod_dir in Path(dep.src_dir).parents or str(dep.name).startswith("wled-")
38+
39+
## Script starts here
40+
# Process usermod option
3141
usermods = env.GetProjectOption("custom_usermods","")
3242
if usermods:
3343
# Inject usermods in to project lib_deps
@@ -82,13 +92,6 @@ def cached_add_includes(dep, dep_cache: set, includes: deque):
8292

8393
# Our new wrapper
8494
def wrapped_ConfigureProjectLibBuilder(xenv):
85-
# Update usermod properties
86-
# Set libArchive before build actions are added
87-
for um in (um for um in xenv.GetLibBuilders() if usermod_dir in Path(um.src_dir).parents):
88-
build = um._manifest.get("build", {})
89-
build["libArchive"] = False
90-
um._manifest["build"] = build
91-
9295
# Call the wrapped function
9396
result = old_ConfigureProjectLibBuilder.clone(xenv)()
9497

@@ -102,12 +105,18 @@ def wrapped_ConfigureProjectLibBuilder(xenv):
102105
for dep in result.depbuilders:
103106
cached_add_includes(dep, processed_deps, extra_include_dirs)
104107

105-
for um in [dep for dep in result.depbuilders if usermod_dir in Path(dep.src_dir).parents]:
106-
# Add the wled folder to the include path
107-
um.env.PrependUnique(CPPPATH=wled_dir)
108-
# Add WLED's own dependencies
109-
for dir in extra_include_dirs:
110-
um.env.PrependUnique(CPPPATH=dir)
108+
for dep in result.depbuilders:
109+
if is_wled_module(dep):
110+
# Add the wled folder to the include path
111+
dep.env.PrependUnique(CPPPATH=wled_dir)
112+
# Add WLED's own dependencies
113+
for dir in extra_include_dirs:
114+
dep.env.PrependUnique(CPPPATH=dir)
115+
# Enforce that libArchive is not set; we must link them directly to the executable
116+
if dep.lib_archive:
117+
build = dep._manifest.get("build", {})
118+
build["libArchive"] = False
119+
dep._manifest["build"] = build
111120

112121
return result
113122

0 commit comments

Comments
 (0)