Skip to content

[beman-tidy] Implement cmake.use_find_package check - #348

Draft
neatudarius wants to merge 5 commits into
bemanproject:mainfrom
neatudarius:implement/issue-80-cmake-use-find-package
Draft

neatudarius wants to merge 5 commits into
bemanproject:mainfrom
neatudarius:implement/issue-80-cmake-use-find-package

Conversation

@neatudarius

@neatudarius neatudarius commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Implements #80

@neatudarius
neatudarius force-pushed the implement/issue-80-cmake-use-find-package branch 3 times, most recently from 250df69 to bf5eda7 Compare July 15, 2026 23:58
@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

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_package check 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 .gitmodules and FetchContent_Declare examples.

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
neatudarius force-pushed the implement/issue-80-cmake-use-find-package branch 6 times, most recently from 507e098 to 7e9fc81 Compare July 16, 2026 06:38
@neatudarius
neatudarius force-pushed the implement/issue-80-cmake-use-find-package branch from 7e9fc81 to 945359d Compare July 16, 2026 06:43

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

The review found an issue that should be addressed before approval.

9 open issues
5 resolved since last review

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

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