Repository navigation
[beman-tidy] Implement cmake.passive_projects check - #345
Draft
neatudarius wants to merge 5 commits into
Draft
neatudarius wants to merge 5 commits into
neatudarius wants to merge 5 commits into
Conversation
neatudarius
force-pushed
the
implement/issue-78-cmake-passive-projects
branch
3 times, most recently
from
July 15, 2026 23:58
c9fc10a to
33975f7
Compare
neatudarius
force-pushed
the
implement/issue-78-cmake-passive-projects
branch
from
July 16, 2026 00:05
33975f7 to
cd54b98
Compare
Contributor
There was a problem hiding this comment.
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
CMakePassiveProjectsCheckand 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 |
Member
Author
neatudarius
force-pushed
the
implement/issue-78-cmake-passive-projects
branch
6 times, most recently
from
July 16, 2026 06:38
07eda58 to
2d9b1ab
Compare
neatudarius
force-pushed
the
implement/issue-78-cmake-passive-projects
branch
from
July 16, 2026 06:43
2d9b1ab to
51cbff3
Compare
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/.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The review found an issue that should be addressed before approval.
5 open issues
Configuration-specific C++ flags are not checked · New Toolchain filename exemption skips project-included helpers · New Case-insensitive matching misclassifies CMake variable guards · New CMake parse failures are silently treated as passing · New PR description says this implements issue #78, which explicitly calls out implementing a fix for…
5 resolved since last review
Issue #78 explicitly calls for implementing a fix for fix-inplace mode, but this test asserts that… The check unconditionally addsinfra/to the ignore list, which can hide real violations in… CMake commands are case-insensitive, but these regexes only match lowercaseset(...). This can… This docstring says the fixture has no forbidden project-level flags, butpassive_projects-v3… Unused import:Pathis imported but never referenced in this module, which will trip linters and…
Review effort: Balanced
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 |
…cmake-passive-projects
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Implements #78