99
1010usermod_dir = Path (env ["PROJECT_DIR" ]).resolve () / "usermods"
1111
12- # "usermods" environment: expand list of usermods to everything in the folder
13- if env ['PIOENV' ] == "usermods" :
14- # Add all usermods
15- all_usermods = [f for f in usermod_dir .iterdir () if f .is_dir () and f .joinpath ('library.json' ).exists ()]
16- env .GetProjectConfig ().set (f"env:usermods" , 'custom_usermods' , " " .join ([f .name for f in all_usermods ]))
17-
1812# Utility functions
1913def find_usermod (mod : str ) -> Path :
2014 """Locate this library in the usermods folder.
@@ -41,38 +35,26 @@ def is_wled_module(dep: LibBuilderBase) -> bool:
4135## Script starts here
4236# Process usermod option
4337usermods = env .GetProjectOption ("custom_usermods" ,"" )
38+
39+ # Handle "all usermods" case
40+ if usermods == '*' :
41+ usermods = [f .name for f in usermod_dir .iterdir () if f .is_dir () and f .joinpath ('library.json' ).exists ()]
42+ # Update the environment, as many modules use scripts to detect their dependencies
43+ env .GetProjectConfig ().set ("env:" + env ['PIOENV' ], 'custom_usermods' , " " .join (usermods ))
44+ # Leave a note for the validation script
45+ env .GetProjectConfig ().set ("env:" + env ['PIOENV' ], 'custom_all_usermods_enabled' , "1" )
46+ else :
47+ usermods = usermods .split ()
48+
4449if usermods :
4550 # Inject usermods in to project lib_deps
4651 proj = env .GetProjectConfig ()
4752 deps = env .GetProjectOption ('lib_deps' )
4853 src_dir = proj .get ("platformio" , "src_dir" )
4954 src_dir = src_dir .replace ('\\ ' ,'/' )
50- mod_paths = {mod : find_usermod (mod ) for mod in usermods . split () }
55+ mod_paths = {mod : find_usermod (mod ) for mod in usermods }
5156 usermods = [f"{ mod } = symlink://{ path .resolve ()} " for mod , path in mod_paths .items ()]
5257 proj .set ("env:" + env ['PIOENV' ], 'lib_deps' , deps + usermods )
53- # Force usermods to be installed in to the environment build state before the LDF runs
54- # Otherwise we won't be able to see them until it's too late to change their paths for LDF
55- # Logic is largely borrowed from PlaformIO internals
56- not_found_specs = []
57- for spec in usermods :
58- found = False
59- for storage_dir in env .GetLibSourceDirs ():
60- #print(f"Checking {storage_dir} for {spec}")
61- lm = LibraryPackageManager (storage_dir )
62- if lm .get_package (spec ):
63- #print("Found!")
64- found = True
65- break
66- if not found :
67- #print("Missing!")
68- not_found_specs .append (spec )
69- if not_found_specs :
70- lm = LibraryPackageManager (
71- env .subst (os .path .join ("$PROJECT_LIBDEPS_DIR" , "$PIOENV" ))
72- )
73- for spec in not_found_specs :
74- #print(f"LU: forcing install of {spec}")
75- lm .install (spec )
7658
7759
7860# Utility function for assembling usermod include paths
0 commit comments