Repository navigation
fix(tools): check sources whose compile command runs through cmake -E env - #12971
Conversation
… env CMake writes a launcher that sets environment variables as a leading `cmake -E env NAME=VALUE ... <launcher> <compiler>`, as the AGC execution tests' ccache launcher does. check_compile took cmake for the compiler, inserted -fsyntax-only before -E and dropped -E as a preprocessing option, so every such source failed with "CMake Error: Unknown argument". Keep the env prefix (NAME=VALUE, --unset=, --modify and --) and rewrite only the command after it; reject its other options and a prefix without a command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rooklz
left a comment
There was a problem hiding this comment.
Reviewed head 151625b on macOS arm64, Python 3.13, CMake 4.3.1, against main bb04a4f.
Approve.
git merge-treeagainstmain,git diff --checkandcheck_conventions.py --base upstream/mainare all clean.tools/tests/test_check_compile.pypasses 55 tests (2 skipped),test_check_compile_modes.py45 (5 skipped) andtest_check_compile_preprocessor.py6 (1 skipped). The realcmake -E envrow ran here: cmake is on PATH and the row was not skipped.- Negative control: with
main'stools/check_compile.pyand the PR's tests, all 9 new rows fail (3 prefix subtests, 5 rejection subtests and the real-cmake row). With the PR's tool, all pass. - I checked the parser against CMake 4.3.1's own
cmake -E env, and they agree:-,-x,--chdir=x, a bare--unsetand--modify=…are all rejected as "unknown option".- A bare
--modifygives "missing a parameter". A=1andA=1 --give "no command given".- CMake takes
=xas an assignment. After--, aB=2is run as the command, which matchesbreakon--.
- Other shapes I tried also behave correctly. A nested
cmake -E env cmake -E env cc …recurses properly, and an upper-caseCMAKE.EXEis recognised. Accache cmake -E env …ordering is still rewritten the old way. That is outside this PR's scope and covered by the debt line ("wrappers with their own option grammar are not covered").
Mutants on launcher_prefix, run against CheckCompileLauncherTests + CheckCompilePathSelectionTests:
| mutant | result |
|---|---|
Path instead of PureWindowsPath for the stem |
killed (cmake.exe row) |
drop the --unset= branch |
killed |
accept -…=… options |
killed (--chdir=x row) |
| drop the no-command check | killed |
drop the stem == "cmake" test |
survives |
-- → continue instead of break |
survives; only differs when an option-looking token follows -- |
--modify skips 1 instead of 2 |
survives; equivalent, because a --modify operand always has = |
=x taken as the command |
survives; CMake takes it as an assignment |
Optional: one row would kill the stem mutant. It checks that a compiler whose arguments happen to start with -E env is not taken for a launcher:
- input:
syntax_arguments(["g++", "-E", "env", "-c", str(source)], …) - PR head gives the ordinary rewrite:
["g++", "-fsyntax-only", "env", str(source)] - the mutant raises:
unsupported cmake -E env option -c
I checked both results here.
AI-assisted: yes
A compiler whose arguments happen to begin with -E env keeps the ordinary rewrite; without the stem check it was taken for the launcher and refused -c. Suggested by rooklz in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review and the mutant run. I added your row in |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Supplemental Windows qualification of
Optional test-only follow-up for the I also confirmed the corresponding valid shape with real CMake: an outer --- a/tools/tests/test_check_compile.py
+++ b/tools/tests/test_check_compile.py
@@ -1010,6 +1010,13 @@
Path.cwd(), source),
[*prefix, "ccache", "g++", "-fsyntax-only", "-DNAME=1", "-include", "pch.hxx", str(source)])
+ def test_env_delimiter_preserves_a_command_path_containing_equals(self):
+ source = Path.cwd() / "unit.cpp"
+ prefix = ["cmake", "-E", "env", "--"]
+ command = "compiler=tools/g++"
+ self.assertEqual(check_compile.syntax_arguments([*prefix, command, "-c", str(source)], Path.cwd(), source),
+ [*prefix, command, "-fsyntax-only", str(source)])
+
def test_only_cmake_starts_an_env_prefix(self):
source = Path.cwd() / "unit.cpp"
self.assertEqual(check_compile.syntax_arguments(["g++", "-E", "env", "-c", str(source)], Path.cwd(), source),The patch applies cleanly to both pinned snapshots. The additional test was run in its focused group; the full-suite totals above are for the existing tests. Scope: native Windows tool/CLI qualification and inspection of existing hosted logs. No local Linux/WSL, Clang-specific run, project build, GPU or title execution. AI-assisted: yes (Codex). |
…delimiter After --, the next argument is the command even when it contains =; taking -- as one more option would read compiler=tools/g++ as an assignment and refuse -c. Suggested by veosett in review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the Windows run. I added your test in |
What
In a build configured with
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache(the optional cache indocs/dev/BUILD.md),core/libs/prx/libSceAgcDriver/CMakeLists.txtgives every AGC execution test the launchercmake -E env CCACHE_SLOPPINESS=pch_defines,time_macros ccache, so their compile commands start withcmake -E env ….tools/check_compile.pytookcmakefor the compiler: it inserted-fsyntax-onlybefore-E, dropped-Eas a preprocessing option and ranwhich fails for every such source with
CMake Error: Unknown argument -include.This PR keeps a leading
cmake -E envprefix as it is and rewrites only the command after it, so the launcher's environment still applies. The prefix's options followcmake -E env [--unset=NAME] [--modify OPERATION] [NAME=VALUE]... [--] <command>as CMake 3.28 accepts them. Any other option before the command (CMake itself rejects-, for example) and a prefix without a command are rejected, as the tool does for options it does not model. The technical debt line about compiler wrappers is cut to what is still not covered.Tested
Linux Mint 22.3, GCC 13.3.0, CMake 3.28.3, Python 3.12.3, Release with ccache, on
mainbb04a4f1ea.CheckCompilePathSelectionTests.test_a_cmake_env_launcher_keeps_its_environment_and_the_compiler_command_is_rewrittenruns a recorded compiler through the realcmake -E env(withNAME=VALUEand--unset=) and checks the arguments and environment it receives; onmainit fails withCMake Error: Unknown argument -include.CheckCompileLauncherTestschecks the rewritten arguments for the prefix forms (including a Windowscmake.exepath and--modify,--), the rejections, and (added after @rooklz's and @veosett's reviews) that a compiler whose arguments start with-E envkeeps the ordinary rewrite and that a command path containing=after--stays the command.tools/tests/test_check_compile.py(57 tests, 2 skipped for Windows quoting as onmain),test_check_compile_modes.py(45) andtest_check_compile_preprocessor.py(6) pass; the 211 source-scanning ctest entries (conventions_*,public_headers*,check_compile*,check_main_sync,check_skips) pass.python3 tools/check_compile.py --build buildwithSampleMultisampleTarget.cpp,UnclampedNormalizedBlend.cpp,OptimizeOnFiber.cpp(all through the launcher) andcore/relinker/main.cppreports4 translation units compile; with a syntax error appended toUnclampedNormalizedBlend.cppit reports the compiler's error at that line and1 of 1 translation units did not compile.check_conventions.py,check_test_registration.pyandcheck_main_sync.pyare clean.tools/pr_overlap.py --branch: no overlap with the 11 PRs it compared; the 8 it could not compare (fix(agc): color compare emulation: review follow-up to #668 #907, feat(agc): retain and refresh sampled depth array storage #1368, feat(ngs2): add experimental I3DL2 reverb #1384, feat(agc): add experimental depth clear and copy recognition #1395, fix(avplayer): keep handed-out video frames until later frames are handed out #1601, feat(aot): discuss native ARM64 compiler architecture and integration #1835, fix(libkernel): keep the signal mask per thread #3986, feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021) edit other entries ofdocs/dev/TechnicalDebt.md, none the quick syntax check 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)🤖 Generated with Claude Code