fix: patch nimconfig.h with #ifndef guards for ROLE defines to eliminate redefinition warnings
This commit is contained in:
@@ -100,5 +100,66 @@ def patch_sdkconfig_bt():
|
||||
print("BLE/NimBLE already configured in sdkconfig")
|
||||
|
||||
|
||||
def patch_nimconfig():
|
||||
# Find nimconfig.h in the NimBLE-Arduino library
|
||||
search_dirs = [
|
||||
os.path.join(os.getcwd(), ".pio", "libdeps"),
|
||||
os.path.expanduser("~/.platformio/lib"),
|
||||
]
|
||||
for env_dir in ["esp32s3", ""]:
|
||||
candidate = os.path.join(
|
||||
os.getcwd(), ".pio", "libdeps",
|
||||
env_dir, "NimBLE-Arduino", "src", "nimconfig.h"
|
||||
) if env_dir else ""
|
||||
if candidate and os.path.exists(candidate):
|
||||
nimconfig_path = candidate
|
||||
break
|
||||
else:
|
||||
# Walk search dirs as fallback
|
||||
nimconfig_path = None
|
||||
for base in search_dirs:
|
||||
if not os.path.exists(base):
|
||||
continue
|
||||
for root, _dirs, files in os.walk(base):
|
||||
if "nimconfig.h" in files:
|
||||
nimconfig_path = os.path.join(root, "nimconfig.h")
|
||||
break
|
||||
if nimconfig_path:
|
||||
break
|
||||
|
||||
if not nimconfig_path:
|
||||
print("WARNING: nimconfig.h not found, skipping ROLE define patch")
|
||||
return
|
||||
|
||||
print(f"Patching {nimconfig_path} with #ifndef guards for ROLE defines")
|
||||
|
||||
with open(nimconfig_path, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
for role in ["CENTRAL", "OBSERVER", "PERIPHERAL", "BROADCASTER"]:
|
||||
pattern = re.compile(
|
||||
'#ifndef CONFIG_BT_NIMBLE_ROLE_' + role + '_DISABLED\n'
|
||||
'#define CONFIG_BT_NIMBLE_ROLE_' + role + '\n'
|
||||
'#endif'
|
||||
)
|
||||
replacement = (
|
||||
'#ifndef CONFIG_BT_NIMBLE_ROLE_' + role + '_DISABLED\n'
|
||||
'#ifndef CONFIG_BT_NIMBLE_ROLE_' + role + '\n'
|
||||
'#define CONFIG_BT_NIMBLE_ROLE_' + role + '\n'
|
||||
'#endif\n'
|
||||
'#endif'
|
||||
)
|
||||
if pattern.search(content):
|
||||
content = pattern.sub(replacement, content)
|
||||
print(f" Guarded CONFIG_BT_NIMBLE_ROLE_{role}")
|
||||
else:
|
||||
print(f" NOTE: CONFIG_BT_NIMBLE_ROLE_{role} pattern not found (may already be guarded)")
|
||||
|
||||
with open(nimconfig_path, 'w') as f:
|
||||
f.write(content)
|
||||
print("nimconfig.h patched successfully")
|
||||
|
||||
|
||||
patch_usb_ids()
|
||||
patch_sdkconfig_bt()
|
||||
patch_nimconfig()
|
||||
Reference in New Issue
Block a user