[PR #620] [MERGED] stale_build: follow includes through the CMake include directories (STALE-BUILD-INCLUDE-DIRS) #661

Closed
opened 2026-11-26 20:18:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/620
Author: @TuroYT
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/stale-build-include-dirs


📝 Commits (2)

  • a92dd6a stale_build: follow includes through the CMake include directories (STALE-BUILD-INCLUDE-DIRS)
  • 378fcbc stale_build: follow every copy of a header in the include directories

📊 Changes

2 files changed (+139 additions, -2 deletions)

View changed files

➕ tests/test_stale_build_include_dirs.py (+109 -0)
📝 tools/stale_build.py (+30 -2)

📄 Description

Claimed in the coordination issue as: STALE-BUILD-INCLUDE-DIRS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128145674)

What was wrong

tools/stale_build.py, program_sources(): a quoted #include "..." was resolved only relative to the including
file's directory (os.path.join(os.path.dirname(path), inc)). The build also finds headers through the include
directories of runtime/CMakeLists.txt.

Reproduction on main (d7576d56a):

python3 -I -c "import sys; sys.path.insert(0,'tools'); import stale_build as s; print(s.program_sources('.', 'pe_loader_test'))"
['runtime/test/pe_loader_test.cpp']

runtime/test/pe_loader_test.cpp line 25 includes "pe_loader.h", which is runtime/src/pe_loader.h. The
pe_loader_test target gets src and shims at runtime/CMakeLists.txt lines 657-660. Editing pe_loader.h did
not make the built program stale, so make_game.py and tools/first_light.py could reuse an old binary, against the
module docstring.

What changed

  • tools/stale_build.py: a new _resolve_include() looks an include up next to the including file first (unchanged),
    then in _INCLUDE_DIRS. The constant lists runtime/src, runtime/shims, then the xtaskqueue directories
    (runtime/shims/xtaskqueue, third_party/xtaskqueue/Source/Task, Source/Common, Include) that
    runtime/CMakeLists.txt gives its test programs at lines 90-92, 1206-1210 and 1227-1229. Every copy found in those
    directories counts as a source, not only the first: CMake orders the directories per target, so a header present in
    two of them could be the copy a given program compiles. No header name exists in two of them today. An include
    found nowhere is skipped, as before. The seen set still stops cycles.
  • tests/test_stale_build_include_dirs.py (new): 11 tests: ten on temporary trees and one smoke test on the real tree.
    It does not touch tests/test_stale_build.py, which belongs to #611.

