Skip to content
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
37 changes: 37 additions & 0 deletions pio-scripts/patch_audioreactive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Import("env")
import os
import json

def patch_audioreactive_lib(source, target, env):
"""Patch the AudioReactive library.json to exclude .cpp from compilation"""
libdeps_dir = env.subst("$PROJECT_LIBDEPS_DIR/$PIOENV")
library_json_path = os.path.join(libdeps_dir, "wled-audioreactive", "library.json")

if os.path.exists(library_json_path):
try:
with open(library_json_path, 'r') as f:
content = f.read()
# Handle malformed JSON (missing opening brace)
if not content.strip().startswith('{'):
content = '{' + content
if not content.strip().endswith('}'):
content = content + '}'
library_config = json.loads(content)

# Add srcFilter to exclude all source files from library compilation
if "build" not in library_config:
library_config["build"] = {}

if "srcFilter" not in library_config["build"]:
library_config["build"]["srcFilter"] = ["-<*>"]

with open(library_json_path, 'w') as f:
json.dump(library_config, f, indent=2)

print("✓ Patched wled-audioreactive library.json to exclude .cpp from compilation")
Comment on lines +21 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n pio-scripts/patch_audioreactive.py | head -40

Repository: MoonModules/WLED-MM

Length of output: 1866


Enforce srcFilter even when it already exists

The patch only applies when srcFilter is missing. If the upstream library is updated with a different srcFilter value that still includes sources, the patch won't override it and builds will unintentionally compile those .cpp files. Update the logic to compare the current value with the desired one and enforce ["-<*>"] whenever it differs.

🛠️ Suggested fix
-            # Add srcFilter to exclude all source files from library compilation
-            if "build" not in library_config:
-                library_config["build"] = {}
-            
-            if "srcFilter" not in library_config["build"]:
-                library_config["build"]["srcFilter"] = ["-<*>"]
-                
-                with open(library_json_path, 'w') as f:
-                    json.dump(library_config, f, indent=2)
-                
-                print("✓ Patched wled-audioreactive library.json to exclude .cpp from compilation")
+            # Add srcFilter to exclude all source files from library compilation
+            build_cfg = library_config.get("build")
+            if not isinstance(build_cfg, dict):
+                build_cfg = {}
+                library_config["build"] = build_cfg
+
+            desired_filter = ["-<*>"]
+            if build_cfg.get("srcFilter") != desired_filter:
+                build_cfg["srcFilter"] = desired_filter
+
+                with open(library_json_path, 'w') as f:
+                    json.dump(library_config, f, indent=2)
+
+                print("✓ Patched wled-audioreactive library.json to exclude .cpp from compilation")
🤖 Prompt for AI Agents
In `@pio-scripts/patch_audioreactive.py` around lines 21 - 31, The code currently
only sets library_config["build"]["srcFilter"] when the key is missing; instead,
check the existing value and enforce ["-<*>"] whenever it differs: ensure
library_config has a "build" dict (create if missing), read current =
library_config["build"].get("srcFilter"), and if current != ["-<*>"] then set
library_config["build"]["srcFilter"] = ["-<*>"], write back to library_json_path
with json.dump, and print the success message; reference the symbols
library_config, "build", "srcFilter", and library_json_path to locate the
change.

except Exception as e:
print(f"Warning: Could not patch wled-audioreactive library.json: {e}")

# Run immediately when script is loaded
patch_audioreactive_lib(None, None, env)

22 changes: 20 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ extra_scripts =
pre:pio-scripts/build_ui.py
pre:pio-scripts/conditional_usb_mode.py
pre:pio-scripts/set_repo.py
pre:pio-scripts/patch_audioreactive.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Search for the patch script and verify its existence
find . -name "patch_audioreactive.py" -o -name "*patch*" -type f | head -20

Repository: MoonModules/WLED-MM

Length of output: 99


🏁 Script executed:

# Check the pio-scripts directory structure
ls -la pio-scripts/ 2>/dev/null || echo "pio-scripts directory check"
git ls-files | grep -E "pio-scripts|patch" | head -20

