Skip to content

[beman-tidy] Implement cmake.passive_targets check - #347

Draft
neatudarius wants to merge 6 commits into
bemanproject:mainfrom
neatudarius:implement/issue-74-cmake-passive-targets
Draft

neatudarius wants to merge 6 commits into
bemanproject:mainfrom
neatudarius:implement/issue-74-cmake-passive-targets

Conversation

@neatudarius

@neatudarius neatudarius commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Implements #74

@neatudarius
neatudarius force-pushed the implement/issue-74-cmake-passive-targets branch 3 times, most recently from cffdc2f to 8b64446 Compare July 15, 2026 23:48
@neatudarius
neatudarius requested a review from Copilot July 16, 2026 00:02

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_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 CMakePassiveTargetsCheck to scan CMake content for target_compile_features(...) and target_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.

Comment on lines +361 to +365
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 "

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

@neatudarius
neatudarius force-pushed the implement/issue-74-cmake-passive-targets branch 3 times, most recently from 51e2b84 to 40c26e8 Compare July 16, 2026 06:38
@neatudarius
neatudarius force-pushed the implement/issue-74-cmake-passive-targets branch from 40c26e8 to 4186034 Compare July 16, 2026 06:43
…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.

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.

🟡 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

Comment on lines +385 to +388
_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"
)
Comment on lines +387 to +389
r"target_compile_definitions\s*\([^)]*\b(PUBLIC|INTERFACE)\b"
)
_COMMENT_RE = re.compile(r"#[^\n]*")
…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.

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