Skip to content

Commit 0a8330a

Browse files
authored
fix dsp detection
1 parent ccdb040 commit 0a8330a

File tree

1 file changed

+20
-71
lines changed

1 file changed

+20
-71
lines changed

builder/frameworks/component_manager.py

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -120,47 +120,27 @@ def _analyze_project_dependencies(self) -> Set[str]:
120120
"""Analyze project files to detect actually used components/libraries."""
121121
used_components = set()
122122

123-
print(f"DEBUG: Starting project analysis")
124-
125123
try:
124+
# Analyze project source files
126125
src_dir = self.env.subst("$PROJECT_SRC_DIR")
127-
print(f"DEBUG: Scanning source directory: {src_dir}")
128-
129126
if os.path.exists(src_dir):
130-
file_count = 0
131127
for root, dirs, files in os.walk(src_dir):
132128
for file in files:
133129
if file.endswith(('.cpp', '.c', '.h', '.hpp', '.ino')):
134-
file_count += 1
135130
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))
142132

143-
# Check lib_deps
133+
# Analyze lib_deps for explicit dependencies (if present)
144134
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)))
157140

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
162143

163-
print(f"DEBUG: Final detected components: {used_components}")
164144
return used_components
165145

166146
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]:
171151
component_patterns = {
172152
'bt': ['bluetooth', 'ble', 'nimble', 'bt_', 'esp_bt', 'esp_ble'],
173153
'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
175155
'esp_http_client': ['esp_http_client', 'http_client'],
176156
'esp_https_ota': ['esp_https_ota', 'esp_ota'],
177157
'mdns': ['mdns', 'esp_mdns'],
@@ -433,36 +413,23 @@ def _remove_ignored_lib_includes(self) -> None:
433413
build_py_path = join(self.arduino_libs_mcu, "pioarduino-build.py")
434414

435415
if not os.path.exists(build_py_path):
436-
print(f"DEBUG: Build file not found: {build_py_path}")
437416
return
438417

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-
446418
try:
447419
with open(build_py_path, 'r') as f:
448420
content = f.read()
449421

450422
original_content = content
451423
total_removed = 0
452424

453-
# Check each library individually
425+
# Remove CPPPATH entries for each ignored library
454426
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")
463430
continue
464-
465-
# Check what would be removed
431+
432+
# Multiple patterns to catch different include formats
466433
patterns = [
467434
rf'.*join\([^,]*,\s*"include",\s*"{re.escape(lib_name)}"[^)]*\),?\n',
468435
rf'.*"include/{re.escape(lib_name)}"[^,\n]*,?\n',
@@ -474,41 +441,23 @@ def _remove_ignored_lib_includes(self) -> None:
474441
rf'\s*"[^"]*/{re.escape(lib_name)}/[^"]*",?\n'
475442
]
476443

477-
matches_found = []
478444
for pattern in patterns:
479445
matches = re.findall(pattern, content)
480446
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:
489447
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)
495449

496450
# Clean up empty lines and trailing commas
497451
content = re.sub(r'\n\s*\n', '\n', content)
498452
content = re.sub(r',\s*\n\s*\]', '\n]', content)
499453

500454
# Validate and write changes
501455
if self._validate_changes(original_content, content) and content != original_content:
502-
print(f"DEBUG: Content changed, writing new file")
503456
with open(build_py_path, 'w') as f:
504457
f.write(content)
505-
else:
506-
print(f"DEBUG: No changes made to build file")
507458

508-
except Exception as e:
509-
print(f"DEBUG: Exception occurred: {e}")
510-
import traceback
511-
traceback.print_exc()
459+
except Exception:
460+
pass
512461

513462
def _validate_changes(self, original_content: str, new_content: str) -> bool:
514463
"""Validate that the changes are reasonable."""

0 commit comments

Comments
 (0)