Repository: MoonModules/WLED-MM

Length of output: 1426


🏁 Script executed:

# Examine the platformio.ini file around line 231 to see the context
sed -n '225,235p' platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 524


🏁 Script executed:

cat pio-scripts/patch_audioreactive.py

Repository: MoonModules/WLED-MM

Length of output: 1607


Script exists and has error handling, but failures are non-critical.

The patch_audioreactive.py script is properly registered and implemented with exception handling. However, the error handling is permissive—if the patch fails, the script only prints a warning and allows the build to continue. This means if the library.json patch is not applied due to an error (file not found, JSON parse failure, etc.), the build will proceed unpatched, potentially causing compilation errors downstream that are harder to trace back to the patch failure.

Consider adding explicit verification that the patch was successfully applied, or make patch failures fatal to the build if the patched library is required for compilation.

🤖 Prompt for AI Agents
In `@platformio.ini` at line 231, The pre-build script
pre:pio-scripts/patch_audioreactive.py currently swallows failures and merely
prints a warning; change it to verify the patch succeeded and fail the build on
error by either (a) validating that library.json contains the expected
modifications after applying the patch (e.g., checking for the expected
key/value or version) and exiting non-zero when validation fails, or (b)
rethrowing the caught exception / calling sys.exit(1) from the main entry point
instead of only logging a warning so the PlatformIO build is aborted; update the
script’s exception handlers to perform this verification and ensure any
file-not-found, JSON parse, or write errors become fatal.

post:pio-scripts/output_bins.py
post:pio-scripts/strip-floats.py
pre:pio-scripts/user_config_copy.py
Expand Down Expand Up @@ -1185,8 +1186,17 @@ build_disable_sync_interfaces =
-D WLED_DISABLE_ADALIGHT ;; WLEDMM this board does not have a serial-to-USB chip. Better to disable serial protocols, to avoid crashes (see upstream #3128)
-D WLED_DISABLE_ESPNOW ;; ESP-NOW requires wifi, may crash with ethernet only

AR_build_flags = -D USERMOD_AUDIOREACTIVE -D UM_AUDIOREACTIVE_USE_NEW_FFT ;; WLEDMM audioreactive usermod, licensed under EUPL-1.2
AR_lib_deps = https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
AR_build_flags =
-D USERMOD_AUDIOREACTIVE
-D UM_AUDIOREACTIVE_USE_NEW_FFT
-I wled00 ;; Allow external AudioReactive library to access wled.h
-I $PROJECT_LIBDEPS_DIR/$PIOENV/wled-audioreactive ;; Allow main project to find audio_reactive.h
-D WLED_USE_PINMANAGER_V14
;; WLEDMM audioreactive usermod, licensed under EUPL-1.2
;; NOTE: External repo needs library.json updated with "srcFilter": ["-<*>"] to prevent .cpp compilation
AR_lib_deps =
https://github.com/netmindz/WLED-AudioReactive-Usermod.git#compat-MM ;; MM version 14
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be swapped to MoonModules once we are good to merge the compat-MM PR

https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3

animartrix_build_flags = -D USERMOD_ANIMARTRIX ;; WLEDMM usermod: CC BY-NC 3.0 licensed effects by Stefan Petrick
;;animartrix_lib_deps = https://github.com/netmindz/animartrix.git#af02653aaabdce08929389ca16d0d86071573dd4 ;; custom PSRAM allocator
Expand Down Expand Up @@ -1600,6 +1610,8 @@ build_flags = ${esp32_4MB_M_base.build_flags}
extends = env:esp8266_2m
upload_speed = 460800 ;115200
board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz)
lib_deps = ${esp8266.lib_deps}
${common_mm.AR_lib_deps}
build_flags = ${common.build_flags_esp8266}
Comment on lines +1613 to 1615
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's locate and examine the esp8266_2MB_S environment section
rg -n "esp8266_2MB_S" platformio.ini -A 10 -B 2

Repository: MoonModules/WLED-MM

Length of output: 1430


🏁 Script executed:

