Find all files that use the specified macro.
(macro_name: str)
| 54 | |
| 55 | |
| 56 | def find_files_using_macro(macro_name: str) -> set[Path]: |
| 57 | """Find all files that use the specified macro.""" |
| 58 | files_with_macro: set[Path] = set() |
| 59 | |
| 60 | for pattern in FILE_PATTERNS: |
| 61 | for file_path in PROJECT_ROOT.glob(pattern): |
| 62 | if not file_path.is_file() or should_skip_path(file_path): |
| 63 | continue |
| 64 | |
| 65 | try: |
| 66 | content = file_path.read_text(encoding="utf-8", errors="ignore") |
| 67 | # Match FL_HAS_INCLUDE(...) usage (not definitions) |
| 68 | # Look for FL_HAS_INCLUDE followed by ( |
| 69 | if re.search(rf"\b{macro_name}\s*\(", content): |
| 70 | # Exclude lines that define the macro |
| 71 | lines_with_macro = [ |
| 72 | line |
| 73 | for line in content.splitlines() |
| 74 | if re.search(rf"\b{macro_name}\s*\(", line) |
| 75 | ] |
| 76 | |
| 77 | # Check if any line is NOT a definition |
| 78 | has_usage = False |
| 79 | for line in lines_with_macro: |
| 80 | # Skip #define FL_HAS_INCLUDE lines |
| 81 | if re.match(r"^\s*#\s*define\s+" + macro_name, line): |
| 82 | continue |
| 83 | # Skip comments |
| 84 | if "//" in line and line.index("//") < line.index(macro_name): |
| 85 | continue |
| 86 | has_usage = True |
| 87 | break |
| 88 | |
| 89 | if has_usage: |
| 90 | files_with_macro.add(file_path) |
| 91 | except KeyboardInterrupt: |
| 92 | _thread.interrupt_main() |
| 93 | raise |
| 94 | except Exception as e: |
| 95 | print(f"Warning: Could not read {file_path}: {e}", file=sys.stderr) |
| 96 | |
| 97 | return files_with_macro |
| 98 | |
| 99 | |
| 100 | def check_has_include(file_path: Path, include_path: str) -> bool: |