1
1
Import ('env' )
2
- import os
2
+ from pathlib import Path # For OS-agnostic path manipulation
3
3
4
- def find_usermod (mod_dir : str , mod : str ):
4
+ usermod_dir = Path (env ["PROJECT_DIR" ]) / "usermods"
5
+
6
+ def find_usermod (mod : str ):
5
7
"""Locate this library in the usermods folder.
6
8
We do this to avoid needing to rename a bunch of folders;
7
9
this could be removed later
8
10
"""
9
11
# Check name match
10
- mp = f" { mod_dir } / { mod } "
11
- if os . path . exists (mp ):
12
+ mp = usermod_dir / mod
13
+ if mp . exists ():
12
14
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 ():
15
17
return mp
16
18
raise RuntimeError (f"Couldn't locate module { mod } in usermods directory!" )
17
19
@@ -21,6 +23,34 @@ def find_usermod(mod_dir: str, mod: str):
21
23
deps = env .GetProjectOption ('lib_deps' )
22
24
src_dir = proj .get ("platformio" , "src_dir" )
23
25
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 (" " )}
25
27
usermods = [f"{ mod } = symlink://{ path } " for mod , path in mod_paths .items ()]
26
28
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" )
0 commit comments