# Find where common_mm.AR_lib_deps and common_mm.AR_build_flags are defined
rg -n "AR_lib_deps|AR_build_flags" platformio.ini -B 2 -A 2

Repository: MoonModules/WLED-MM

Length of output: 5568


🏁 Script executed:

# Check the structure of the file to understand the context better
wc -l platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 82


🏁 Script executed:

# Check for comments around the 2MB, 4MB, and 16MB environments
sed -n '1608,1625p' platformio.ini
sed -n '1638,1650p' platformio.ini
sed -n '1736,1745p' platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 1839


🏁 Script executed:

# Verify that common_mm.AR_build_flags is properly defined
sed -n '1189,1200p' platformio.ini

Repository: MoonModules/WLED-MM

Length of output: 872


Add AR_build_flags to esp8266_2MB_S build configuration.

The environment pulls ${common_mm.AR_lib_deps} but omits ${common_mm.AR_build_flags}, which includes the -D USERMOD_AUDIOREACTIVE define and required include paths. Without these flags, the AudioReactive library will fail to compile. This is inconsistent with esp8266pro_16MB_S and all ESP32 AR-enabled environments, which include both.

✅ Suggested fix:
 build_flags = ${common.build_flags_esp8266}
+  ${common_mm.AR_build_flags}
   -D WLED_RELEASE_NAME=esp8266_2MB_S
🤖 Prompt for AI Agents
In `@platformio.ini` around lines 1612 - 1614, The esp8266 AR-enabled env is
pulling ${common_mm.AR_lib_deps} but missing the matching build flags; update
the esp8266_2MB_S environment so its build_flags include
${common_mm.AR_build_flags} (in the same place where build_flags =
${common.build_flags_esp8266} is declared) so the -D USERMOD_AUDIOREACTIVE
define and include paths from common_mm.AR_build_flags are applied; ensure the
change mirrors how esp8266pro_16MB_S and ESP32 AR environments include both
${common_mm.AR_lib_deps} and ${common_mm.AR_build_flags}.

-D WLED_RELEASE_NAME=esp8266_2MB_S
-D WLED_USE_UNREAL_MATH ;; may cause some wrong sunset/sunrise times, but saves 7064 bytes FLASH and 975 bytes RAM
Expand All @@ -1625,6 +1637,8 @@ build_flags = ${common.build_flags_esp8266}
extends = env:d1_mini
upload_speed = 460800 ;115200
board_build.f_cpu = 160000000L ;; we want 160Mhz (default = 80Mhz)
lib_deps = ${esp8266.lib_deps}
${common_mm.AR_lib_deps}
build_flags = ${common.build_flags_esp8266}
-D WLED_RELEASE_NAME=esp8266_4MB_S
-D WLED_DISABLE_ALEXA
Expand Down Expand Up @@ -1721,7 +1735,10 @@ board_build.flash_mode = qio ;; quad IO - fastest speed, in case your chip
board_build.ldscript = ${common.ldscript_16m14m} ;; 16MB flash, use 14MB for LittleFS

upload_speed = 460800 ;115200
lib_deps = ${esp8266.lib_deps}
${common_mm.AR_lib_deps}
build_flags = ${common.build_flags_esp8266}
${common_mm.AR_build_flags}
-D WLED_RELEASE_NAME=esp8266pro_16MB_S
-D WLED_WATCHDOG_TIMEOUT=0
-D WLED_DISABLE_ALEXA
Expand Down Expand Up @@ -1779,6 +1796,7 @@ build_flags = ${common.build_flags_esp8266}
; -D WLED_DEBUG
monitor_filters = esp8266_exception_decoder
lib_deps = ${esp8266.lib_deps}
${common_mm.AR_lib_deps}
OneWire@~2.3.5 ; used for USERMOD_FOUR_LINE_DISPLAY and USERMOD_DALLASTEMPERATURE
olikraus/U8g2 @ ^2.28.8 ; used for USERMOD_FOUR_LINE_DISPLAY
ElectronicCats/MPU6050 @ 0.6.0 ; used for USERMOD_MPU6050_IMU
Expand Down
Loading
Loading