Skip to content

[beman-tidy] Implement cmake.project_name#313

Draft
vickgoodman wants to merge 4 commits into
bemanproject:mainfrom
vickgoodman:beman-tidy-implement-check-cmake.project_name
Draft

[beman-tidy] Implement cmake.project_name#313
vickgoodman wants to merge 4 commits into
bemanproject:mainfrom
vickgoodman:beman-tidy-implement-check-cmake.project_name

Conversation

@vickgoodman
Copy link
Copy Markdown
Contributor

@vickgoodman vickgoodman commented May 7, 2026

Implement:

Comment on lines +65 to +66
if item.identifier == "project":
cmake_project_name = item.args[0].value
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if item.identifier == "project":
cmake_project_name = item.args[0].value
if item.identifier == "project":
if item.args:
cmake_project_name = item.args[0].value

?

Same for get_cmake_library_name

Copy link
Copy Markdown
Member

@neatudarius neatudarius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

invalid_prefix = f"{test_data_prefix}/invalid"



Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@@ -1,2 +1,12 @@
# missing 'project' from next line
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer to keep the test cases not overlapping,

Rename existing 3 files to invalid-library_name-v1/2/3.txt, and add invalid-project_name-v1/2/3.txt

Let's keep testcases as simple as possible!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 for validating the project() name in CMakeLists.txt (cmake.project_name) and extends the CMake test suite/data to cover valid/invalid cases.

Changes:

  • Added CMakeProjectNameCheck plus shared AST helper for extracting the CMake project name.
  • Made CMake parsing helpers accept a skip_comments parameter (defaulting to current behavior).
  • Added/updated pytest coverage and CMakeLists test fixtures for cmake.project_name.

Reviewed changes

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

Show a summary per file
File Description
beman_tidy/lib/checks/beman_standard/cmake.py Introduces cmake.project_name check and project-name extraction helper; adjusts parsing helper signatures.
tests/lib/checks/beman_standard/cmake/test_cmake.py Adds tests for the new check and updates existing test comments.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-CMakeLists-v1.txt Updates invalid fixture to represent “missing project()” scenario.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-CMakeLists-v2.txt Updates invalid fixture to include an explicitly wrong project() name.
tests/lib/checks/beman_standard/cmake/data/invalid/invalid-CMakeLists-v3.txt Updates invalid fixture to include an explicitly wrong project() name.

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

Comment on lines +27 to +31
valid_cmake_paths = [
# CMakeLists.txt from beman.exemplar
Path(f"{valid_prefix}/CMakeLists-v1.txt")
]

Comment on lines +45 to +50
invalid_cmake_paths = [
# CMakeLists.txt missing project name
Path(f"{invalid_prefix}/invalid-CMakeLists-v1.txt"),
# CMakeLists.txt with invalid library name
Path(f"{invalid_prefix}/invalid-CMakeLists-v2.txt"),
# CMakeLists.txt with another invalid library name
Comment on lines +48 to +50
# CMakeLists.txt with invalid library name
Path(f"{invalid_prefix}/invalid-CMakeLists-v2.txt"),
# CMakeLists.txt with another invalid library name

for item in ast:
if item.identifier == "project":
cmake_project_name = item.args[0].value
"Please update the CMakeLists.txt file so that the CMake project name is identical to the Beman library name. "
"See https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmakeproject_name for more information."
)
return True
"Please update the CMakeLists.txt file so that the CMake library target's name is identical to the Beman library name. "
"See https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmakelibrary_name for more information."
)
return True

if cmake_project_name is None:
self.log("CMake project name not found. "
"Please update the CMakeLists.txt file according to the Beman Standard. "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Please update the CMakeLists.txt file according to the Beman Standard. "
f"Expected project name: '{self.library_name}'"

?

and in the next if can be Invalid CMake project name - got: {cmake_project_name} expected: {self.library_name}.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 8 comments.


if cmake_project_name is None:
self.log("CMake project name not found. "
f"Expected project name: '{self.library_name}'"
Comment on lines 123 to 126
cmake_library_name2 = self.get_cmake_library_name(ast)

self.log(f"{cmake_library_name} -> {cmake_library_name2}")


if cmake_library_name is None:
self.log("CMake library target name not found. "
f"Expected library target name: '{self.library_name}'"
Comment on lines +104 to +109
def fix(self):
self.log(
"Please update the CMakeLists.txt file so that the CMake project name is identical to the Beman project name. "
"See https://github.com/bemanproject/beman/blob/main/docs/beman_standard.md#cmakeproject_name for more information."
)
return False
# Actual tested checks.
from beman_tidy.lib.checks.beman_standard.cmake import (
CMakeProjectNameCheck,
CMakeLibraryNameCheck
Comment on lines +26 to +29
valid_cmake_paths = [
# CMakeLists.txt from beman.exemplar
Path(f"{valid_prefix}/CMakeLists-v1.txt")
]
Comment on lines +44 to +51
invalid_cmake_paths = [
# CMakeLists.txt missing project name
Path(f"{invalid_prefix}/invalid-project_name-v1.txt"),
# CMakeLists.txt with invalid project name
Path(f"{invalid_prefix}/invalid-project_name-v2.txt"),
# CMakeLists.txt with another invalid project name
Path(f"{invalid_prefix}/invalid-project_name-v3.txt")
]
Comment on lines +96 to +98
# CMakeLists.txt with invalid library target name
Path(f"{invalid_prefix}/invalid-library_name-v2.txt"),
# CMakeLists.txt with another invalid library target name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants