Skip to content

[beman-tidy] Implement cmake.passive_projects check - #345

Draft
neatudarius wants to merge 5 commits into
bemanproject:mainfrom
neatudarius:implement/issue-78-cmake-passive-projects
Draft

neatudarius wants to merge 5 commits into
bemanproject:mainfrom
neatudarius:implement/issue-78-cmake-passive-projects

Conversation

@neatudarius

@neatudarius neatudarius commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Implements #78

@neatudarius neatudarius changed the title Implement cmake.passive_projects check [beman-tidy] Implement cmake.passive_projects check Jul 15, 2026
@neatudarius
neatudarius force-pushed the implement/issue-78-cmake-passive-projects branch 3 times, most recently from c9fc10a to 33975f7 Compare July 15, 2026 23:58
@neatudarius
neatudarius requested a review from Copilot July 16, 2026 00:02
@neatudarius
neatudarius force-pushed the implement/issue-78-cmake-passive-projects branch from 33975f7 to cd54b98 Compare July 16, 2026 00:05

Copilot AI 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.

Pull request overview

This PR adds a new Beman Standard check, cmake.passive_projects, intended to detect CMake code that overrides user-provided compilation settings (e.g., CMAKE_CXX_FLAGS, CMAKE_CXX_STANDARD). It also introduces test coverage and fixture repositories to validate the new check.

Changes:

  • Added CMakePassiveProjectsCheck and supporting CMake file discovery helper (get_cmake_files).
  • Added pytest coverage for valid/invalid passive-projects scenarios and new fixture directories.
  • Added representative CMake fixtures covering multiple layout variants (v1/v2/v3) and invalid cases.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
beman_tidy/lib/checks/beman_standard/cmake.py Adds the new cmake.passive_projects check implementation and registers it.
beman_tidy/lib/utils/file.py Adds get_cmake_files() to enumerate CMakeLists.txt and *.cmake files.
tests/lib/checks/beman_standard/cmake/test_cmake.py Adds tests for valid/invalid cmake.passive_projects behavior and a fix-inplace expectation.
tests/lib/checks/beman_standard/cmake/data/valid/passive_projects-v1/CMakeLists.txt New “valid” fixture (v1 format) for passive projects.
tests/lib/checks/beman_standard/cmake/data/valid/passive_projects-v2/CMakeLists.txt New “valid” fixture (v2 format) for passive projects.
tests/lib/checks/beman_standard/cmake/data/valid/passive_projects-v3/CMakeLists.txt New “valid” fixture (v3 format) for passive projects.
tests/lib/checks/beman_standard/cmake/data/valid/passive_projects-v3/infra/cmake/toolchain.cmake Additional “valid” fixture file used by the v3 layout.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-passive_projects-v1/CMakeLists.txt New “invalid” fixture that sets CMAKE_CXX_STANDARD.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-passive_projects-v2/CMakeLists.txt New “invalid” fixture that sets CMAKE_CXX_FLAGS.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-passive_projects-v3/CMakeLists.txt New “invalid” fixture that sets CMAKE_CXX_STANDARD_REQUIRED.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +344 to +351
def fix(self):
self.log(
"Please remove set(CMAKE_CXX_FLAGS), set(CMAKE_CXX_STANDARD), and "
"set(CMAKE_CXX_STANDARD_REQUIRED) from CMake files. "
"See https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmakepassive_projects "
"for more information."
)
return False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changed: no cmake.* check implements fix(), and removing these settings automatically can break builds. fix() logs guidance on using presets or toolchains instead. The PR says 'Implements #78', so #78 stays open for fix mode.

@neatudarius
neatudarius force-pushed the implement/issue-78-cmake-passive-projects branch 6 times, most recently from 07eda58 to 2d9b1ab Compare July 16, 2026 06:38
@neatudarius
neatudarius force-pushed the implement/issue-78-cmake-passive-projects branch from 2d9b1ab to 51cbff3 Compare July 16, 2026 06:43
Keep both in test_cmake.py: main's skip_tests/skip_examples plus the
passive_projects tests. Port get_cmake_files and the check to main's
IgnoreMatcher (get_ignores was removed on main).
Parse CMake files instead of regex matching. Skip toolchain files and the
files they include, and set() calls guarded by if(NOT DEFINED <var>).
Report file:line. Exempt toolchains by name instead of all of infra/.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Comment on lines +387 to +391
_FORBIDDEN_VARIABLES = (
"CMAKE_CXX_FLAGS",
"CMAKE_CXX_STANDARD",
"CMAKE_CXX_STANDARD_REQUIRED",
)
files they include, transitively.
"""
known = set(cmake_files)
toolchains = {p for p in cmake_files if self._TOOLCHAIN_NAME_RE.search(p.name)}
"""
True for if(NOT DEFINED <variable>), which only sets a default.
"""
values = [arg.value.upper() for arg in if_args or []]
Comment on lines +478 to +485
trees = {}
for rel_path in cmake_files:
tree = self._parse(rel_path)
if tree is not None:
trees[rel_path] = tree
toolchains = self._get_toolchain_files(cmake_files, trees)

all_passed = True
Also report CMAKE_CXX_FLAGS_<CONFIG>, CMAKE_CXX_EXTENSIONS and
string()/list() appends, set() inside function bodies and CACHE ... FORCE.
Don't report toolchains named in CMake presets, files they include
relative to the source dir, if(NOT <var>) defaults or CACHE without FORCE.
Skip unparseable files. Move the check to its place in the rule order.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants