refactor(build): improve auto-discovery of GUI library sources in build_cleaner.py

- Enhanced the discover_cmake_libraries function to identify decomposed libraries and handle special cases for source variables.
- Updated gui_library.cmake to utilize auto-maintenance markers, streamlining the management of source lists for GUI components.
- Commented out hardcoded CMake source blocks, allowing for dynamic discovery of source files.

Benefits:
- Simplifies the maintenance of GUI library sources by automating updates and reducing manual configuration.
- Improves clarity and efficiency in the build process for GUI components.
This commit is contained in:
scawful
2025-10-13 20:25:00 -04:00
parent 99424fa2b2
commit 530b4e8f76
2 changed files with 61 additions and 26 deletions

View File

@@ -159,6 +159,10 @@ def discover_cmake_libraries() -> List[CMakeSourceBlock]:
# If a prefix has multiple variables, treat it as a decomposed library
decomposed_prefixes = {p for p, vars in prefix_groups.items() if len(vars) >= 2}
# Check if this looks like a decomposed library (multiple *_SRC vars)
# even if some don't follow the PREFIX_SUBDIR_SRC pattern
is_likely_decomposed = len(variables) >= 2 and any(p in decomposed_prefixes for p in prefix_groups)
for var_name in variables:
# Try to extract subdirectory from variable name
subdir_match = re.match(r'([A-Z]+)_([A-Z_]+)_(?:SRC|SOURCES|SOURCE)$', var_name)
@@ -179,6 +183,22 @@ def discover_cmake_libraries() -> List[CMakeSourceBlock]:
))
continue
# Handle special cases: CANVAS_SRC, etc. (no prefix, just subdirectory name)
# Pattern: SUBDIR_SRC where SUBDIR is a lowercase directory name
simple_match = re.match(r'([A-Z]+)_(?:SRC|SOURCES|SOURCE)$', var_name)
if simple_match and is_likely_decomposed:
subdir_part = simple_match.group(1)
subdir = subdir_part.lower()
target_dir = cmake_dir / subdir
if target_dir.exists() and target_dir.is_dir():
blocks.append(CMakeSourceBlock(
variable=var_name,
cmake_path=cmake_file,
directories=(DirectorySpec(target_dir, recursive=True),),
))
continue
# Fallback: scan entire cmake directory
blocks.append(CMakeSourceBlock(
variable=var_name,
@@ -259,31 +279,32 @@ STATIC_CONFIG: Sequence[CMakeSourceBlock] = (
# cmake_path=SOURCE_ROOT / "app/gfx/gfx_library.cmake",
# directories=(DirectorySpec(SOURCE_ROOT / "app/gfx/debug"),),
# ),
CMakeSourceBlock(
variable="GUI_CORE_SRC",
cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
directories=(DirectorySpec(SOURCE_ROOT / "app/gui/core"),),
),
CMakeSourceBlock(
variable="CANVAS_SRC",
cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
directories=(DirectorySpec(SOURCE_ROOT / "app/gui/canvas"),),
),
CMakeSourceBlock(
variable="GUI_WIDGETS_SRC",
cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
directories=(DirectorySpec(SOURCE_ROOT / "app/gui/widgets"),),
),
CMakeSourceBlock(
variable="GUI_AUTOMATION_SRC",
cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
directories=(DirectorySpec(SOURCE_ROOT / "app/gui/automation"),),
),
CMakeSourceBlock(
variable="GUI_APP_SRC",
cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
directories=(DirectorySpec(SOURCE_ROOT / "app/gui/app"),),
),
# Note: GUI library variables commented out - now auto-discovered via markers
# CMakeSourceBlock(
# variable="GUI_CORE_SRC",
# cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
# directories=(DirectorySpec(SOURCE_ROOT / "app/gui/core"),),
# ),
# CMakeSourceBlock(
# variable="CANVAS_SRC",
# cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
# directories=(DirectorySpec(SOURCE_ROOT / "app/gui/canvas"),),
# ),
# CMakeSourceBlock(
# variable="GUI_WIDGETS_SRC",
# cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
# directories=(DirectorySpec(SOURCE_ROOT / "app/gui/widgets"),),
# ),
# CMakeSourceBlock(
# variable="GUI_AUTOMATION_SRC",
# cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
# directories=(DirectorySpec(SOURCE_ROOT / "app/gui/automation"),),
# ),
# CMakeSourceBlock(
# variable="GUI_APP_SRC",
# cmake_path=SOURCE_ROOT / "app/gui/gui_library.cmake",
# directories=(DirectorySpec(SOURCE_ROOT / "app/gui/app"),),
# ),
CMakeSourceBlock(
variable="YAZE_AGENT_SOURCES",
cmake_path=SOURCE_ROOT / "cli/agent.cmake",

View File

@@ -7,7 +7,12 @@
# compatibility.
# ==============================================================================
# 1. Define Source Groups for each sub-library
# ==============================================================================
# SOURCE LISTS (auto-maintained by build_cleaner.py)
# Paths are relative to src/ directory
# ==============================================================================
# build_cleaner:auto-maintain
set(GUI_CORE_SRC
app/gui/core/background_renderer.cc
app/gui/core/color.cc
@@ -18,6 +23,7 @@ set(GUI_CORE_SRC
app/gui/core/ui_helpers.cc
)
# build_cleaner:auto-maintain
set(CANVAS_SRC
app/gui/canvas/bpp_format_ui.cc
app/gui/canvas/canvas.cc
@@ -30,6 +36,7 @@ set(CANVAS_SRC
app/gui/canvas/canvas_utils.cc
)
# build_cleaner:auto-maintain
set(GUI_WIDGETS_SRC
app/gui/widgets/asset_browser.cc
app/gui/widgets/dungeon_object_emulator_preview.cc
@@ -39,6 +46,7 @@ set(GUI_WIDGETS_SRC
app/gui/widgets/tile_selector_widget.cc
)
# build_cleaner:auto-maintain
set(GUI_AUTOMATION_SRC
app/gui/automation/widget_auto_register.cc
app/gui/automation/widget_id_registry.cc
@@ -46,6 +54,7 @@ set(GUI_AUTOMATION_SRC
app/gui/automation/widget_state_capture.cc
)
# build_cleaner:auto-maintain
set(GUI_APP_SRC
app/gui/app/agent_chat_widget.cc
app/gui/app/collaboration_panel.cc
@@ -53,6 +62,11 @@ set(GUI_APP_SRC
app/gui/app/editor_layout.cc
)
# ==============================================================================
# LIBRARY DEFINITIONS AND LINK STRUCTURE (manually configured)
# DO NOT AUTO-MAINTAIN
# ==============================================================================
# 2. Create Static Libraries and Establish Link Dependencies
add_library(yaze_gui_core STATIC ${GUI_CORE_SRC})
add_library(yaze_canvas STATIC ${CANVAS_SRC})