Skip to content

[beman-tidy] Implement cmake.target_names check - #326

Merged
vickgoodman merged 3 commits into
bemanproject:mainfrom
vickgoodman:beman.tidy-implement-cmake.target_names
Jul 15, 2026
Merged

vickgoodman merged 3 commits into
bemanproject:mainfrom
vickgoodman:beman.tidy-implement-cmake.target_names

Conversation

@vickgoodman

@vickgoodman vickgoodman commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

@vickgoodman
vickgoodman marked this pull request as ready for review July 6, 2026 22:00

@neatudarius neatudarius left a comment •

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.

Thanks for implementing cmake.target_names — the logic correctly matches the standard and CI is green, so I'm approving to unblock.

That said, please address the feedback below before merging — especially point 1, which leaves the happy path untested.

1. (Medium) The "valid" test never exercises the positive path the rule is about.
tests/.../cmake/data/valid/CMakeLists-v1.txt only contains:

add_library(beman.exemplar INTERFACE)
add_library(beman::exemplar ALIAS beman.exemplar)

Both are skipped by the library_name/library_alias guards, so the branch that validates the prefix (target_name.startswith(f"{self.library_name}.")) is never executed in the passing test — it passes vacuously. Since correctly-prefixed example/test targets are the whole point of the rule, a regression in the startswith branch would not be caught. Please add a valid fixture containing a properly-prefixed target, e.g. add_executable(beman.exemplar.examples.basic).

2. (Low, scope) The check only sees the top-level CMakeLists.txt.
get_cmake_target_names() uses parse_raw, which does not resolve add_subdirectory. In real Beman repos the example/test targets this rule governs typically live in subdirectory CMakeLists files added via add_subdirectory(...), so in practice the check will rarely see the targets it's meant to police and will silently pass. This is consistent with the other cmake.* checks and arguably out of scope here — but worth a TODO/comment or a follow-up issue noting the limitation.

3. (Low) Misleading message for misnamed library targets.
In check(), an add_library first-arg that isn't exactly library_name/library_alias is reported as "Invalid CMake target name ... expected prefix: '<library_name>.'". For invalid-target_names-v1.txt (add_library(beman.foobar)) and -v3.txt (add_library(beman.exemplar2 ...)), the offending line is really the library target itself, which is the domain of cmake.library_name. Not a bug (still returns False), but the diagnostic conflates two rules. Invalid fixtures for this check would be more on-point using add_executable example/test targets with a bad prefix (v2 already does this well).

@vickgoodman

Copy link
Copy Markdown
Contributor Author
  1. Done
  2. Added a note and TODO to cmake.targe_names check
  3. Kept the code as-is

@vickgoodman

Copy link
Copy Markdown
Contributor Author

@neatudarius
Same failed workflows as mentioned here: #325 (comment)

@vickgoodman
vickgoodman merged commit fd352c7 into bemanproject:main Jul 15, 2026
10 checks passed
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