Skip to content

fix(tools): check sources whose compile command runs through cmake -E env - #12971

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
GiannisG1:fix/check-compile-cmake-env-wrapper
Oct 30, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
GiannisG1:fix/check-compile-cmake-env-wrapper

Conversation

@GiannisG1

@GiannisG1 GiannisG1 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

In a build configured with -DCMAKE_CXX_COMPILER_LAUNCHER=ccache (the optional cache in docs/dev/BUILD.md), core/libs/prx/libSceAgcDriver/CMakeLists.txt gives every AGC execution test the launcher cmake -E env CCACHE_SLOPPINESS=pch_defines,time_macros ccache, so their compile commands start with cmake -E env …. tools/check_compile.py took cmake for the compiler: it inserted -fsyntax-only before -E, dropped -E as a preprocessing option and ran

cmake -fsyntax-only env CCACHE_SLOPPINESS=pch_defines,time_macros ccache /usr/bin/g++ … -include …

which fails for every such source with CMake Error: Unknown argument -include.

This PR keeps a leading cmake -E env prefix as it is and rewrites only the command after it, so the launcher's environment still applies. The prefix's options follow cmake -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 main bb04a4f1ea.

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 specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

… 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>
@adriadam10 adriadam10 self-assigned this Oct 29, 2026

@rooklz rooklz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 151625b on macOS arm64, Python 3.13, CMake 4.3.1, against main bb04a4f.

Approve.

  • git merge-tree against main, git diff --check and check_conventions.py --base upstream/main are all clean.
  • tools/tests/test_check_compile.py passes 55 tests (2 skipped), test_check_compile_modes.py 45 (5 skipped) and test_check_compile_preprocessor.py 6 (1 skipped). The real cmake -E env row ran here: cmake is on PATH and the row was not skipped.
  • Negative control: with main's tools/check_compile.py and 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 --unset and --modify=… are all rejected as "unknown option".
    • A bare --modify gives "missing a parameter".
    • A=1 and A=1 -- give "no command given".
    • CMake takes =x as an assignment. After --, a B=2 is run as the command, which matches break on --.
  • Other shapes I tried also behave correctly. A nested cmake -E env cmake -E env cc … recurses properly, and an upper-case CMAKE.EXE is recognised. A ccache 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>
@GiannisG1

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the mutant run. I added your row in 4ebd5c3a11 as CheckCompileLauncherTests.test_only_cmake_starts_an_env_prefix: without the stem check it raises unsupported cmake -E env option -c, and with the PR it gets the ordinary rewrite. The three suites pass (56/45/6), and so do the 210 source-scanning ctest entries.

@github-actions

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 907 docs/dev/TechnicalDebt.md
PR 1368 docs/dev/TechnicalDebt.md
PR 1384 docs/dev/TechnicalDebt.md
PR 1395 docs/dev/TechnicalDebt.md
PR 1601 docs/dev/TechnicalDebt.md
PR 1835 docs/dev/TechnicalDebt.md
PR 3986 docs/dev/TechnicalDebt.md
PR 5021 docs/dev/TechnicalDebt.md

@veosett

veosett commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Supplemental Windows qualification of 4ebd5c3a118f190083c56168d32fe740532eba63 against observed main d820fef1827f27247cd28da7b4eec7891904bae5. The merge is clean (tree bda4e35a722e16847cbaa82afadd4baf1e55b315). CPython 3.12.14, CMake 4.3.1, WinLibs GCC 15.2.0, Git 2.45.1.windows.1. No production defect found in this scope.

  • The three unmodified suites (test_check_compile, test_check_compile_modes, test_check_compile_preprocessor) run 107 methods: 87 passed, 20 skipped, zero failures/errors. The skips concern unavailable Clang, unavailable symlink privileges, and one ANSI-code-page case. The real CMake launcher case and the Windows paths/quoted-defines test execute successfully.
  • The production tool and all three test files are byte-identical between the pristine PR and its merge with the pinned main. The full run above uses the pristine PR; I did not repeat an identical full run on the merged snapshot.
  • 36 additional CLI checks pass using real CMake from a path containing spaces, under both arguments and Windows-quoted command compilation-database entries. Twelve recorder checks verify exact compiler arguments and environment values across assignments, --unset, --modify, --, nested launchers, embedded quotes and trailing backslashes. Twenty-four GCC syntax-only checks cover valid/invalid tiny C sources, forced includes with spaces, preserved existing object/dependency files and absence of new build outputs. No project build is involved.
  • Negative control: pinned main's production with the PR's four focused launcher methods produces nine assertion failures and zero errors/skips. The ordinary-compiler -E env control passes. With main's CLI, all six assignment-prefix recorder/native checks fail their intended behavior checks, reproducing the launcher problem.
  • Hosted Linux and Windows logs explicitly identify 4ebd5c3a118. The registered real-CMake launcher target passes in 0.22 s / 0.71 s, and both complete job logs report zero failed tests. Those jobs do not contain the additional test below.

Optional test-only follow-up for the -- mutation survivor noted in rooklz's earlier review: a command path can contain =, so it must stop being interpreted as an environment assignment after the delimiter. The current implementation handles it correctly. Replacing the delimiter's break with continue still passes the existing four focused launcher methods, but the proposed test exposes a behavioral ValueError: unsupported cmake -E env option -c from launcher_prefix. The five-method group passes on the actual PR with zero failures/errors/skips.

I also confirmed the corresponding valid shape with real CMake: an outer cmake -E env -- launches another CMake executable from a directory containing =, then a recording child receives the rewritten syntax-only arguments. It exits 0 and preserves the expected environment. The temporary copies of the CMake executable were removed after qualification.

--- 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>
@GiannisG1

Copy link
Copy Markdown
Contributor Author

Thanks for the Windows run. I added your test in b3b4037585 as CheckCompileLauncherTests.test_env_delimiter_preserves_a_command_path_containing_equals: with the delimiter's break turned into continue it raises unsupported cmake -E env option -c, and with the PR it passes. The three suites pass (57/45/6), and so do the 211 source-scanning ctest entries; the branch still merges cleanly onto current main.

@github-actions github-actions Bot added the docs label Oct 30, 2026
@adriadam10
adriadam10 merged commit e628c03 into boykopovar:main Oct 30, 2026
13 of 14 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked the two new tests (test_only_cmake_starts_an_env_prefix, test_env_delimiter_preserves_a_command_path_containing_equals): production code is unchanged and both pin the cases they name; Windows run by @veosett and macOS negative control by @rooklz also cover it; merged.

@GiannisG1
GiannisG1 deleted the fix/check-compile-cmake-env-wrapper branch November 19, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants