feat(tools): compile the changed translation units only #4730

Merged
Dextroid17 merged 2 commits from upstream-pr/4730 into main 2026-10-14 10:56:43 +00:00
Dextroid17 commented 2026-10-12 19:55:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T19:55:52Z.


What

Adds tools/check_compile.py, which compiles only the translation units a change touches, so a contributor learns whether the change compiles without a full build.

The compile commands come from a configured Ninja build of the checkout: compile_commands.json when it exists, otherwise ninja -t compdb. For each file it drops -c, -o, -MD, -MMD, -MP, -MT and -MF, replaces the recorded source argument with the file being checked, adds -fsyntax-only, and runs the command in the directory it was recorded with. The files are the translation units changed between --base (origin/main by default) and the working tree, including new files that are not yet tracked by Git; paths can also be named directly, relative to the working directory or absolute.

python3 tools/check_compile.py --base origin/main
python3 tools/check_compile.py core/libs/prx/libkernel/Module/src/Module.cpp

The head of most pull requests is not compiled automatically: full Linux and Windows builds run only when a collaborator starts one by hand, and the automatic relinker matrix runs only when the author already has a commit in main and the change touches a path the relinker-only build watches. The checks that need no compiler read text — tools/check_conventions.py parses Git objects, and tools/nid_names.py reports already-implemented from a definition in the source — so a read-only check can pass while a translation unit does not build. Measured on one failing file, this tool answers the compile question in 0.6–0.8 s wall. Nothing is linked and no object is written, so it works in a tree whose link step is broken and in a build directory that is configured but not built.

It checks compilation only: it does not link, it does not run the tests, -fsyntax-only stops before code generation, and a configured build directory is required (its recorded include paths are used, so it must be a build of this checkout). A translation unit with no compile command in the build is named on stderr and does not count towards the result; the others decide the exit code. A run in which none of the files, named on the command line or found by --base, has a compile command checks nothing and exits 1, so it cannot read as a pass. A run with no changed translation unit prints that and exits 0.

Tested

  • python3 -m unittest tools.tests.test_check_compile — Ran 15 tests / OK.
  • A translation unit that does not compile, made by adding the line Dl_info bogus_symbol_use; to core/libs/prx/libkernel/Socket/src/Udp.cpp in a scratch checkout: python3 tools/check_compile.py --build <configured build> <path> exits 1, prints the compiler's own diagnostic, beginning error: ‘Dl_info’ does not name a type, and ends with 1 of 1 translation units did not compile. The same invocation on the unmodified file exits 0 with 1 translation units compile. Measured 0.6–0.9 s wall per file for four libkernel files.
  • The flags came from ninja -t compdb on a Ninja build directory that was configured and had no object built, which the tool handles because nothing is linked and no object is written. -fsyntax-only stops before the optimizer, so a warning this project promoted to an error during code generation would not be seen; this tree sets no -Werror.
  • Linux, GCC 16, Release.

Not tested: Windows and macOS; the tool only prefers compile_commands.json when a build writes one.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not one title's
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4834324440 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4730). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T19:55:52Z. --- ### What Adds `tools/check_compile.py`, which compiles only the translation units a change touches, so a contributor learns whether the change compiles without a full build. The compile commands come from a configured Ninja build of the checkout: `compile_commands.json` when it exists, otherwise `ninja -t compdb`. For each file it drops `-c`, `-o`, `-MD`, `-MMD`, `-MP`, `-MT` and `-MF`, replaces the recorded source argument with the file being checked, adds `-fsyntax-only`, and runs the command in the directory it was recorded with. The files are the translation units changed between `--base` (`origin/main` by default) and the working tree, including new files that are not yet tracked by Git; paths can also be named directly, relative to the working directory or absolute. ``` python3 tools/check_compile.py --base origin/main python3 tools/check_compile.py core/libs/prx/libkernel/Module/src/Module.cpp ``` The head of most pull requests is not compiled automatically: full Linux and Windows builds run only when a collaborator starts one by hand, and the automatic relinker matrix runs only when the author already has a commit in `main` and the change touches a path the relinker-only build watches. The checks that need no compiler read text — `tools/check_conventions.py` parses Git objects, and `tools/nid_names.py` reports `already-implemented` from a definition in the source — so a read-only check can pass while a translation unit does not build. Measured on one failing file, this tool answers the compile question in 0.6–0.8 s wall. Nothing is linked and no object is written, so it works in a tree whose link step is broken and in a build directory that is configured but not built. It checks compilation only: it does not link, it does not run the tests, `-fsyntax-only` stops before code generation, and a configured build directory is required (its recorded include paths are used, so it must be a build of this checkout). A translation unit with no compile command in the build is named on stderr and does not count towards the result; the others decide the exit code. A run in which none of the files, named on the command line or found by `--base`, has a compile command checks nothing and exits 1, so it cannot read as a pass. A run with no changed translation unit prints that and exits 0. ### Tested - `python3 -m unittest tools.tests.test_check_compile` — `Ran 15 tests` / `OK`. - A translation unit that does not compile, made by adding the line `Dl_info bogus_symbol_use;` to `core/libs/prx/libkernel/Socket/src/Udp.cpp` in a scratch checkout: `python3 tools/check_compile.py --build <configured build> <path>` exits 1, prints the compiler's own diagnostic, beginning `error: ‘Dl_info’ does not name a type`, and ends with `1 of 1 translation units did not compile`. The same invocation on the unmodified file exits 0 with `1 translation units compile`. Measured 0.6–0.9 s wall per file for four libkernel files. - The flags came from `ninja -t compdb` on a Ninja build directory that was configured and had no object built, which the tool handles because nothing is linked and no object is written. `-fsyntax-only` stops before the optimizer, so a warning this project promoted to an error during code generation would not be seen; this tree sets no `-Werror`. - Linux, GCC 16, `Release`. Not tested: Windows and macOS; the tool only prefers `compile_commands.json` when a build writes one. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not one title's - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 12:27:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T12:27:25Z.


