Repository navigation
[beman-tidy] Implement cmake.implicit_defaults - #360
Draft
neatudarius wants to merge 6 commits into
Draft
neatudarius wants to merge 6 commits into
neatudarius wants to merge 6 commits into
Conversation
Contributor
There was a problem hiding this comment.
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
CMakeImplicitDefaultsCheckto flaginstall(TARGETS ...)blocks containingDESTINATION. - 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.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The review found an issue that should be addressed before approval.
7 open issues
InheritingCMakeBaseChecklimits this check to the rootCMakeLists.txt, although this… · New The literal paths are not always CMake's defaults:CMAKE_INSTALL_LIBDIR,CMAKE_INSTALL_BINDIR,… · New A generic destination is not equivalent to every artifact's default: for example, `install(TARGETS… · New Header file sets need not be namedHEADERS: `target_sources(lib PUBLIC FILE_SET api TYPE HEADERS… · New This comparison ignores a preceding genericDESTINATION, which is inherited by artifact kinds… · New The recommendation covers CMake commands generally, but this check ignores every command other than… · New The linked issue explicitly requests fix-inplace support, but this method only logs and always… · New
5 resolved since last review
PR metadata says this “Implements #178”, but #178 explicitly calls out implementing both check()… This skipped fix-inplace test is missing the standard docstring used by the other skipped… These new tests don’t follow the established pattern in this file where each test function has a… These new tests don’t follow the established pattern in this file where each test function has a… _install_targets_blocks_with_explicit_destinations() builds and returns a list of full install(...)…
Review effort: Balanced
|
|
||
|
|
||
| @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
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 #178