@@ -23,38 +23,46 @@ def __init__(self, env):
23
23
24
24
self .arduino_framework_dir = self .platform .get_package_dir ("framework-arduinoespressif32" )
25
25
self .arduino_libs_mcu = join (self .platform .get_package_dir ("framework-arduinoespressif32-libs" ), self .mcu )
26
-
26
+
27
27
def handle_component_settings (self , add_components : bool = False , remove_components : bool = False ) -> None :
28
28
"""Handle adding and removing IDF components based on project configuration."""
29
- if not (add_components or remove_components ):
30
- return
31
-
29
+
32
30
# Create backup before first component removal
33
- if remove_components and not self .removed_components :
31
+ if remove_components and not self .removed_components or add_components and not self . add_components :
34
32
self ._backup_pioarduino_build_py ()
33
+
34
+ # Check if env and GetProjectOption are available
35
+ if hasattr (self , 'env' ) or hasattr (self .env , 'GetProjectOption' ):
36
+ component_yml_path = self ._get_or_create_component_yml ()
37
+ component_data = self ._load_component_yml (component_yml_path )
38
+
39
+ if remove_components :
40
+ try :
41
+ remove_option = self .env .GetProjectOption ("custom_component_remove" , None )
42
+ if remove_option :
43
+ components_to_remove = remove_option .splitlines ()
44
+ self ._remove_components (component_data , components_to_remove )
45
+ except Exception as e :
46
+ # Optional: Logging for debugging
47
+ # print(f"Error removing components: {e}")
48
+ pass
49
+
50
+ if add_components :
51
+ try :
52
+ add_option = self .env .GetProjectOption ("custom_component_add" , None )
53
+ if add_option :
54
+ components_to_add = add_option .splitlines ()
55
+ self ._add_components (component_data , components_to_add )
56
+ except Exception as e :
57
+ # Optional: Logging for debugging
58
+ # print(f"Error adding components: {e}")
59
+ pass
60
+
61
+ self ._save_component_yml (component_yml_path , component_data )
35
62
36
- component_yml_path = self ._get_or_create_component_yml ()
37
- component_data = self ._load_component_yml (component_yml_path )
38
-
39
- if remove_components :
40
- try :
41
- components_to_remove = self .env .GetProjectOption ("custom_component_remove" ).splitlines ()
42
- self ._remove_components (component_data , components_to_remove )
43
- except :
44
- pass
45
-
46
- if add_components :
47
- try :
48
- components_to_add = self .env .GetProjectOption ("custom_component_add" ).splitlines ()
49
- self ._add_components (component_data , components_to_add )
50
- except :
51
- pass
52
-
53
- self ._save_component_yml (component_yml_path , component_data )
54
-
55
- # Clean up removed components
56
- if self .removed_components :
57
- self ._cleanup_removed_components ()
63
+ # Clean up removed components
64
+ if self .removed_components :
65
+ self ._cleanup_removed_components ()
58
66
59
67
self .handle_lib_ignore ()
60
68
0 commit comments