Skip to content

Commit 0b8721c

Browse files
committed
Fix usermod libArchive setting
Monkey-patch PlatformIO to intercept the build process after library dependencies are loaded, but before the build is fully analyzed. This lets us enforce libArchive=False for usermods without making that setting global across all libraries. The rest of the fixup code is integrated at the same call site for simplicity.
1 parent 869e275 commit 0b8721c

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

pio-scripts/fixup_usermods.py

-17
This file was deleted.

pio-scripts/load_usermods.py

+37-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
Import('env')
2-
import os
2+
from pathlib import Path # For OS-agnostic path manipulation
33

4-
def find_usermod(mod_dir: str, mod: str):
4+
usermod_dir = Path(env["PROJECT_DIR"]) / "usermods"
5+
6+
def find_usermod(mod: str):
57
"""Locate this library in the usermods folder.
68
We do this to avoid needing to rename a bunch of folders;
79
this could be removed later
810
"""
911
# Check name match
10-
mp = f"{mod_dir}/{mod}"
11-
if os.path.exists(mp):
12+
mp = usermod_dir / mod
13+
if mp.exists():
1214
return mp
13-
mp = f"{mod_dir}/usermod_v2_{mod}"
14-
if os.path.exists(mp):
15+
mp = usermod_dir / f"usermod_v2_{mod}"
16+
if mp.exists():
1517
return mp
1618
raise RuntimeError(f"Couldn't locate module {mod} in usermods directory!")
1719

@@ -21,6 +23,34 @@ def find_usermod(mod_dir: str, mod: str):
2123
deps = env.GetProjectOption('lib_deps')
2224
src_dir = proj.get("platformio", "src_dir")
2325
src_dir = src_dir.replace('\\','/')
24-
mod_paths = {mod: find_usermod(f"{src_dir}/../usermods", mod) for mod in usermods.split(" ")}
26+
mod_paths = {mod: find_usermod(mod) for mod in usermods.split(" ")}
2527
usermods = [f"{mod} = symlink://{path}" for mod, path in mod_paths.items()]
2628
proj.set("env:" + env['PIOENV'], 'lib_deps', deps + usermods)
29+
30+
31+
# Monkey-patch ConfigureProjectLibBuilder to mark up the dependencies
32+
# Save the old value
33+
cpl = env.ConfigureProjectLibBuilder
34+
# Our new wrapper
35+
def cpl_wrapper(env):
36+
result = cpl.clone(env)()
37+
# Update usermod properties
38+
lib_builders = env.GetLibBuilders()
39+
um_deps = [dep for dep in lib_builders if usermod_dir in Path(dep.src_dir).parents]
40+
other_deps = [dep for dep in lib_builders if usermod_dir not in Path(dep.src_dir).parents]
41+
for um in um_deps:
42+
# Add include paths for all non-usermod dependencies
43+
for dep in other_deps:
44+
for dir in dep.get_include_dirs():
45+
um.env.PrependUnique(CPPPATH=dir)
46+
# Add the wled folder to the include path
47+
um.env.PrependUnique(CPPPATH=env["PROJECT_SRC_DIR"])
48+
# Make sure we link directly, not through an archive
49+
# Archives drop the .dtor table section we need
50+
build = um._manifest.get("build", {})
51+
build["libArchive"] = False
52+
um._manifest["build"] = build
53+
return result
54+
55+
# Replace the old one with ours
56+
env.AddMethod(cpl_wrapper, "ConfigureProjectLibBuilder")

platformio.ini

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ extra_scripts =
115115
post:pio-scripts/strip-floats.py
116116
pre:pio-scripts/user_config_copy.py
117117
pre:pio-scripts/load_usermods.py
118-
post:pio-scripts/fixup_usermods.py
119118
pre:pio-scripts/build_ui.py
120119
; post:pio-scripts/obj-dump.py ;; convenience script to create a disassembly dump of the firmware (hardcore debugging)
121120

0 commit comments

Comments
 (0)