@@ -120,47 +120,27 @@ def _analyze_project_dependencies(self) -> Set[str]:
120
120
"""Analyze project files to detect actually used components/libraries."""
121
121
used_components = set ()
122
122
123
- print (f"DEBUG: Starting project analysis" )
124
-
125
123
try :
124
+ # Analyze project source files
126
125
src_dir = self .env .subst ("$PROJECT_SRC_DIR" )
127
- print (f"DEBUG: Scanning source directory: { src_dir } " )
128
-
129
126
if os .path .exists (src_dir ):
130
- file_count = 0
131
127
for root , dirs , files in os .walk (src_dir ):
132
128
for file in files :
133
129
if file .endswith (('.cpp' , '.c' , '.h' , '.hpp' , '.ino' )):
134
- file_count += 1
135
130
file_path = os .path .join (root , file )
136
- file_components = self ._extract_components_from_file (file_path )
137
- if file_components :
138
- print (f"DEBUG: File { file } detected components: { file_components } " )
139
- used_components .update (file_components )
140
-
141
- print (f"DEBUG: Scanned { file_count } source files" )
131
+ used_components .update (self ._extract_components_from_file (file_path ))
142
132
143
- # Check lib_deps
133
+ # Analyze lib_deps for explicit dependencies (if present)
144
134
lib_deps = self .env .GetProjectOption ("lib_deps" , [])
145
- if lib_deps :
146
- print (f"DEBUG: Found lib_deps: { lib_deps } " )
147
- if isinstance (lib_deps , str ):
148
- lib_deps = [lib_deps ]
149
-
150
- for dep in lib_deps :
151
- dep_components = self ._extract_components_from_lib_dep (str (dep ))
152
- if dep_components :
153
- print (f"DEBUG: lib_dep '{ dep } ' mapped to components: { dep_components } " )
154
- used_components .update (dep_components )
155
- else :
156
- print (f"DEBUG: No lib_deps found" )
135
+ if isinstance (lib_deps , str ):
136
+ lib_deps = [lib_deps ]
137
+
138
+ for dep in lib_deps :
139
+ used_components .update (self ._extract_components_from_lib_dep (str (dep )))
157
140
158
- except Exception as e :
159
- print (f"DEBUG: Exception in project analysis: { e } " )
160
- import traceback
161
- traceback .print_exc ()
141
+ except Exception :
142
+ pass
162
143
163
- print (f"DEBUG: Final detected components: { used_components } " )
164
144
return used_components
165
145
166
146
def _extract_components_from_file (self , file_path : str ) -> Set [str ]:
@@ -171,7 +151,7 @@ def _extract_components_from_file(self, file_path: str) -> Set[str]:
171
151
component_patterns = {
172
152
'bt' : ['bluetooth' , 'ble' , 'nimble' , 'bt_' , 'esp_bt' , 'esp_ble' ],
173
153
'esp_wifi' : ['wifi' , 'esp_wifi' , 'tcpip_adapter' ],
174
- 'esp_dsp' : ['dsps_' , 'esp_dsp' , 'fft2r' ],
154
+ 'esp_dsp' : ['dsps_' , 'esp_dsp' , 'fft2r' , 'dsps_fft2r' ], # Enhanced DSP detection
175
155
'esp_http_client' : ['esp_http_client' , 'http_client' ],
176
156
'esp_https_ota' : ['esp_https_ota' , 'esp_ota' ],
177
157
'mdns' : ['mdns' , 'esp_mdns' ],
@@ -433,36 +413,23 @@ def _remove_ignored_lib_includes(self) -> None:
433
413
build_py_path = join (self .arduino_libs_mcu , "pioarduino-build.py" )
434
414
435
415
if not os .path .exists (build_py_path ):
436
- print (f"DEBUG: Build file not found: { build_py_path } " )
437
416
return
438
417
439
- print (f"DEBUG: Starting lib_ignore processing" )
440
- print (f"DEBUG: ignored_libs = { list (self .ignored_libs )} " )
441
-
442
- # Force project analysis and show results
443
- self ._project_components_cache = self ._analyze_project_dependencies ()
444
- print (f"DEBUG: Detected project components: { list (self ._project_components_cache )} " )
445
-
446
418
try :
447
419
with open (build_py_path , 'r' ) as f :
448
420
content = f .read ()
449
421
450
422
original_content = content
451
423
total_removed = 0
452
424
453
- # Check each library individually
425
+ # Remove CPPPATH entries for each ignored library
454
426
for lib_name in self .ignored_libs :
455
- print (f"DEBUG: Processing lib_name = '{ lib_name } '" )
456
-
457
- # Check if component is used
458
- is_used = self ._is_component_used_in_project (lib_name )
459
- print (f"DEBUG: Is '{ lib_name } ' used in project? { is_used } " )
460
-
461
- if is_used :
462
- print (f"DEBUG: SKIPPING '{ lib_name } ' - detected as used" )
427
+ # Universal protection: Skip if component is actually used in project
428
+ if self ._is_component_used_in_project (lib_name ):
429
+ print (f"Skipping removal of library '{ lib_name } ' - detected as used in project" )
463
430
continue
464
-
465
- # Check what would be removed
431
+
432
+ # Multiple patterns to catch different include formats
466
433
patterns = [
467
434
rf'.*join\([^,]*,\s*"include",\s*"{ re .escape (lib_name )} "[^)]*\),?\n' ,
468
435
rf'.*"include/{ re .escape (lib_name )} "[^,\n]*,?\n' ,
@@ -474,41 +441,23 @@ def _remove_ignored_lib_includes(self) -> None:
474
441
rf'\s*"[^"]*/{ re .escape (lib_name )} /[^"]*",?\n'
475
442
]
476
443
477
- matches_found = []
478
444
for pattern in patterns :
479
445
matches = re .findall (pattern , content )
480
446
if matches :
481
- matches_found .extend (matches )
482
-
483
- if matches_found :
484
- print (f"DEBUG: REMOVING '{ lib_name } ' - found { len (matches_found )} matches:" )
485
- for match in matches_found :
486
- print (f"DEBUG: - { match .strip ()} " )
487
-
488
- for pattern in patterns :
489
447
content = re .sub (pattern , '' , content )
490
- total_removed += len (re .findall (pattern , original_content ))
491
- else :
492
- print (f"DEBUG: No matches found for '{ lib_name } '" )
493
-
494
- print (f"DEBUG: Total lines removed: { total_removed } " )
448
+ total_removed += len (matches )
495
449
496
450
# Clean up empty lines and trailing commas
497
451
content = re .sub (r'\n\s*\n' , '\n ' , content )
498
452
content = re .sub (r',\s*\n\s*\]' , '\n ]' , content )
499
453
500
454
# Validate and write changes
501
455
if self ._validate_changes (original_content , content ) and content != original_content :
502
- print (f"DEBUG: Content changed, writing new file" )
503
456
with open (build_py_path , 'w' ) as f :
504
457
f .write (content )
505
- else :
506
- print (f"DEBUG: No changes made to build file" )
507
458
508
- except Exception as e :
509
- print (f"DEBUG: Exception occurred: { e } " )
510
- import traceback
511
- traceback .print_exc ()
459
+ except Exception :
460
+ pass
512
461
513
462
def _validate_changes (self , original_content : str , new_content : str ) -> bool :
514
463
"""Validate that the changes are reasonable."""
0 commit comments