feat(tools): compile the changed translation units only #4730
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4730"
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?
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.jsonwhen it exists, otherwiseninja -t compdb. For each file it drops-c,-o,-MD,-MMD,-MP,-MTand-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/mainby 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.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
mainand the change touches a path the relinker-only build watches. The checks that need no compiler read text —tools/check_conventions.pyparses Git objects, andtools/nid_names.pyreportsalready-implementedfrom 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-onlystops 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.Dl_info bogus_symbol_use;tocore/libs/prx/libkernel/Socket/src/Udp.cppin a scratch checkout:python3 tools/check_compile.py --build <configured build> <path>exits 1, prints the compiler's own diagnostic, beginningerror: ‘Dl_info’ does not name a type, and ends with1 of 1 translation units did not compile. The same invocation on the unmodified file exits 0 with1 translation units compile. Measured 0.6–0.9 s wall per file for four libkernel files.ninja -t compdbon 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-onlystops before the optimizer, so a warning this project promoted to an error during code generation would not be seen; this tree sets no-Werror.Release.Not tested: Windows and macOS; the tool only prefers
compile_commands.jsonwhen a build writes one.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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 currentmain14036cb0e;git merge-treereports a conflict inCMakeLists.txt, so I could not run its tests on a merged tree. A rebase onto currentmainwould allow a Windows run.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T12:31:18Z.
Confirmed on current
main. I rangit merge-tree --write-tree upstream/main a72ac42e37againstupstream/mainc827e1187and it exits 1 withCONFLICT (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.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:26:57Z.
Checked on the PR merged onto current main:
check_compilectest 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.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:47:05Z.
The full Build failed
check_compileon 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/varvs/var, WindowsRUNNER~1vsrunneradmin). The root is now.resolve()d.ninjastub was a shebang script, which Windows cannot run (ninjanot found → exit 2). It now writes aninja.cmdon Windows and anshwrapper elsewhere.Pushed as a commit on top of yours; the 15 tests pass locally, also with
TMPDIRbehind a symlink. Merging once the Windows build is green.