Repository navigation
[beman-tidy] Implement cmake.use_find_package check - #348
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-80-cmake-use-find-package
branch
3 times, most recently
from
July 15, 2026 23:58
250df69 to
bf5eda7
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new Beman Standard check to enforce dependency consumption via find_package() (and to disallow submodules / FetchContent_Declare) along with representative test repositories and pytest coverage for dry-run behavior.
Changes:
- Introduces
cmake.use_find_packagecheck implementation (dry-run) in the CMake checks module. - Adds new pytest cases for valid/invalid repository layouts for the new check.
- Adds test fixture repositories (valid/invalid) containing
.gitmodulesandFetchContent_Declareexamples.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/lib/checks/beman_standard/cmake/test_cmake.py | Adds tests for CMakeUseFindPackageCheck valid/invalid behavior (dry-run) and a skipped fix-inplace test. |
| tests/lib/checks/beman_standard/cmake/data/valid/repo-exemplar-v2/infra/cmake/deps.cmake | Valid sample showing FetchContent_Declare under infra/ (intended exclusion). |
| tests/lib/checks/beman_standard/cmake/data/valid/repo-exemplar-v2/CMakeLists.txt | Valid repo root CMakeLists for exemplar v2. |
| tests/lib/checks/beman_standard/cmake/data/valid/repo-exemplar-v1/tests/beman/exemplar/CMakeLists.txt | Valid sample using find_package(GTest REQUIRED). |
| tests/lib/checks/beman_standard/cmake/data/valid/repo-exemplar-v1/examples/CMakeLists.txt | Valid sample examples CMakeLists without dependency fetching. |
| tests/lib/checks/beman_standard/cmake/data/valid/repo-exemplar-v1/CMakeLists.txt | Valid exemplar v1 project structure including tests/examples subdirs. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v4/examples/CMakeLists.txt | Invalid sample: FetchContent_Declare used under examples. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v4/CMakeLists.txt | Invalid exemplar v4 root driving examples subdir. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v3/tests/beman/exemplar/CMakeLists.txt | Invalid sample: FetchContent_Declare used under tests. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v3/CMakeLists.txt | Invalid exemplar v3 root driving tests subdir. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v2/CMakeLists.txt | Invalid sample: root FetchContent_Declare. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v1/CMakeLists.txt | Invalid exemplar v1 root paired with .gitmodules. |
| tests/lib/checks/beman_standard/cmake/data/invalid/repo-exemplar-v1/.gitmodules | Invalid sample: non-empty .gitmodules. |
| beman_tidy/lib/checks/beman_standard/cmake.py | Implements the new cmake.use_find_package check (dry-run) and a stub fix(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
neatudarius
force-pushed
the
implement/issue-80-cmake-use-find-package
branch
6 times, most recently
from
July 16, 2026 06:38
507e098 to
7e9fc81
Compare
neatudarius
force-pushed
the
implement/issue-80-cmake-use-find-package
branch
from
July 16, 2026 06:43
7e9fc81 to
945359d
Compare
…cmake-use-find-package # Conflicts: # tests/lib/checks/beman_standard/cmake/test_cmake.py
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The review found an issue that should be addressed before approval.
9 open issues
The wg21 exception depends on the repository, not the transport, but this regex accepts only HTTPS… · New Restricting detection toFetchContent_Declaremisses other ways of fetching dependency targets.… · NewFetchContent_Declareonly registers content details; by itself it neither fetches anything nor… · New Valid Git config permits a trailing comment after a URL, but_SUBMODULE_URLdoes not match that… · New This only searchestests/andexamples/below the root, so a commoninclude(cmake/deps.cmake)… · New The recursive scan bypasses the repository's ignore matcher, soignored_paths,.gitignore, and… · New Walking every CMake file undertests/also treats unrelated fixture projects as part of the… · New This excludes any directory namedinfra, not just the rootinfra/directory. Consequently, a… · New This makes any non-wg21 submodule fail thecmake.use_find_packagecheck, even when it contains… · New
5 resolved since last review
_cmake_files_to_check() currently inspects only CMakeLists.txt at the repo root and under tests/… _gitmodules_has_content() calls read_text() without handling I/O errors. If .gitmodules exists but… _has_fetch_content_declare() compares item.identifier to "FetchContent_Declare" without normalizing… The PR description says "Implements #80", but Issue #80 explicitly includes implementing both… This docstring says the "valid" repositories are "without ... FetchContent", but valid_repo_paths…
Review effort: Balanced
|
|
||
| # Known exception from repository.disallow_git_submodules: the mpark/wg21 | ||
| # paper framework is not a C++ dependency, so it is not fetched via CMake. | ||
| _ALLOWED_SUBMODULE_URL = re.compile(r"^https://github\.com/mpark/wg21(?:\.git)?/?$") |
Comment on lines
+388
to
+390
| hasattr(item, "identifier") | ||
| and item.identifier.lower() == "fetchcontent_declare" | ||
| for item in ast |
Comment on lines
+388
to
+390
| hasattr(item, "identifier") | ||
| and item.identifier.lower() == "fetchcontent_declare" | ||
| for item in ast |
Comment on lines
+411
to
+415
| urls = _SUBMODULE_URL.findall(content) | ||
| if not urls: | ||
| # Non-empty .gitmodules without a parsable url: treat it as a submodule. | ||
| return len(content.strip()) > 0 | ||
| return any(not _ALLOWED_SUBMODULE_URL.match(url) for url in urls) |
| for cmake_file in self.repo_path.glob("*.cmake"): | ||
| cmake_files.append(cmake_file) | ||
|
|
||
| for subdir in ("tests", "examples"): |
| subdir_path = self.repo_path / subdir | ||
| if not subdir_path.is_dir(): | ||
| continue | ||
| for cmake_file in subdir_path.rglob("*"): |
| subdir_path = self.repo_path / subdir | ||
| if not subdir_path.is_dir(): | ||
| continue | ||
| for cmake_file in subdir_path.rglob("*"): |
Comment on lines
+434
to
+435
| if "infra" in cmake_file.relative_to(self.repo_path).parts: | ||
| continue |
| return sorted(set(cmake_files)) | ||
|
|
||
| def check(self): | ||
| if self._has_disallowed_submodules(): |
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 #80