Repository navigation
[beman-tidy] Implement cmake.passive_targets check - #347
neatudarius wants to merge 6 commits into
Conversation
cffdc2f to
8b64446
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a new Beman Standard check cmake.passive_targets to detect disallowed CMake patterns that propagate compile requirements/definitions to dependent targets, along with new test coverage and supporting file-discovery utilities.
Changes:
- Added
CMakePassiveTargetsCheckto scan CMake content fortarget_compile_features(...)andtarget_compile_definitions(... PUBLIC|INTERFACE ...). - Added unit tests and new valid/invalid CMake test fixtures for
cmake.passive_targets. - Added a repository utility helper to enumerate CMake files (
CMakeLists.txt,*.cmake).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
beman_tidy/lib/checks/beman_standard/cmake.py |
Implements the cmake.passive_targets check and registers it in the Beman Standard checks registry. |
beman_tidy/lib/utils/file.py |
Adds get_cmake_files() to locate CMake files for repository-wide scanning. |
tests/lib/checks/beman_standard/cmake/test_cmake.py |
Adds tests for valid/invalid cmake.passive_targets behavior and a (skipped) fix-inplace test placeholder. |
tests/lib/checks/beman_standard/cmake/data/valid/passive_targets-v1.txt |
Adds a passing CMake fixture (no banned patterns). |
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-passive_targets-v1.txt |
Adds a failing fixture using target_compile_features(...). |
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-passive_targets-v2.txt |
Adds a failing fixture using target_compile_definitions(... PUBLIC ...). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def fix(self): | ||
| self.log( | ||
| "Please remove target_compile_features and target_compile_definitions with " | ||
| "PUBLIC or INTERFACE visibility from CMake files. " | ||
| "See https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmakepassive_targets " |
There was a problem hiding this comment.
Not changed: no cmake.* check implements fix-inplace, and removing target_compile_features or PUBLIC definitions needs a per-library redesign (e.g. a generated config.hpp). This PR is dry-run only, and #74 stays open for fix mode.
51e2b84 to
40c26e8
Compare
40c26e8 to
4186034
Compare
…cmake-passive-targets # Conflicts: # tests/lib/checks/beman_standard/cmake/test_cmake.py
main replaced get_ignores/_is_ignored with the gitignore-aware IgnoreMatcher (bemanproject#366); without this the merged branch fails to import.
…missing Previously a missing file silently fell back to scanning the whole repository.
There was a problem hiding this comment.
🟡 Changes recommended
Case-sensitive, raw-text CMake matching causes false positives and false negatives when handling command names, comments, quoted arguments, and visibility scopes.
3 open issues
2 resolved since last review
Review effort: Balanced
| _TARGET_COMPILE_FEATURES_RE = re.compile(r"target_compile_features\s*\(") | ||
| _TARGET_COMPILE_DEFINITIONS_RE = re.compile( | ||
| r"target_compile_definitions\s*\([^)]*\b(PUBLIC|INTERFACE)\b" | ||
| ) |
| r"target_compile_definitions\s*\([^)]*\b(PUBLIC|INTERFACE)\b" | ||
| ) | ||
| _COMMENT_RE = re.compile(r"#[^\n]*") |
…cmake-passive-targets
…arser Matches command names case-insensitively, skips bracket comments and look-alike commands, finds PUBLIC/INTERFACE after values with parentheses, reports file:line and fails on files it cannot parse.


Implements #74