Windows test note: this branch (base 90c683946) no longer merges onto current main 14036cb0e; git merge-tree reports a conflict in CMakeLists.txt, so I could not run its tests on a merged tree. A rebase onto current main would allow a Windows run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145526418 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4730#issuecomment-6145526418). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T12:27:25Z. --- Windows test note: this branch (base `90c683946`) no longer merges onto current `main` `14036cb0e`; `git merge-tree` reports a conflict in `CMakeLists.txt`, so I could not run its tests on a merged tree. A rebase onto current `main` would allow a Windows run. AI-assisted (Claude Code).
Dextroid17 commented 2026-10-13 12:31:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T12:31:18Z.


Confirmed on current main. I ran git merge-tree --write-tree upstream/main a72ac42e37 against upstream/main c827e1187 and it exits 1 with CONFLICT (content): Merge conflict in CMakeLists.txt. The branch needs a rebase before a Windows run on a merged tree. Rebase is pending on the author's side, and I have not pushed anything.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145595388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4730#issuecomment-6145595388). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-13T12:31:18Z. --- Confirmed on current `main`. I ran `git merge-tree --write-tree upstream/main a72ac42e37` against `upstream/main` `c827e1187` and it exits 1 with `CONFLICT (content): Merge conflict in CMakeLists.txt`. The branch needs a rebase before a Windows run on a merged tree. Rebase is pending on the author's side, and I have not pushed anything.
adriadam10 commented 2026-10-13 15:26:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:26:57Z.


Checked on the PR merged onto current main: check_compile ctest passes and fails without the script; on a real libkernel unit the tool exits 0 when it compiles and 1 with the compiler diagnostic after adding an undeclared type. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149047025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4730#issuecomment-6149047025). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T15:26:57Z. --- Checked on the PR merged onto current main: `check_compile` ctest passes and fails without the script; on a real libkernel unit the tool exits 0 when it compiles and 1 with the compiler diagnostic after adding an undeclared type. Merging.
adriadam10 commented 2026-10-14 10:47:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:47:05Z.


The full Build failed check_compile on windows and macOS, caused by the new tests, not by the tool:

  • tools/tests/test_check_compile.py: the temp root was compared unresolved while the tool resolves paths (macOS /private/var vs /var, Windows RUNNER~1 vs runneradmin). The root is now .resolve()d.
  • the ninja stub was a shebang script, which Windows cannot run (ninja not found → exit 2). It now writes a ninja.cmd on Windows and an sh wrapper elsewhere.

Pushed as a commit on top of yours; the 15 tests pass locally, also with TMPDIR behind a symlink. Merging once the Windows build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6166604510 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4730#issuecomment-6166604510). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T10:47:05Z. --- The full Build failed `check_compile` on windows and macOS, caused by the new tests, not by the tool: - `tools/tests/test_check_compile.py`: the temp root was compared unresolved while the tool resolves paths (macOS `/private/var` vs `/var`, Windows `RUNNER~1` vs `runneradmin`). The root is now `.resolve()`d. - the `ninja` stub was a shebang script, which Windows cannot run (`ninja` not found → exit 2). It now writes a `ninja.cmd` on Windows and an `sh` wrapper elsewhere. Pushed as a commit on top of yours; the 15 tests pass locally, also with `TMPDIR` behind a symlink. Merging once the Windows build is green.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!4730
No description provided.