Fix conflicting ARDUINO_USB_MODE definitions using BUILD_UNFLAGS
Co-authored-by: softhack007 <91616163+softhack007@users.noreply.github.com>
This commit is contained in:
@@ -87,43 +87,13 @@ def conditional_usb_mode(env):
|
|||||||
print("WLED Release build detected - board has USB-OTG (CDC_ON_BOOT=1)")
|
print("WLED Release build detected - board has USB-OTG (CDC_ON_BOOT=1)")
|
||||||
print(" Setting ARDUINO_USB_MODE=0 for production")
|
print(" Setting ARDUINO_USB_MODE=0 for production")
|
||||||
|
|
||||||
# Find and modify ARDUINO_USB_MODE in build flags
|
# Check if ARDUINO_USB_MODE=1 is present
|
||||||
build_flags = env.get('BUILD_FLAGS', [])
|
if has_usb_mode_enabled(env):
|
||||||
cpp_defines = env.get('CPPDEFINES', [])
|
# Remove the old definition and add the new one
|
||||||
|
# This approach properly handles flag inheritance in PlatformIO
|
||||||
# Look through CPPDEFINES and modify ARDUINO_USB_MODE if found
|
env.Append(BUILD_UNFLAGS=["-DARDUINO_USB_MODE=1"])
|
||||||
modified = False
|
env.Append(CPPDEFINES=[("ARDUINO_USB_MODE", "0")])
|
||||||
new_defines = []
|
print(f" Changed ARDUINO_USB_MODE from 1 to 0")
|
||||||
|
|
||||||
for define in cpp_defines:
|
|
||||||
if isinstance(define, (list, tuple)) and len(define) == 2:
|
|
||||||
if define[0] == 'ARDUINO_USB_MODE' and define[1] == '1':
|
|
||||||
# Change ARDUINO_USB_MODE from 1 to 0 for release builds
|
|
||||||
new_defines.append(('ARDUINO_USB_MODE', '0'))
|
|
||||||
modified = True
|
|
||||||
print(f" Changed ARDUINO_USB_MODE from 1 to 0")
|
|
||||||
else:
|
|
||||||
new_defines.append(define)
|
|
||||||
else:
|
|
||||||
new_defines.append(define)
|
|
||||||
|
|
||||||
if modified:
|
|
||||||
env.Replace(CPPDEFINES=new_defines)
|
|
||||||
|
|
||||||
# Also check raw build flags for -DARDUINO_USB_MODE=1
|
|
||||||
new_build_flags = []
|
|
||||||
for flag in build_flags:
|
|
||||||
if isinstance(flag, str) and 'ARDUINO_USB_MODE=1' in flag:
|
|
||||||
# Replace ARDUINO_USB_MODE=1 with ARDUINO_USB_MODE=0
|
|
||||||
new_flag = flag.replace('ARDUINO_USB_MODE=1', 'ARDUINO_USB_MODE=0')
|
|
||||||
new_build_flags.append(new_flag)
|
|
||||||
modified = True
|
|
||||||
print(f" Modified build flag: {flag} -> {new_flag}")
|
|
||||||
else:
|
|
||||||
new_build_flags.append(flag)
|
|
||||||
|
|
||||||
if modified:
|
|
||||||
env.Replace(BUILD_FLAGS=new_build_flags)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Development build
|
# Development build
|
||||||
|
|||||||
Reference in New Issue
Block a user