Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Copy Markdown

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)

13 changes: 11 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
Copy Markdown

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,16 @@ 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
;; 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/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
Comment on lines +1190 to +1200
Copy link
Copy Markdown

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

🌐 Web query:

PlatformIO library dependency specification syntax VCS git branch version

💡 Result:

In platformio.ini, lib_deps entries use Package Specifications. There are two common cases:

1) PlatformIO Registry libraries (SemVer / version requirements)

Syntax:

  • <owner>/<name>@<version requirement>

Examples:

2) VCS (Git) dependencies (pin branch/tag/commit with #)

Syntax:

  • [<name>=]<git-url>[#<commit-ish|branch|tag>]

Examples:

Key distinction: @ vs #

  • Use @... for Registry version constraints.
  • Use #... for Git branch/tag/commit when the dependency is a VCS URL. (docs.platformio.org)

Citations:


🌐 Web query:

PlatformIO lib_deps format mixed version specifier git reference

💡 Result:

In lib_deps, you can’t combine the registry SemVer specifier syntax (owner/name @ ^1.2.3, ~, !=, etc.) with a VCS (git) reference (...git#branch|tag|commit) in the same dependency entry—they are two different kinds of package specifications:

  • PlatformIO Registry library + SemVer constraints uses @:
  • Git (or other VCS) dependency uses a URL (or user/repo) plus # for branch/tag/commit:

If you want “versioning” with git

You must do it by pinning to a tag (e.g., #v1.2.3) or a commit SHA—there’s no SemVer range resolution for arbitrary git URLs in lib_deps like #^1.2.3. (docs.platformio.org)

Citations:


Fix invalid PlatformIO lib spec for arduinoFFT.
https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2 mixes VCS syntax (#branch) with registry versioning (@version). PlatformIO does not support combining both formats in a single dependency entry. Remove the @ 1.9.2 portion to use the valid VCS-only specification.

🛠️ Suggested fix
 AR_lib_deps =
   https://github.com/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
-  https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2      ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
+  https://github.com/softhack007/arduinoFFT.git#develop              ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
;; 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/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
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
;; 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/MoonModules/WLED-AudioReactive-Usermod.git#39fee0aebc4f7581f23723acc710ea9cacc199d1 ;; MM version 14
https://github.com/softhack007/arduinoFFT.git#develop ;; used for USERMOD_AUDIOREACTIVE - optimized version, 10% faster on -S2/-C3
🤖 Prompt for AI Agents
In `@platformio.ini` around lines 1189 - 1198, The AR_lib_deps entry for
arduinoFFT is an invalid mixed-format spec; update the AR_lib_deps line
referencing arduinoFFT (currently
"https://github.com/softhack007/arduinoFFT.git#develop @ 1.9.2") to a valid
VCS-only spec by removing the "@ 1.9.2" suffix (or alternatively pin a specific
git tag/commit after the "#" instead of using "@version"); ensure AR_lib_deps
contains a clean VCS URL for arduinoFFT so PlatformIO can resolve it.


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
Loading
Loading