Skip to content

[beman-tidy] Implement cmake.implicit_defaults - #360

Draft
neatudarius wants to merge 6 commits into
bemanproject:mainfrom
neatudarius:issue-178
Draft

neatudarius wants to merge 6 commits into
bemanproject:mainfrom
neatudarius:issue-178

Conversation

@neatudarius

@neatudarius neatudarius commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Implements #178

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

Adds initial support for the Beman Standard rule cmake.implicit_defaults by introducing a new CMake check and accompanying test vectors, aiming to catch install(TARGETS ...) usage that explicitly enumerates DESTINATION arguments instead of relying on CMake defaults.

Changes:

  • Introduces CMakeImplicitDefaultsCheck to flag install(TARGETS ...) blocks containing DESTINATION.
  • Adds unit tests for valid/invalid cases of the new check.
  • Adds new CMake input fixtures representing compliant and non-compliant install(TARGETS ...) blocks.

Reviewed changes

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

Show a summary per file
File Description
beman_tidy/lib/checks/beman_standard/cmake.py Adds the new cmake.implicit_defaults check implementation (currently check-only; fix is a stub).
tests/lib/checks/beman_standard/cmake/test_cmake.py Registers new tests for cmake.implicit_defaults (dry-run behavior).
tests/lib/checks/beman_standard/cmake/data/valid/valid-implicit_defaults-v1.txt Adds a compliant install(TARGETS ...) fixture with no explicit DESTINATION.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-implicit_defaults-v1.txt Adds a non-compliant fixture with multiple explicit DESTINATION clauses.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-implicit_defaults-v2.txt Adds a non-compliant fixture with explicit DESTINATION on FILE_SET HEADERS.

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

# Conflicts:
#	beman_tidy/lib/checks/beman_standard/cmake.py
#	tests/lib/checks/beman_standard/cmake/test_cmake.py
Explicit DESTINATION is required for C++ module file sets and BMIs, so the check now flags only values equal to CMake's built-in default.

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.



@register_beman_standard_check("cmake.implicit_defaults")
class CMakeImplicitDefaultsCheck(CMakeBaseCheck):
Comment on lines +483 to +485
_BINDIR = frozenset({"${CMAKE_INSTALL_BINDIR}", "bin"})
_LIBDIR = frozenset({"${CMAKE_INSTALL_LIBDIR}", "lib"})
_INCLUDEDIR = frozenset({"${CMAKE_INSTALL_INCLUDEDIR}", "include"})
Comment on lines +495 to +496
# A DESTINATION given before any artifact kind applies to all of them.
None: _BINDIR | _LIBDIR | _INCLUDEDIR,
if arg == "FILE_SET" and index + 1 < len(args):
# Only the conventional HEADERS set has a known type here.
index += 1
kind = f"FILE_SET {args[index]}"
Comment on lines +543 to +544
if destination in self._DEFAULT_DESTINATIONS.get(kind, ()):
found.append((kind or "TARGETS", destination))
def check(self):
found = []
for command in self.get_cmake_parse_raw():
if getattr(command, "identifier", "").lower() != "install":
"CMake's default destination. "
"See https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmakeimplicit_defaults for more information."
)
return False
Remove default DESTINATION arguments in place, ignore comments inside install(), and match a top-level DESTINATION against the target kind.

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