Skip to content

Fix up usermod libArchive settings #4669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions pio-scripts/load_usermods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
import os.path
from collections import deque
from pathlib import Path # For OS-agnostic path manipulation
from click import secho
from SCons.Script import Exit
from platformio.builder.tools.piolib import LibBuilderBase
from platformio.package.manager.library import LibraryPackageManager

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

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

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

def is_wled_module(dep: LibBuilderBase) -> bool:
"""Returns true if the specified library is a wled module
"""
return usermod_dir in Path(dep.src_dir).parents or str(dep.name).startswith("wled-")

## Script starts here
# Process usermod option
usermods = env.GetProjectOption("custom_usermods","")
if usermods:
# Inject usermods in to project lib_deps
Expand Down Expand Up @@ -82,13 +94,6 @@ def cached_add_includes(dep, dep_cache: set, includes: deque):

# Our new wrapper
def wrapped_ConfigureProjectLibBuilder(xenv):
# Update usermod properties
# Set libArchive before build actions are added
for um in (um for um in xenv.GetLibBuilders() if usermod_dir in Path(um.src_dir).parents):
build = um._manifest.get("build", {})
build["libArchive"] = False
um._manifest["build"] = build

# Call the wrapped function
result = old_ConfigureProjectLibBuilder.clone(xenv)()

Expand All @@ -102,12 +107,25 @@ def wrapped_ConfigureProjectLibBuilder(xenv):
for dep in result.depbuilders:
cached_add_includes(dep, processed_deps, extra_include_dirs)

for um in [dep for dep in result.depbuilders if usermod_dir in Path(dep.src_dir).parents]:
# Add the wled folder to the include path
um.env.PrependUnique(CPPPATH=wled_dir)
# Add WLED's own dependencies
for dir in extra_include_dirs:
um.env.PrependUnique(CPPPATH=dir)
broken_usermods = []
for dep in result.depbuilders:
if is_wled_module(dep):
# Add the wled folder to the include path
dep.env.PrependUnique(CPPPATH=str(wled_dir))
# Add WLED's own dependencies
for dir in extra_include_dirs:
dep.env.PrependUnique(CPPPATH=str(dir))
# Enforce that libArchive is not set; we must link them directly to the executable
if dep.lib_archive:
broken_usermods.append(dep)

if broken_usermods:
broken_usermods = [usermod.name for usermod in broken_usermods]
secho(
f"ERROR: libArchive=false is missing on usermod(s) {' '.join(broken_usermods)} -- modules will not compile in correctly",
fg="red",
err=True)
Exit(1)

return result

Expand Down
1 change: 1 addition & 0 deletions usermods/ADS1115_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "ADS1115_v2",
"build": { "libArchive": false },
"dependencies": {
"Adafruit BusIO": "https://github.com/adafruit/Adafruit_BusIO#1.13.2",
"Adafruit ADS1X15": "https://github.com/adafruit/Adafruit_ADS1X15#2.4.0"
Expand Down
1 change: 1 addition & 0 deletions usermods/AHT10_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "AHT10_v2",
"build": { "libArchive": false },
"dependencies": {
"enjoyneering/AHT10":"~1.1.0"
}
Expand Down
3 changes: 2 additions & 1 deletion usermods/Analog_Clock/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "Analog_Clock"
"name": "Analog_Clock",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/Animated_Staircase/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "Animated_Staircase"
"name": "Animated_Staircase",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/BH1750_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "BH1750_v2",
"build": { "libArchive": false },
"dependencies": {
"claws/BH1750":"^1.2.0"
}
Expand Down
1 change: 1 addition & 0 deletions usermods/BME280_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "BME280_v2",
"build": { "libArchive": false },
"dependencies": {
"finitespace/BME280":"~3.0.0"
}
Expand Down
1 change: 1 addition & 0 deletions usermods/BME68X_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "BME68X",
"build": { "libArchive": false },
"dependencies": {
"boschsensortec/BSEC Software Library":"^1.8.1492"
}
Expand Down
3 changes: 2 additions & 1 deletion usermods/Battery/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "Battery"
"name": "Battery",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/Cronixie/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "Cronixie"
"name": "Cronixie",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/EXAMPLE/library.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "EXAMPLE",
"build": { "libArchive": false },
"dependencies": {}
}
1 change: 1 addition & 0 deletions usermods/EleksTube_IPS/library.json.disabled
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name:": "EleksTube_IPS",
"build": { "libArchive": false },
"dependencies": {
"TFT_eSPI" : "2.5.33"
}
Expand Down
1 change: 1 addition & 0 deletions usermods/INA226_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "INA226_v2",
"build": { "libArchive": false },
"dependencies": {
"wollewald/INA226_WE":"~1.2.9"
}
Expand Down
3 changes: 2 additions & 1 deletion usermods/Internal_Temperature_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "Internal_Temperature_v2"
"name": "Internal_Temperature_v2",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/LD2410_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "LD2410_v2",
"build": { "libArchive": false },
"dependencies": {
"ncmreynolds/ld2410":"^0.1.3"
}
Expand Down
3 changes: 2 additions & 1 deletion usermods/LDR_Dusk_Dawn_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "LDR_Dusk_Dawn_v2"
"name": "LDR_Dusk_Dawn_v2",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/MY9291/library.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "MY9291",
"build": { "libArchive": false },
"platforms": ["espressif8266"]
}
3 changes: 2 additions & 1 deletion usermods/PIR_sensor_switch/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "PIR_sensor_switch"
"name": "PIR_sensor_switch",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/PWM_fan/library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "PWM_fan",
"build": {
"libArchive": false,
"extraScript": "setup_deps.py"
}
}
3 changes: 2 additions & 1 deletion usermods/RTC/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "RTC"
"name": "RTC",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/SN_Photoresistor/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "SN_Photoresistor"
"name": "SN_Photoresistor",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/ST7789_display/library.json.disabled
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name:": "ST7789_display"
"name:": "ST7789_display",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/Si7021_MQTT_HA/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Si7021_MQTT_HA",
"build": { "libArchive": false },
"dependencies": {
"finitespace/BME280":"3.0.0",
"adafruit/Adafruit Si7021 Library" : "1.5.3"
Expand Down
3 changes: 2 additions & 1 deletion usermods/TetrisAI_v2/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "TetrisAI_v2"
"name": "TetrisAI_v2",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/boblight/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "boblight"
"name": "boblight",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/buzzer/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "buzzer"
"name": "buzzer",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/deep_sleep/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "deep_sleep"
"name": "deep_sleep",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/multi_relay/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "multi_relay"
"name": "multi_relay",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/pwm_outputs/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "pwm_outputs"
"name": "pwm_outputs",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/sd_card/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "sd_card"
"name": "sd_card",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/seven_segment_display/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "seven_segment_display"
"name": "seven_segment_display",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/seven_segment_display_reloaded/library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "seven_segment_display_reloaded",
"build": {
"libArchive": false,
"extraScript": "setup_deps.py"
}
}
}
1 change: 1 addition & 0 deletions usermods/sht/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "sht",
"build": { "libArchive": false },
"dependencies": {
"robtillaart/SHT85": "~0.3.3"
}
Expand Down
3 changes: 2 additions & 1 deletion usermods/smartnest/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "smartnest"
"name": "smartnest",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/stairway_wipe_basic/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "stairway_wipe_basic"
"name": "stairway_wipe_basic",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/usermod_rotary_brightness_color/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "usermod_rotary_brightness_color"
"name": "usermod_rotary_brightness_color",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/usermod_v2_HttpPullLightControl/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "usermod_v2_HttpPullLightControl"
"name": "usermod_v2_HttpPullLightControl",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/usermod_v2_RF433/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "usermod_v2_RF433",
"build": { "libArchive": false },
"dependencies": {
"sui77/rc-switch":"2.6.4"
}
Expand Down
1 change: 1 addition & 0 deletions usermods/usermod_v2_animartrix/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "animartrix",
"build": { "libArchive": false },
"dependencies": {
"Animartrix": "https://github.com/netmindz/animartrix.git#b172586"
}
Expand Down
3 changes: 2 additions & 1 deletion usermods/usermod_v2_auto_save/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "auto_save"
"name": "auto_save",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/usermod_v2_brightness_follow_sun/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "brightness_follow_sun"
"name": "brightness_follow_sun",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/usermod_v2_four_line_display_ALT/library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "four_line_display_ALT",
"build": { "libArchive": false },
"dependencies": {
"U8g2": "~2.34.4",
"Wire": ""
Expand Down
3 changes: 2 additions & 1 deletion usermods/usermod_v2_klipper_percentage/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "usermod_v2_klipper_percentage"
"name": "usermod_v2_klipper_percentage",
"build": { "libArchive": false }
}
3 changes: 2 additions & 1 deletion usermods/usermod_v2_ping_pong_clock/library.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"name": "usermod_v2_ping_pong_clock"
"name": "usermod_v2_ping_pong_clock",
"build": { "libArchive": false }
}
1 change: 1 addition & 0 deletions usermods/usermod_v2_rotary_encoder_ui_ALT/library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "rotary_encoder_ui_ALT",
"build": {
"libArchive": false,
"extraScript": "setup_deps.py"
}
}
Loading