Corpus numbers (every runtime/test/*.cpp)

Quoted includes counted with the same regex as the tool.

before after
files 240 240
quoted includes 665 665
resolve next to the including file 589 589
resolve through the new directories 0 76
resolve nowhere 76 0

The 76 that were not next to their file: 53 are in runtime/src or runtime/shims, and 23 are xtaskqueue headers
(TaskQueueImpl.h, TaskQueueP.h, XTaskQueue.h, XTaskQueuePriv.h, pch.h, referenced_ptr.h). All 665 now
resolve, and none is a system or generated header.

Note: 368 includes have no / in their name, but most of those sit next to their file. The 76 is the count that
matters here.

Tested

python3 -m compileall -q tools tests                          # ok
python3 -I tests/test_stale_build_include_dirs.py             # Ran 11 tests ... OK
python3 -I tests/test_text_write_line_endings.py              # Ran 3 tests ... OK
python3 -I scripts/check_no_game_data.py tools/stale_build.py tests/test_stale_build_include_dirs.py   # rc 0
python3 -I make_game.py --help                                # rc 0
python3 -I tests/test_first_light_stale_mesh.py               # OK
python3 -I tests/test_make_game_dry_run.py                    # OK

Against the unfixed tool (tools/stale_build.py taken from main, test file unchanged): 7 of 11 tests fail, including
the header-in-runtime/src case, the exe-marked-stale case, the xtaskqueue cycle and the real-tree smoke test. The
four that pass on both (next-to-program wins, unresolved header skipped, relative resolution unchanged, missing
program) pin behaviour that must not change.

PR #611 (tests/test_stale_build.py, 15 tests) copied into the worktree and run against the fixed tool: 15 tests OK.
The copy was deleted afterwards.

Review follow-up

Dezmonius checked this on Windows 10 and pointed out that the first revision took the first match in a fixed order
(src before shims), which can differ from one CMake target's order: with target_include_directories(prog PRIVATE shims src) the compiler takes the shims copy, and editing only that copy left newer_sources() empty. The second
commit follows every copy instead, and test_editing_only_the_shims_copy_marks_the_exe_stale covers that case.

Not tested

  • Windows paths (the os.path.join and normpath handling was not exercised with backslashes).
  • An end-to-end make_game.py run that rebuilds a stale program. Only --help and the existing dry-run and
    first_light tests were run.
  • The xtaskqueue directories are added for every program, not only the ones CMake gives them. That can only mark a
    program stale that did not need it (an extra rebuild), never miss one.

AI-assisted (Claude Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/620 **Author:** [@TuroYT](https://github.com/TuroYT) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/stale-build-include-dirs` --- ### 📝 Commits (2) - [`a92dd6a`](https://github.com/ubiquitarianism/leonida/commit/a92dd6a11c7365c5bda5f5cff7af9cda44b48471) stale_build: follow includes through the CMake include directories (STALE-BUILD-INCLUDE-DIRS) - [`378fcbc`](https://github.com/ubiquitarianism/leonida/commit/378fcbca40cf8b7d42f1de5949c0695dd8d7ce02) stale_build: follow every copy of a header in the include directories ### 📊 Changes **2 files changed** (+139 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_stale_build_include_dirs.py` (+109 -0) 📝 `tools/stale_build.py` (+30 -2) </details> ### 📄 Description Claimed in the coordination issue as: STALE-BUILD-INCLUDE-DIRS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128145674) ## What was wrong `tools/stale_build.py`, `program_sources()`: a quoted `#include "..."` was resolved only relative to the including file's directory (`os.path.join(os.path.dirname(path), inc)`). The build also finds headers through the include directories of `runtime/CMakeLists.txt`. Reproduction on main (d7576d56a): python3 -I -c "import sys; sys.path.insert(0,'tools'); import stale_build as s; print(s.program_sources('.', 'pe_loader_test'))" ['runtime/test/pe_loader_test.cpp'] `runtime/test/pe_loader_test.cpp` line 25 includes `"pe_loader.h"`, which is `runtime/src/pe_loader.h`. The `pe_loader_test` target gets `src` and `shims` at `runtime/CMakeLists.txt` lines 657-660. Editing `pe_loader.h` did not make the built program stale, so `make_game.py` and `tools/first_light.py` could reuse an old binary, against the module docstring. ## What changed - `tools/stale_build.py`: a new `_resolve_include()` looks an include up next to the including file first (unchanged), then in `_INCLUDE_DIRS`. The constant lists `runtime/src`, `runtime/shims`, then the xtaskqueue directories (`runtime/shims/xtaskqueue`, `third_party/xtaskqueue/Source/Task`, `Source/Common`, `Include`) that `runtime/CMakeLists.txt` gives its test programs at lines 90-92, 1206-1210 and 1227-1229. Every copy found in those directories counts as a source, not only the first: CMake orders the directories per target, so a header present in two of them could be the copy a given program compiles. No header name exists in two of them today. An include found nowhere is skipped, as before. The `seen` set still stops cycles. - `tests/test_stale_build_include_dirs.py` (new): 11 tests: ten on temporary trees and one smoke test on the real tree. It does not touch `tests/test_stale_build.py`, which belongs to #611. ## Corpus numbers (every `runtime/test/*.cpp`) Quoted includes counted with the same regex as the tool. | | before | after | |---|---|---| | files | 240 | 240 | | quoted includes | 665 | 665 | | resolve next to the including file | 589 | 589 | | resolve through the new directories | 0 | 76 | | resolve nowhere | 76 | 0 | The 76 that were not next to their file: 53 are in `runtime/src` or `runtime/shims`, and 23 are xtaskqueue headers (`TaskQueueImpl.h`, `TaskQueueP.h`, `XTaskQueue.h`, `XTaskQueuePriv.h`, `pch.h`, `referenced_ptr.h`). All 665 now resolve, and none is a system or generated header. Note: 368 includes have no `/` in their name, but most of those sit next to their file. The 76 is the count that matters here. ## Tested python3 -m compileall -q tools tests # ok python3 -I tests/test_stale_build_include_dirs.py # Ran 11 tests ... OK python3 -I tests/test_text_write_line_endings.py # Ran 3 tests ... OK python3 -I scripts/check_no_game_data.py tools/stale_build.py tests/test_stale_build_include_dirs.py # rc 0 python3 -I make_game.py --help # rc 0 python3 -I tests/test_first_light_stale_mesh.py # OK python3 -I tests/test_make_game_dry_run.py # OK Against the unfixed tool (`tools/stale_build.py` taken from main, test file unchanged): 7 of 11 tests fail, including the header-in-`runtime/src` case, the exe-marked-stale case, the xtaskqueue cycle and the real-tree smoke test. The four that pass on both (next-to-program wins, unresolved header skipped, relative resolution unchanged, missing program) pin behaviour that must not change. PR #611 (`tests/test_stale_build.py`, 15 tests) copied into the worktree and run against the fixed tool: 15 tests OK. The copy was deleted afterwards. ## Review follow-up Dezmonius checked this on Windows 10 and pointed out that the first revision took the first match in a fixed order (`src` before `shims`), which can differ from one CMake target's order: with `target_include_directories(prog PRIVATE shims src)` the compiler takes the shims copy, and editing only that copy left `newer_sources()` empty. The second commit follows every copy instead, and `test_editing_only_the_shims_copy_marks_the_exe_stale` covers that case. ## Not tested - Windows paths (the `os.path.join` and `normpath` handling was not exercised with backslashes). - An end-to-end `make_game.py` run that rebuilds a stale program. Only `--help` and the existing dry-run and first_light tests were run. - The xtaskqueue directories are added for every program, not only the ones CMake gives them. That can only mark a program stale that did not need it (an extra rebuild), never miss one. AI-assisted (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:37 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#661
No description provided.