Repository navigation
Fix build_with_debinfo.py broken by CONFIGURE_DEPENDS globbing - #188192
Merged
Merged
Conversation
## Summary `tools/build_with_debinfo.py` recompiles named source files with `-g` so you can get debug info for a targeted file without a full (slow, ABI-incompatible) debug build. It is referenced in `CONTRIBUTING.md`, and it broke on current `main`: running it just prints `Nothing to do` and rebuilds nothing. ## Root cause The tool derived its compile/link commands from `ninja -j1 -v -n torch_python` (a dry run) and rewrote `-O2`/`-O3` to `-g`. The build now uses `file(GLOB ... CONFIGURE_DEPENDS)`, which wires a glob-verification step into `build.ninja`'s own regeneration (`CMakeFiles/VerifyGlobs.cmake` + `regenerate-during-build`). In dry-run (`-n`) mode ninja cannot run that check or reload the regenerated graph, so `ninja -n <target>` only ever reports the regeneration step and never the real compile/link commands. The tool parsed an empty plan and no-op'd. ## Fix Source the commands from places the glob-check does not gate: - the per-file compile command from `build/compile_commands.json` (rewrite `-O2`/`-O3` -> `-g`); - the `libtorch_python` link command from `ninja -t commands torch_python` (a graph walk, not a dry run; strip ninja's `: && ... && :` wrapper). Then symlink `build/lib` into `torch/lib` as before. The tool now rebuilds exactly the files you name plus the relink, rather than touching sources and relying on ninja's staleness detection. The old `>100 stale items` guard was a dry-run artifact and is removed; the tool now requires `compile_commands.json` and an already-built tree. ## Tests - **Unit tests** (`tools/test/test_build_with_debinfo.py`) for the pure plan-derivation helpers: the `-O` -> `-g` rewrite, `compile_commands.json` indexing, the command/arguments entry forms, and the `ninja -t commands` link extraction. - **Build-tree smoke check**: a new `--dry-run` mode plus a step in `.ci/pytorch/build.sh` that, after the Linux build, asserts the emitted plan contains a `-g` compile and the `libtorch_python` relink. This exercises the real `compile_commands.json` and `ninja -t commands` and fails loudly if a future build-system change breaks those data sources -- the class of bug here, which unit tests alone would not catch. `--dry-run` only reads the tree, so it does not dirty the checkout. ## Test plan Validated on a real editable CUDA build of `viable/strict`: ``` python tools/build_with_debinfo.py --verbose torch/csrc/Module.cpp ``` recompiles `Module.cpp.o` with `.debug_info`, relinks `libtorch_python.so` (which then carries `.debug_info`), symlinks it into `torch/lib`, and `import torch` still works. ``` python tools/build_with_debinfo.py --dry-run torch/csrc/Module.cpp ``` exits 0, prints the plan, and leaves the git tree clean; the build.sh `-g` and `libtorch_python` plan assertions both pass against that output. ``` python -m pytest tools/test/test_build_with_debinfo.py ``` -> 9 passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #186780 Approved by: https://github.com/benjaminglass1, https://github.com/atalman Co-authored-by: Benjamin Glass <[email protected]> (cherry picked from commit 8f9a6c8)
This was referenced Jun 25, 2026
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/188192
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 56 PendingAs of commit 2fd87b3 with merge base 636bc91 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
20 of 27 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tools/build_with_debinfo.pyrecompiles named source files with-gso youcan get debug info for a targeted file without a full (slow, ABI-incompatible)
debug build. It is referenced in
CONTRIBUTING.md, and it broke on currentmain: running it just printsNothing to doand rebuilds nothing.Root cause
The tool derived its compile/link commands from
ninja -j1 -v -n torch_python(a dry run) and rewrote
-O2/-O3to-g. The build now usesfile(GLOB ... CONFIGURE_DEPENDS), which wires a glob-verification step intobuild.ninja's own regeneration (CMakeFiles/VerifyGlobs.cmake+regenerate-during-build). In dry-run (-n) mode ninja cannot run that checkor reload the regenerated graph, so
ninja -n <target>only ever reports theregeneration step and never the real compile/link commands. The tool parsed an
empty plan and no-op'd.
Fix
Source the commands from places the glob-check does not gate:
build/compile_commands.json(rewrite-O2/-O3->-g);libtorch_pythonlink command fromninja -t commands torch_python(a graph walk, not a dry run; strip ninja's
: && ... && :wrapper).Then symlink
build/libintotorch/libas before. The tool now rebuildsexactly the files you name plus the relink, rather than touching sources and
relying on ninja's staleness detection. The old
>100 stale itemsguard was adry-run artifact and is removed; the tool now requires
compile_commands.jsonand an already-built tree.
Tests
tools/test/test_build_with_debinfo.py) for the pureplan-derivation helpers: the
-O->-grewrite,compile_commands.jsonindexing, the command/arguments entry forms, and the
ninja -t commandslink extraction.
--dry-runmode plus a step in.ci/pytorch/build.shthat, after the Linux build, asserts the emitted plancontains a
-gcompile and thelibtorch_pythonrelink. This exercises thereal
compile_commands.jsonandninja -t commandsand fails loudly if afuture build-system change breaks those data sources -- the class of bug
here, which unit tests alone would not catch.
--dry-runonly reads thetree, so it does not dirty the checkout.
Test plan
Validated on a real editable CUDA build of
viable/strict:recompiles
Module.cpp.owith.debug_info, relinkslibtorch_python.so(which then carries
.debug_info), symlinks it intotorch/lib, andimport torchstill works.exits 0, prints the plan, and leaves the git tree clean; the build.sh
-gandlibtorch_pythonplan assertions both pass against that output.-> 9 passed.
🤖 Generated with Claude Code