yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
build_cleaner Namespace Reference

Classes

class  CMakeSourceBlock
 
class  DirectorySpec
 

Functions

 load_gitignore ()
 
bool is_ignored (Path path, gitignore_spec)
 
List[CMakeSourceBlockdiscover_cmake_libraries ()
 
Path relative_to_source (Path path)
 
int parse_block (List[str] lines, int start_idx)
 
Optional[str] parse_entry (str line)
 
Set[str] extract_conditional_files (Path cmake_path, str variable)
 
List[str] gather_expected_sources (CMakeSourceBlock block, Any gitignore_spec=None)
 
bool should_ignore_path (Path path)
 
Set[str] extract_includes (Path file_path)
 
Set[str] extract_symbols (Path file_path)
 
List[str] find_missing_headers (Path source)
 
List[str] find_conditional_blocks_after (List[str] cmake_lines, int end_idx, str variable)
 
bool update_cmake_block (CMakeSourceBlock block, bool dry_run, Any gitignore_spec=None)
 
Optional[Path] find_self_header (Path source)
 
bool has_include (Sequence[str] lines, Iterable[str] header_variants)
 
int find_insert_index (List[str] lines)
 
bool ensure_self_header_include (Path source, bool dry_run)
 
bool add_missing_headers (Path source, bool dry_run, bool iwyu_mode)
 
Set[Path] collect_source_files (List[CMakeSourceBlock] config, Any gitignore_spec=None)
 
List[CMakeSourceBlockget_config (bool auto_discover=False)
 
int run (bool dry_run, bool cmake_only, bool includes_only, bool iwyu_mode, bool auto_discover)
 
int main ()
 

Variables

bool HAS_PATHSPEC = True
 
 PROJECT_ROOT = Path(__file__).resolve().parent.parent
 
str SOURCE_ROOT = PROJECT_ROOT / "src"
 
tuple SUPPORTED_EXTENSIONS = (".cc", ".c", ".cpp", ".cxx", ".mm")
 
tuple HEADER_EXTENSIONS = (".h", ".hh", ".hpp", ".hxx")
 
str BUILD_CLEANER_IGNORE_TOKEN = "build_cleaner:ignore"
 
dict COMMON_HEADERS
 
tuple STATIC_CONFIG
 

Detailed Description

Automate source list maintenance and self-header includes for YAZE.

Function Documentation

◆ load_gitignore()

build_cleaner.load_gitignore ( )
Load .gitignore patterns into a pathspec matcher.

Definition at line 62 of file build_cleaner.py.

Referenced by run().

◆ is_ignored()

bool build_cleaner.is_ignored ( Path  path,
  gitignore_spec 
)
Check if a path should be ignored based on .gitignore patterns.

Definition at line 80 of file build_cleaner.py.

Referenced by collect_source_files(), and gather_expected_sources().

◆ discover_cmake_libraries()

List[CMakeSourceBlock] build_cleaner.discover_cmake_libraries ( )
Auto-discover CMake library files that explicitly opt-in to auto-maintenance.

Looks for marker comments like:
- "# build_cleaner:auto-maintain"
- "# auto-maintained by build_cleaner.py"
- "# AUTO-MAINTAINED"

Only source lists with these markers will be updated.

Supports decomposed libraries where one cmake file defines multiple PREFIX_SUBDIR_SRC
variables (e.g., GFX_TYPES_SRC, GFX_BACKEND_SRC). Automatically scans subdirectories.

Definition at line 92 of file build_cleaner.py.

Referenced by get_config().

◆ relative_to_source()

Path build_cleaner.relative_to_source ( Path  path)

Definition at line 329 of file build_cleaner.py.

Referenced by gather_expected_sources().

◆ parse_block()

int build_cleaner.parse_block ( List[str]  lines,
int  start_idx 
)
Return index of the closing ')' line for a set/list block.

Definition at line 333 of file build_cleaner.py.

Referenced by update_cmake_block().

◆ parse_entry()

Optional[str] build_cleaner.parse_entry ( str  line)

Definition at line 341 of file build_cleaner.py.

Referenced by extract_conditional_files(), and update_cmake_block().

◆ extract_conditional_files()

Set[str] build_cleaner.extract_conditional_files ( Path  cmake_path,
str  variable 
)
Extract files that are added to the variable via conditional blocks (if/endif).

Definition at line 354 of file build_cleaner.py.

References parse_entry().

Referenced by gather_expected_sources().

Here is the call graph for this function:

◆ gather_expected_sources()

List[str] build_cleaner.gather_expected_sources ( CMakeSourceBlock  block,
Any   gitignore_spec = None 
)

Definition at line 407 of file build_cleaner.py.

References extract_conditional_files(), is_ignored(), relative_to_source(), and should_ignore_path().

Referenced by update_cmake_block().

Here is the call graph for this function:

◆ should_ignore_path()

bool build_cleaner.should_ignore_path ( Path  path)

◆ extract_includes()

Set[str] build_cleaner.extract_includes ( Path  file_path)
Extract all #include statements from a source file.

Definition at line 445 of file build_cleaner.py.

Referenced by find_missing_headers().

◆ extract_symbols()

Set[str] build_cleaner.extract_symbols ( Path  file_path)
Extract potential symbols/identifiers that might need headers.

Definition at line 460 of file build_cleaner.py.

Referenced by find_missing_headers().

◆ find_missing_headers()

List[str] build_cleaner.find_missing_headers ( Path  source)
Analyze a source file and suggest missing headers based on symbol usage.

Definition at line 480 of file build_cleaner.py.

References extract_includes(), extract_symbols(), and should_ignore_path().

Referenced by add_missing_headers().

Here is the call graph for this function:

◆ find_conditional_blocks_after()

List[str] build_cleaner.find_conditional_blocks_after ( List[str]  cmake_lines,
int  end_idx,
str  variable 
)
Find conditional blocks (if/endif) that append to the variable after the main set() block.
Returns lines that should be preserved.

Definition at line 501 of file build_cleaner.py.

◆ update_cmake_block()

bool build_cleaner.update_cmake_block ( CMakeSourceBlock  block,
bool  dry_run,
Any   gitignore_spec = None 
)

Definition at line 556 of file build_cleaner.py.

References gather_expected_sources(), parse_block(), and parse_entry().

Referenced by run().

Here is the call graph for this function:

◆ find_self_header()

Optional[Path] build_cleaner.find_self_header ( Path  source)

Definition at line 645 of file build_cleaner.py.

Referenced by ensure_self_header_include().

◆ has_include()

bool build_cleaner.has_include ( Sequence[str]  lines,
Iterable[str]  header_variants 
)
Check if any line includes one of the header variants (with any path or quote style).

Definition at line 653 of file build_cleaner.py.

Referenced by ensure_self_header_include().

◆ find_insert_index()

int build_cleaner.find_insert_index ( List[str]  lines)

Definition at line 676 of file build_cleaner.py.

Referenced by add_missing_headers(), and ensure_self_header_include().

◆ ensure_self_header_include()

bool build_cleaner.ensure_self_header_include ( Path  source,
bool  dry_run 
)
Ensure a source file includes its corresponding header file.

Skips files that:
- Are explicitly ignored
- Have no corresponding header
- Already include their header (in any path format)
- Are test files or main entry points (typically don't include own header)

Definition at line 710 of file build_cleaner.py.

References find_insert_index(), find_self_header(), has_include(), and should_ignore_path().

Referenced by run().

Here is the call graph for this function:

◆ add_missing_headers()

bool build_cleaner.add_missing_headers ( Path  source,
bool  dry_run,
bool  iwyu_mode 
)
Add missing headers based on IWYU-style analysis.

Definition at line 779 of file build_cleaner.py.

References find_insert_index(), find_missing_headers(), and should_ignore_path().

Referenced by run().

Here is the call graph for this function:

◆ collect_source_files()

Set[Path] build_cleaner.collect_source_files ( List[CMakeSourceBlock config,
Any   gitignore_spec = None 
)
Collect all source files from the given configuration, respecting .gitignore patterns.

Definition at line 815 of file build_cleaner.py.

References is_ignored().

Referenced by run().

Here is the call graph for this function:

◆ get_config()

List[CMakeSourceBlock] build_cleaner.get_config ( bool   auto_discover = False)
Get the full configuration, optionally including auto-discovered libraries.

Definition at line 834 of file build_cleaner.py.

References discover_cmake_libraries().

Referenced by run().

Here is the call graph for this function:

◆ run()

int build_cleaner.run ( bool  dry_run,
bool  cmake_only,
bool  includes_only,
bool  iwyu_mode,
bool  auto_discover 
)

◆ main()

int build_cleaner.main ( )

Definition at line 901 of file build_cleaner.py.

References main(), and run().

Referenced by main().

Here is the call graph for this function:

Variable Documentation

◆ HAS_PATHSPEC

bool build_cleaner.HAS_PATHSPEC = True

Definition at line 14 of file build_cleaner.py.

◆ PROJECT_ROOT

build_cleaner.PROJECT_ROOT = Path(__file__).resolve().parent.parent

Definition at line 20 of file build_cleaner.py.

◆ SOURCE_ROOT

str build_cleaner.SOURCE_ROOT = PROJECT_ROOT / "src"

Definition at line 21 of file build_cleaner.py.

◆ SUPPORTED_EXTENSIONS

tuple build_cleaner.SUPPORTED_EXTENSIONS = (".cc", ".c", ".cpp", ".cxx", ".mm")

Definition at line 23 of file build_cleaner.py.

◆ HEADER_EXTENSIONS

tuple build_cleaner.HEADER_EXTENSIONS = (".h", ".hh", ".hpp", ".hxx")

Definition at line 24 of file build_cleaner.py.

◆ BUILD_CLEANER_IGNORE_TOKEN

str build_cleaner.BUILD_CLEANER_IGNORE_TOKEN = "build_cleaner:ignore"

Definition at line 25 of file build_cleaner.py.

◆ COMMON_HEADERS

dict build_cleaner.COMMON_HEADERS
Initial value:
1= {
2 'std::': ['<memory>', '<string>', '<vector>', '<map>', '<set>', '<algorithm>', '<functional>'],
3 'absl::': ['<absl/status/status.h>', '<absl/status/statusor.h>', '<absl/strings/str_format.h>'],
4 'ImGui::': ['<imgui.h>'],
5 'SDL_': ['<SDL.h>'],
6}

Definition at line 28 of file build_cleaner.py.

◆ STATIC_CONFIG

tuple build_cleaner.STATIC_CONFIG

Definition at line 214 of file build_cleaner.py.