stale_build: follow includes through the CMake include directories (STALE-BUILD-INCLUDE-DIRS) #620
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!620
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/620/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@TuroYT on GitHub · 2026-11-24 10:01 UTC · original
TuroYT:fix/stale-build-include-dirs→main· +139 −2 · 2 files · 2 commits · merged 2026-11-24 13:37 UTCClaimed in the coordination issue as: STALE-BUILD-INCLUDE-DIRS (#14)
What was wrong
tools/stale_build.py,program_sources(): a quoted#include "..."was resolved only relative to the includingfile's directory (
os.path.join(os.path.dirname(path), inc)). The build also finds headers through the includedirectories of
runtime/CMakeLists.txt.Reproduction on main (
d7576d56a):runtime/test/pe_loader_test.cppline 25 includes"pe_loader.h", which isruntime/src/pe_loader.h. Thepe_loader_testtarget getssrcandshimsatruntime/CMakeLists.txtlines 657-660. Editingpe_loader.hdidnot make the built program stale, so
make_game.pyandtools/first_light.pycould reuse an old binary, against themodule 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 listsruntime/src,runtime/shims, then the xtaskqueue directories(
runtime/shims/xtaskqueue,third_party/xtaskqueue/Source/Task,Source/Common,Include) thatruntime/CMakeLists.txtgives its test programs at lines 90-92, 1206-1210 and 1227-1229. Every copy found in thosedirectories 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
seenset 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.
The 76 that were not next to their file: 53 are in
runtime/srcorruntime/shims, and 23 are xtaskqueue headers(
TaskQueueImpl.h,TaskQueueP.h,XTaskQueue.h,XTaskQueuePriv.h,pch.h,referenced_ptr.h). All 665 nowresolve, 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 thatmatters here.
Tested
Against the unfixed tool (
tools/stale_build.pytaken from main, test file unchanged): 7 of 11 tests fail, includingthe header-in-
runtime/srccase, the exe-marked-stale case, the xtaskqueue cycle and the real-tree smoke test. Thefour 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
(
srcbeforeshims), which can differ from one CMake target's order: withtarget_include_directories(prog PRIVATE shims src)the compiler takes the shims copy, and editing only that copy leftnewer_sources()empty. The secondcommit follows every copy instead, and
test_editing_only_the_shims_copy_marks_the_exe_stalecovers that case.Not tested
os.path.joinandnormpathhandling was not exercised with backslashes).make_game.pyrun that rebuilds a stale program. Only--helpand the existing dry-run andfirst_light tests were run.
program stale that did not need it (an extra rebuild), never miss one.
AI-assisted (Claude Code).
@Dezmonius on GitHub · 2026-11-24 10:29 UTC · original
Independent Windows 10 check of
a92dd6aagainst21625bc, CPython 3.14.7. All 10 include-directory tests passed on the PR. Six fail when the same tests run against the old implementation, including thepe_loader.hsmoke check.A scope issue with the docstring: the fallback is a fixed directory order, and can differ from an individual CMake target. I verified this with a tiny CMake/MSVC fixture:
test/prog.cppincludes"selection.h", present in both directories. MSVC's include trace showsshims/selection.h. The PR recordssrc/selection.hinstead. After editing only the selected shim header,newer_sources()returned[], even though that header was newer than the binary. A clean rebuild changed the executable's result from 7 to 8.I would document the fixed fallback as an approximation for the covered layout, or use target-specific include order if the intention is to track CMake's actual selection. The fixture is synthetic and demonstrates the limit of the fallback.
AI-assisted (Codex).
@TuroYT on GitHub · 2026-11-24 10:32 UTC · original
Confirmed, and the fixture is a good catch. The first revision took the first match in a fixed order (
src, thenshims), so withtarget_include_directories(prog PRIVATE shims src)an edit to the shims copy was missed.378fcbcfollows every copy found in the include directories instead of the first, so which one a target compiles no longer matters. The cost is an occasional extra rebuild, never a missed one. Your case is now a test,test_editing_only_the_shims_copy_marks_the_exe_stale: it fails on the previous revision and passes on this one.No header name exists in two of these directories on main today (138 names), so the result on the current tree is unchanged: 665 quoted includes, 589 next to their file, 76 through the directories, 0 unresolved. I did not try to follow each target's own order, since that would mean parsing the CMake files.
@madvillain91 on GitHub · 2026-11-24 10:53 UTC · original · reviewed
Independent Windows 11 26H2 (26300.9711) check at
378fcbca4against main21625bca8, using CPython 3.12.3 and Git for Windows 2.56.0.windows.2. All 36 tests acrosstest_stale_build_include_dirs.py,test_first_light_stale_mesh.py, andtest_make_game_dry_run.pypassed (32.442s), confirming Windows path handling andos.utimebehavior. Following every matching copy across_INCLUDE_DIRSis a clean fix for per-target CMake include ordering. LGTM.@Dezmonius on GitHub · 2026-11-24 11:34 UTC · original
Confirmed at
378fcbcon Windows 10 with CPython 3.14.7. All 11 include-directory tests pass. I reused the original MSVC-built fixture withshims src: when only the compiler-selectedruntime/shims/selection.hwas newer than the existing binary, the previous revision returned[]and this revision returned["runtime/shims/selection.h"]. Thanks for adding the case to the suite.Synthetic fixture only. AI-assisted (Codex).
@QemmHD on GitHub · 2026-11-24 13:37 UTC · original
Merging.
Why merged: stale_build follows includes through the CMake include directories, so a header change in another include dir correctly marks a target stale. Dezmonius independently re-checked the fixed head; the "six failures" he first reported were the new tests running against the old implementation, which is expected.
Why it's good: Its tests: 55 passed, 8 skipped, and on current main with main's new tests/test_stale_build.py: 26/26.
Tested on Windows 11, RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, alone on main (
21625bca8or51f316092) and in a cumulative merge of #497, #278, #310, #334, #346, #340, #355, #361, #363, #620 and #577 (which carries #540) on main2d73c242f(git merge-tree: 0 conflicts against current main). Repo-consistency set (cmake/translator-deps, shader_stage_resume, runtime_paths, docs, make_game, no-game-data, run_semantic_tests): 566 passed / 5 skipped / 0 failed on main and on main + batch. compileall OK. Full ctest: 302/304 on main and on main + batch (the same two pre-existing failures, d3d12_execute_indirect_validation and d3d12_depth_resolve, no new ones).AI-assisted (Claude Code, Claude Opus 5.5).
@madvillain91 on GitHub · 2026-11-25 12:12 UTC · original
madvillain8099