@@ -770,6 +770,8 @@ def _map_library_to_include_path(self, lib_name: str, dir_name: str) -> str:
770
770
# Arduino Core specific mappings (safe mappings that don't conflict with critical components)
771
771
'esp32blearduino' : 'bt' ,
772
772
'esp32_ble_arduino' : 'bt' ,
773
+ 'simpleble' : 'bt' ,
774
+ 'esp-nimble-cpp' : 'bt' ,
773
775
'esp32' : 'esp32' ,
774
776
'wire' : 'driver' ,
775
777
'spi' : 'driver' ,
@@ -841,17 +843,7 @@ def _map_library_to_include_path(self, lib_name: str, dir_name: str) -> str:
841
843
842
844
# Fallback: Use directory name as include path
843
845
return dir_name_lower
844
-
845
- def _get_original_lib_ignore_entries (self ) -> List [str ]:
846
- """Get original lib_ignore entries without conversion."""
847
- try :
848
- lib_ignore = self .config .env .GetProjectOption ("lib_ignore" , [])
849
- if isinstance (lib_ignore , str ):
850
- lib_ignore = [lib_ignore ]
851
- return [str (entry ).strip ().lower () for entry in lib_ignore if str (entry ).strip ()]
852
- except Exception :
853
- return []
854
-
846
+
855
847
def _convert_lib_name_to_include (self , lib_name : str ) -> str :
856
848
"""
857
849
Convert library name to potential include directory name.
@@ -900,8 +892,13 @@ def _convert_lib_name_to_include(self, lib_name: str) -> str:
900
892
'ble' : 'bt' ,
901
893
'bluetooth' : 'bt' ,
902
894
'bluetoothserial' : 'bt' ,
903
- 'dsp' : 'esp_dsp' ,
904
- 'esp-dsp' : 'esp_dsp'
895
+ 'simpleble' : 'bt' ,
896
+ 'esp-nimble-cpp' : 'bt' ,
897
+ 'dsp' : 'espressif__esp-dsp' ,
898
+ 'esp_dsp' : 'espressif__esp-dsp' ,
899
+ 'dsps' : 'espressif__esp-dsp' ,
900
+ 'fft2r' : 'espressif__esp-dsp' ,
901
+ 'dsps_fft2r' : 'espressif__esp-dsp'
905
902
}
906
903
907
904
if cleaned_name in direct_mapping :
@@ -912,46 +909,42 @@ def _convert_lib_name_to_include(self, lib_name: str) -> str:
912
909
def _remove_ignored_lib_includes (self ) -> None :
913
910
"""
914
911
Remove include entries for ignored libraries from pioarduino-build.py.
915
-
912
+
916
913
Processes the Arduino build script to remove CPPPATH entries for
917
914
all ignored libraries. Implements protection for BT/BLE and DSP
918
915
components when dependencies are detected. Uses multiple regex
919
916
patterns to catch different include path formats.
920
917
"""
921
918
build_py_path = str (Path (self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
922
-
919
+
923
920
if not os .path .exists (build_py_path ):
924
921
self .logger .log_change ("Build file not found" )
925
922
return
926
-
923
+
927
924
# Check if BT/BLE dependencies exist in lib_deps
928
925
bt_ble_protected = self ._has_bt_ble_dependencies ()
929
926
if bt_ble_protected :
930
927
self .logger .log_change ("BT/BLE protection enabled" )
931
-
932
- # Get original lib_ignore entries for DSP protection check
933
- original_lib_ignore = self ._get_original_lib_ignore_entries ()
934
-
928
+
935
929
try :
936
930
with open (build_py_path , 'r' , encoding = 'utf-8' ) as f :
937
931
content = f .read ()
938
-
932
+
939
933
original_content = content
940
934
total_removed = 0
941
-
935
+
942
936
# Remove CPPPATH entries for each ignored library
943
937
for lib_name in self .ignored_libs :
944
938
# Skip BT-related libraries if BT/BLE dependencies are present
945
939
if bt_ble_protected and self ._is_bt_related_library (lib_name ):
946
940
self .logger .log_change (f"Protected BT library: { lib_name } " )
947
941
continue
948
-
949
- # # Protection for DSP components - only remove if 'dsp' is explicitly in lib_ignore
950
- # if lib_name.lower() in ['dsp', 'esp_dsp', 'dsps', 'fft2r', 'dsps_fft2r', 'espressif__esp-dsp']:
951
- # if 'dsp' not in original_lib_ignore:
952
- # self.logger.log_change(f"Protected DSP component: {lib_name}")
953
- # continue
954
-
942
+
943
+ # # Hard protection for DSP components
944
+ # if lib_name.lower() in ['dsp', 'esp_dsp', 'dsps', 'fft2r', 'dsps_fft2r']:
945
+ # self.logger.log_change(f"Protected DSP component: {lib_name}")
946
+ # continue
947
+
955
948
# Multiple patterns to catch different include formats
956
949
patterns = [
957
950
rf'.*join\([^,]*,\s*"include",\s*"{ re .escape (lib_name )} "[^)]*\),?\n' ,
@@ -966,28 +959,28 @@ def _remove_ignored_lib_includes(self) -> None:
966
959
rf'.*Path\([^)]*\)\s*/\s*"include"\s*/\s*"{ re .escape (lib_name )} "[^,\n]*,?\n' ,
967
960
rf'.*Path\([^)]*{ re .escape (lib_name )} [^)]*\)\s*/\s*"include"[^,\n]*,?\n'
968
961
]
969
-
962
+
970
963
removed_count = 0
971
964
for pattern in patterns :
972
965
matches = re .findall (pattern , content )
973
966
if matches :
974
967
content = re .sub (pattern , '' , content )
975
968
removed_count += len (matches )
976
-
969
+
977
970
if removed_count > 0 :
978
971
self .logger .log_change (f"Ignored library: { lib_name } ({ removed_count } entries)" )
979
972
total_removed += removed_count
980
-
973
+
981
974
# Clean up empty lines and trailing commas
982
975
content = re .sub (r'\n\s*\n' , '\n ' , content )
983
976
content = re .sub (r',\s*\n\s*\]' , '\n ]' , content )
984
-
977
+
985
978
# Validate and write changes
986
979
if self ._validate_changes (original_content , content ) and content != original_content :
987
980
with open (build_py_path , 'w' , encoding = 'utf-8' ) as f :
988
981
f .write (content )
989
982
self .logger .log_change (f"Updated build file ({ total_removed } total removals)" )
990
-
983
+
991
984
except (IOError , OSError ) as e :
992
985
self .logger .log_change (f"Error processing libraries: { str (e )} " )
993
986
except Exception as e :
@@ -996,47 +989,41 @@ def _remove_ignored_lib_includes(self) -> None:
996
989
def _validate_changes (self , original_content : str , new_content : str ) -> bool :
997
990
"""
998
991
Validate that the changes are reasonable and safe.
999
-
992
+
1000
993
Performs sanity checks on the modified content to ensure that
1001
994
the changes don't remove too much content or create invalid
1002
995
modifications that could break the build process.
1003
-
996
+
1004
997
Args:
1005
998
original_content: Original file content before modifications
1006
- new_content: Modified file content after changes
1007
-
999
+ new_content: Modified file content after processing
1000
+
1008
1001
Returns:
1009
- True if changes are valid and safe to apply
1002
+ True if changes are within acceptable limits and safe to apply
1010
1003
"""
1011
- # Check if too much content was removed (more than 50% indicates potential error)
1012
- if len (new_content ) < len (original_content ) * 0.5 :
1013
- self .logger .log_change ("Warning: Too much content removed, skipping changes" )
1014
- return False
1015
-
1016
- # Check for basic Python syntax structure preservation
1017
- if 'CPPPATH' not in new_content or 'env.Append' not in new_content :
1018
- self .logger .log_change ("Warning: Critical build structure missing, skipping changes" )
1019
- return False
1020
-
1021
- return True
1004
+ original_lines = len (original_content .splitlines ())
1005
+ new_lines = len (new_content .splitlines ())
1006
+ removed_lines = original_lines - new_lines
1007
+
1008
+ # Don't allow removing more than 50% of the file or negative changes
1009
+ return not (removed_lines > original_lines * 0.5 or removed_lines < 0 )
1022
1010
1023
1011
def _backup_pioarduino_build_py (self ) -> None :
1024
1012
"""
1025
1013
Create backup of the original pioarduino-build.py file.
1026
-
1027
- Creates a backup of the Arduino framework's build script before
1028
- making modifications. Only operates when Arduino framework is active
1029
- and creates MCU-specific backup names to avoid conflicts.
1014
+
1015
+ Creates a backup copy of the Arduino build script before making
1016
+ modifications. Only operates when Arduino framework is active
1017
+ and uses MCU-specific backup naming to avoid conflicts.
1030
1018
"""
1031
1019
if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
1032
1020
return
1033
1021
1034
1022
if not self .config .arduino_libs_mcu :
1035
1023
return
1036
-
1037
1024
build_py_path = str (Path (self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1038
1025
backup_path = str (Path (self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
1039
-
1026
+
1040
1027
if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
1041
1028
shutil .copy2 (build_py_path , backup_path )
1042
1029
0 commit comments