MCPcopy Create free account
hub / github.com/FastLED/FastLED / cleanup_build_artifacts

Function cleanup_build_artifacts

ci/meson/meson_cleanup.py:21–94  ·  view source on GitHub ↗

Clean all build artifacts from a build directory. This function centralizes all build artifact cleanup logic and provides consistent failure tracking and reporting. It's designed to be called when debug mode, build mode, or compiler version changes. Args: build_dir: Me

(build_dir: Path, reason: str)

Source from the content-addressed store, hash-verified

19
20
21def cleanup_build_artifacts(build_dir: Path, reason: str) -> dict[str, CleanupResult]:
22 """
23 Clean all build artifacts from a build directory.
24
25 This function centralizes all build artifact cleanup logic and provides
26 consistent failure tracking and reporting. It's designed to be called
27 when debug mode, build mode, or compiler version changes.
28
29 Args:
30 build_dir: Meson build directory to clean
31 reason: Human-readable reason for cleanup (e.g., "debug mode changed")
32
33 Returns:
34 Dictionary mapping artifact type to CleanupResult with deletion stats
35 """
36 _ts_print(f"[MESON] 🗑️ {reason} - cleaning all build artifacts")
37
38 # Artifact types with their file extensions
39 # Format: (display_name, list of glob patterns)
40 artifact_types: list[tuple[str, list[str]]] = [
41 ("object files", ["*.obj", "*.o"]),
42 ("static libraries", ["*.a"]),
43 ("executables", ["*.exe"]),
44 ("precompiled headers", ["*.pch"]),
45 ("Windows static libraries", ["*.lib"]),
46 ("Windows DLLs", ["*.dll"]),
47 ("Linux shared objects", ["*.so"]),
48 ("macOS dynamic libraries", ["*.dylib"]),
49 ]
50
51 results: dict[str, CleanupResult] = {}
52
53 for display_name, patterns in artifact_types:
54 deleted = 0
55 failed = 0
56 failed_files: list[str] = []
57
58 for pattern in patterns:
59 files = glob.glob(str(build_dir / "**" / pattern), recursive=True)
60 for file_path in files:
61 try:
62 Path(file_path).unlink()
63 deleted += 1
64 except (OSError, IOError) as e:
65 failed += 1
66 failed_files.append(f"{file_path}: {e}")
67
68 results[display_name] = CleanupResult(
69 deleted=deleted, failed=failed, failed_files=failed_files
70 )
71
72 # Build summary message
73 summary_parts: list[str] = []
74 total_failed = 0
75 for display_name, result in results.items():
76 if result.deleted > 0 or result.failed > 0:
77 summary_parts.append(f"{result.deleted} {display_name}")
78 total_failed += result.failed

Callers 3

setup_meson_buildFunction · 0.90
_recover_stale_buildFunction · 0.85

Calls 4

CleanupResultClass · 0.85
unlinkMethod · 0.80
itemsMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected