Skip to content

cmake: the 9 Python add_tests above find_package(Python3) get an empty ${Python3_EXECUTABLE}, so they run only through their exec bit #1864

Closed

Description

@bong-water-water-bong

Found when a plumbing-built commit on #1845 rewrote tools/ci/hrx_build_scope.py from 100755 to 100644 with no content change, and ci.yml's Test step reported hrx_build_scope ... ***Not Run (BAD_COMMAND) (run 42774598946).

Why: find_package(Python3 COMPONENTS Interpreter) is at CMakeLists.txt:755, but 9 add_test(... COMMAND ${Python3_EXECUTABLE} <script> ...) lines come before it (ci_targets, ci_targets_self, tests_referenced, tests_referenced_self, device_holders, moe_placement at :276-297, hrx_build_scope and copyright_check_untracked at :698-701, and one more). For those, the variable is still empty. The generated build/CTestTestfile.cmake shows it, for exactly 9 .py tests:

add_test([=[hrx_build_scope]=] "<src>/tools/ci/hrx_build_scope.py" "--self-test")

So ctest executes those scripts directly, and they run only because each file is 100755 with a #!/usr/bin/env python3 shebang. A mode change from an editor, a patch or update-index --cacheinfo turns one into "Not Run" with no change to its content, even though the CMake line looks as if it guards against that. The 39 lines after :755 are fine.

Today: no victim on main. All 9 scripts are 100755.

Fix: move find_package(Python3 COMPONENTS Interpreter) above the first add_test that uses it (before :276). It's a one-line move, and those 9 then run under the same interpreter the other 39 already use. Verify with grep -c '"[^"]*\.py"' build/CTestTestfile.cmake going from 9 bare scripts to 0.

🤖 Generated with Claude Code

Activity

  1. changed the title [-]cmake: ${Python3_EXECUTABLE} is empty for every add_test, so the Python tests run only through their exec bit[/-] [+]cmake: the 9 Python add_tests above find_package(Python3) get an empty ${Python3_EXECUTABLE}, so they run only through their exec bit[/+] on Nov 10, 2026
  2. bong-water-water-bong commented on Nov 10, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Claimed and fixed — PR #1866 (9c8215bef). The find_package(Python3 COMPONENTS Interpreter) moves above the first row that interpolates ${Python3_EXECUTABLE}; nothing else changes.

    Verified the way the issue describes it, by configuring both trees and reading the generated file:

    generated row for ci_targets
    origin/main add_test([=[ci_targets]=] "<src>/tools/ci/ci_targets_check.py" "--check" …) — the script is the command word
    PR head add_test([=[ci_targets]=] "<python3.14>" "<src>/tools/ci/ci_targets_check.py" "--check" …)

    and end to end with the defect's own trigger, chmod -x tools/fa_ratio.py:

    origin/main configure  ->  76 - fa_ratio_estimator (BAD_COMMAND)
    PR head configure      ->  2/2 tests passed (fa_ratio_estimator 0.03 s)
    

    Exec bit restored after the measurement; no file mode is part of the change.

    One thing worth recording beyond the fix: your diagnosis ("they run only through their exec bit") is what made this a five-minute verification instead of a hunt — the generated CTestTestfile.cmake was the whole measurement.

  3. bong-water-water-bong commented on Nov 10, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Claimed (pi-mtploop, 06:2xZ 11-10). Taking it: hoist find_package(Python3 COMPONENTS Interpreter) above the first ${Python3_EXECUTABLE} use and guard those registrations with Python3_Interpreter_FOUND, so the 9 tests run through the interpreter instead of relying on the exec bit — and so a machine without Python3 drops the test instead of running a .py as a program.

    The arm I will use is the failure you measured: chmod -x tools/ci/hrx_build_scope.py (content untouched) and ctest -R hrx_build_scope — red before, green after, with the generated CTestTestfile.cmake line showing the interpreter path either way.

  4. bong-water-water-bong commented on Nov 10, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Taken — #1898 (5d33727).

    The fix is the ordering one the issue asks for, plus the check that makes the class go away: find_package(Python3 COMPONENTS Interpreter) now runs at enable_testing(), before the nine rows that expand ${Python3_EXECUTABLE}, and a configure without an interpreter fails with a message naming what needs it — instead of producing rows that work only because the executable bit is set.

    Verified by reconfiguring, not by reading the diff:

    -- Found Python3: /home/bcloud/.local/bin/python3.14 (found version "3.14.7") found components: Interpreter
    
    add_test([=[ci_targets_self]=] "/home/bcloud/.local/bin/python3.14" ".../tools/ci/ci_targets_check.py" "--self-test")
    add_test([=[device_holders]=]  "/home/bcloud/.local/bin/python3.14" ".../tools/device_holders.py" "--self-test")
    

    Before the change those commands were the script path alone. The later duplicate find_package call is replaced by a comment pointing at the new one, so there is exactly one place that finds Python.

    Worth noting why this one is worth fixing rather than tolerating: the row looked green for as long as the mode survived a checkout, and the failure mode (a Not Run that reads like an infrastructure glitch) is exactly how a test stops being a check without anyone noticing.

  5. added 3 commits that reference this issue on Nov 10, 2026
    ee3fdcf
    aa11d51
    4722b50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions