@@ -297,13 +297,64 @@ def _convert_lib_name_to_include(self, lib_name: str) -> str:
297
297
298
298
return cleaned_name
299
299
300
+ def _has_bt_ble_dependencies (self ) -> bool :
301
+ """Check if lib_deps contains any BT/BLE related dependencies."""
302
+ try :
303
+ # Get lib_deps from current environment
304
+ lib_deps = self .env .GetProjectOption ("lib_deps" , [])
305
+
306
+ if isinstance (lib_deps , str ):
307
+ lib_deps = [lib_deps ]
308
+ elif lib_deps is None :
309
+ lib_deps = []
310
+
311
+ # Convert to string and check for BT/BLE keywords
312
+ lib_deps_str = ' ' .join (str (dep ) for dep in lib_deps ).upper ()
313
+
314
+ bt_ble_keywords = ['BLE' , 'BT' , 'NIMBLE' , 'BLUETOOTH' ]
315
+
316
+ for keyword in bt_ble_keywords :
317
+ if keyword in lib_deps_str :
318
+ return True
319
+
320
+ return False
321
+
322
+ except Exception :
323
+ return False
324
+
325
+ def _is_bt_related_library (self , lib_name : str ) -> bool :
326
+ """Check if a library name is related to Bluetooth/BLE functionality."""
327
+ lib_name_upper = lib_name .upper ()
328
+
329
+ bt_related_names = [
330
+ 'BT' ,
331
+ 'BLE' ,
332
+ 'BLUETOOTH' ,
333
+ 'NIMBLE' ,
334
+ 'ESP32_BLE' ,
335
+ 'ESP32BLE' ,
336
+ 'BLUETOOTHSERIAL' ,
337
+ 'BLE_ARDUINO' ,
338
+ 'ESP_BLE' ,
339
+ 'ESP_BT'
340
+ ]
341
+
342
+ for bt_name in bt_related_names :
343
+ if bt_name in lib_name_upper :
344
+ return True
345
+
346
+ return False
347
+
300
348
def _remove_ignored_lib_includes (self ) -> None :
301
349
"""Remove include entries for ignored libraries from pioarduino-build.py."""
302
350
build_py_path = join (self .arduino_libs_mcu , "pioarduino-build.py" )
303
351
304
352
if not os .path .exists (build_py_path ):
305
353
return
306
354
355
+ # Check if BT/BLE dependencies exist in lib_deps
356
+ bt_ble_protected = self ._has_bt_ble_dependencies ()
357
+
307
358
try :
308
359
with open (build_py_path , 'r' ) as f :
309
360
content = f .read ()
@@ -313,6 +364,11 @@ def _remove_ignored_lib_includes(self) -> None:
313
364
314
365
# Remove CPPPATH entries for each ignored library
315
366
for lib_name in self .ignored_libs :
367
+ # Skip BT-related libraries if BT/BLE dependencies are present
368
+ if bt_ble_protected and self ._is_bt_related_library (lib_name ):
369
+ print (f"Skipping removal of BT-related library '{ lib_name } ' due to BT/BLE dependency in lib_deps" )
370
+ continue
371
+
316
372
# Multiple patterns to catch different include formats
317
373
patterns = [
318
374
rf'.*join\([^,]*,\s*"include",\s*"{ re .escape (lib_name )} "[^)]*\),?\n' ,
0 commit comments