13
13
import re
14
14
import yaml
15
15
from yaml import SafeLoader
16
- from os . path import join
16
+ from pathlib import Path
17
17
from typing import Set , Optional , Dict , Any , List , Tuple
18
18
19
19
@@ -49,8 +49,12 @@ def __init__(self, env):
49
49
self .project_src_dir = env .subst ("$PROJECT_SRC_DIR" )
50
50
# Get Arduino framework installation directory
51
51
self .arduino_framework_dir = self .platform .get_package_dir ("framework-arduinoespressif32" )
52
+ # Get Arduino libraries installation directory
53
+ ald = self .platform .get_package_dir ("framework-arduinoespressif32-libs" )
52
54
# Get MCU-specific Arduino libraries directory
53
- self .arduino_libs_mcu = join (self .platform .get_package_dir ("framework-arduinoespressif32-libs" ), self .mcu )
55
+ self .arduino_libs_mcu = (
56
+ str (Path (ald ) / self .mcu ) if ald else ""
57
+ )
54
58
55
59
56
60
class ComponentLogger :
@@ -228,13 +232,14 @@ def _get_or_create_component_yml(self) -> str:
228
232
Absolute path to the component YAML file
229
233
"""
230
234
# Try Arduino framework first
231
- framework_yml = join (self .config .arduino_framework_dir , "idf_component.yml" )
232
- if os .path .exists (framework_yml ):
235
+ afd = self .config .arduino_framework_dir
236
+ framework_yml = str (Path (afd ) / "idf_component.yml" ) if afd else ""
237
+ if framework_yml and os .path .exists (framework_yml ):
233
238
self ._create_backup (framework_yml )
234
239
return framework_yml
235
240
236
241
# Try project source directory
237
- project_yml = join ( self .config .project_src_dir , "idf_component.yml" )
242
+ project_yml = str ( Path ( self .config .project_src_dir ) / "idf_component.yml" )
238
243
if os .path .exists (project_yml ):
239
244
self ._create_backup (project_yml )
240
245
return project_yml
@@ -416,9 +421,12 @@ def _backup_pioarduino_build_py(self) -> None:
416
421
"""
417
422
if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
418
423
return
419
-
420
- build_py_path = join (self .config .arduino_libs_mcu , "pioarduino-build.py" )
421
- backup_path = join (self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
424
+
425
+ if not self .config .arduino_libs_mcu :
426
+ return
427
+
428
+ build_py_path = str (Path (self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
429
+ backup_path = str (Path (self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
422
430
423
431
if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
424
432
shutil .copy2 (build_py_path , backup_path )
@@ -446,7 +454,7 @@ def _remove_include_directory(self, component: str) -> None:
446
454
Args:
447
455
component: Component name in filesystem format
448
456
"""
449
- include_path = join ( self .config .arduino_libs_mcu , "include" , component )
457
+ include_path = str ( Path ( self .config .arduino_libs_mcu ) / "include" / component )
450
458
451
459
if os .path .exists (include_path ):
452
460
shutil .rmtree (include_path )
@@ -459,7 +467,7 @@ def _remove_cpppath_entries(self) -> None:
459
467
for all components that were removed from the project. Uses
460
468
multiple regex patterns to catch different include path formats.
461
469
"""
462
- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
470
+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
463
471
464
472
if not os .path .exists (build_py_path ):
465
473
return
@@ -667,14 +675,17 @@ def _get_arduino_core_libraries(self) -> Dict[str, str]:
667
675
libraries_mapping = {}
668
676
669
677
# Path to Arduino Core Libraries
670
- arduino_libs_dir = join (self .config .arduino_framework_dir , "libraries" )
678
+ afd = self .config .arduino_framework_dir
679
+ if not afd :
680
+ return libraries_mapping
681
+ arduino_libs_dir = str (Path (afd ).resolve () / "libraries" )
671
682
672
683
if not os .path .exists (arduino_libs_dir ):
673
684
return libraries_mapping
674
685
675
686
try :
676
687
for entry in os .listdir (arduino_libs_dir ):
677
- lib_path = join ( arduino_libs_dir , entry )
688
+ lib_path = str ( Path ( arduino_libs_dir ) / entry )
678
689
if os .path .isdir (lib_path ):
679
690
lib_name = self ._get_library_name_from_properties (lib_path )
680
691
if lib_name :
@@ -699,7 +710,7 @@ def _get_library_name_from_properties(self, lib_dir: str) -> Optional[str]:
699
710
Returns:
700
711
Official library name or None if not found or readable
701
712
"""
702
- prop_path = join ( lib_dir , "library.properties" )
713
+ prop_path = str ( Path ( lib_dir ) / "library.properties" )
703
714
if not os .path .isfile (prop_path ):
704
715
return None
705
716
@@ -891,7 +902,7 @@ def _remove_ignored_lib_includes(self) -> None:
891
902
components when dependencies are detected. Uses multiple regex
892
903
patterns to catch different include path formats.
893
904
"""
894
- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
905
+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
895
906
896
907
if not os .path .exists (build_py_path ):
897
908
self .logger .log_change ("Build file not found" )
@@ -930,7 +941,10 @@ def _remove_ignored_lib_includes(self) -> None:
930
941
rf'.*"[^"]*{ re .escape (lib_name )} [^"]*include[^"]*"[^,\n]*,?\n' ,
931
942
rf'.*join\([^)]*"include"[^)]*"{ re .escape (lib_name )} "[^)]*\),?\n' ,
932
943
rf'.*"{ re .escape (lib_name )} /include"[^,\n]*,?\n' ,
933
- rf'\s*"[^"]*/{ re .escape (lib_name )} /[^"]*",?\n'
944
+ rf'\s*"[^"]*[\\/]{ re .escape (lib_name )} [\\/][^"]*",?\n' ,
945
+ # pathlib-style: Path(...)/"include"/"<name>"
946
+ rf'.*Path\([^)]*\)\s*/\s*"include"\s*/\s*"{ re .escape (lib_name )} "[^,\n]*,?\n' ,
947
+ rf'.*Path\([^)]*{ re .escape (lib_name )} [^)]*\)\s*/\s*"include"[^,\n]*,?\n'
934
948
]
935
949
936
950
removed_count = 0
@@ -992,8 +1006,10 @@ def _backup_pioarduino_build_py(self) -> None:
992
1006
if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
993
1007
return
994
1008
995
- build_py_path = join (self .config .arduino_libs_mcu , "pioarduino-build.py" )
996
- backup_path = join (self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
1009
+ if not self .config .arduino_libs_mcu :
1010
+ return
1011
+ build_py_path = str (Path (self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1012
+ backup_path = str (Path (self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
997
1013
998
1014
if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
999
1015
shutil .copy2 (build_py_path , backup_path )
@@ -1007,7 +1023,7 @@ class BackupManager:
1007
1023
framework build scripts, ensuring that original files can be restored
1008
1024
when needed or when builds are cleaned.
1009
1025
"""
1010
-
1026
+
1011
1027
def __init__ (self , config : ComponentManagerConfig ):
1012
1028
"""
1013
1029
Initialize the backup manager with configuration access.
@@ -1019,7 +1035,7 @@ def __init__(self, config: ComponentManagerConfig):
1019
1035
config: Configuration manager instance providing access to paths
1020
1036
"""
1021
1037
self .config = config
1022
-
1038
+
1023
1039
def backup_pioarduino_build_py (self ) -> None :
1024
1040
"""
1025
1041
Create backup of the original pioarduino-build.py file.
@@ -1030,13 +1046,13 @@ def backup_pioarduino_build_py(self) -> None:
1030
1046
"""
1031
1047
if "arduino" not in self .config .env .subst ("$PIOFRAMEWORK" ):
1032
1048
return
1033
-
1034
- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
1035
- backup_path = join ( self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
1036
-
1049
+
1050
+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1051
+ backup_path = str ( Path ( self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
1052
+
1037
1053
if os .path .exists (build_py_path ) and not os .path .exists (backup_path ):
1038
1054
shutil .copy2 (build_py_path , backup_path )
1039
-
1055
+
1040
1056
def restore_pioarduino_build_py (self , target = None , source = None , env = None ) -> None :
1041
1057
"""
1042
1058
Restore the original pioarduino-build.py from backup.
@@ -1050,9 +1066,9 @@ def restore_pioarduino_build_py(self, target=None, source=None, env=None) -> Non
1050
1066
source: Build source (unused, for PlatformIO compatibility)
1051
1067
env: Environment (unused, for PlatformIO compatibility)
1052
1068
"""
1053
- build_py_path = join ( self .config .arduino_libs_mcu , "pioarduino-build.py" )
1054
- backup_path = join ( self .config .arduino_libs_mcu , f"pioarduino-build.py.{ self .config .mcu } " )
1055
-
1069
+ build_py_path = str ( Path ( self .config .arduino_libs_mcu ) / "pioarduino-build.py" )
1070
+ backup_path = str ( Path ( self .config .arduino_libs_mcu ) / f"pioarduino-build.py.{ self .config .mcu } " )
1071
+
1056
1072
if os .path .exists (backup_path ):
1057
1073
shutil .copy2 (backup_path , build_py_path )
1058
1074
os .remove (backup_path )
0 commit comments