Skip to content

Conversation

@davidlion
Copy link
Member

@davidlion davidlion commented Aug 4, 2025

Description

Depends on #125.

This PR adds the tool, gersemi, to link CMake files through tasks and in CI.
To pass CI it applies the refactoring done by gersemi.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

gersemi passing in CI and locally. Existing CI still passing.

Summary by CodeRabbit

  • New Features

    • Introduced CMake linting capabilities to the linting framework, including dedicated check and fix tasks.
    • Added configuration for the gersemi linter.
  • Chores

    • Added the gersemi package to linting dependencies.
    • Updated linting taskfiles to support CMake linting.
  • Style

    • Reformatted all CMakeLists.txt files for improved readability and consistent style; no changes to build logic.

@davidlion davidlion requested a review from a team as a code owner August 4, 2025 15:10
@coderabbitai
Copy link

coderabbitai bot commented Aug 4, 2025

Walkthrough

This update introduces a .gersemirc configuration for CMake linting, integrates the gersemi tool into the lint workflow, and updates the lint dependencies accordingly. Multiple CMakeLists.txt files have been reformatted for consistency and readability, with no changes to build logic or behaviour.

Changes

Cohort / File(s) Change Summary
CMake Formatting
CMakeLists.txt, examples/CMakeLists.txt, tests/CMakeLists.txt
Reformatted CMake files for consistent style, indentation, and readability. No changes to logic or build behaviour.
CMake Lint Integration
taskfiles/lint.yaml
Added CMake linting tasks (check-cmake, fix-cmake, internal gersemi), integrated with main lint workflow, introduced utility variables and dependencies.
Gersemi Configuration
.gersemirc
Added new .gersemirc config file specifying line length, schema, and linting rules for CMake/YAML files.
Lint Requirements
lint-requirements.txt
Added gersemi>=0.16.2 to lint dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant TaskRunner
    participant LintVenv
    participant Gersemi

    Developer->>TaskRunner: Run lint check or fix
    TaskRunner->>TaskRunner: Invoke check-cmake/fix-cmake subtask
    TaskRunner->>LintVenv: Activate lint virtual environment
    TaskRunner->>Gersemi: Run gersemi on CMake files (with flags)
    Gersemi-->>TaskRunner: Report lint results or apply fixes
    TaskRunner-->>Developer: Output lint status
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • SharafMohamed

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@davidlion davidlion changed the title feat(lint): Add tasks for linting CMake with gersemi; Apply gersemi refactoring to CMake files. feat(lint): Add tasks for linting CMake scripts with gersemi; Apply gersemi to CMake scripts. Aug 4, 2025
@davidlion davidlion requested a review from SharafMohamed August 5, 2025 05:16
@davidlion davidlion requested a review from SharafMohamed August 6, 2025 00:13
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4a8b91 and ffab4aa.

📒 Files selected for processing (6)
  • .gersemirc (1 hunks)
  • CMakeLists.txt (3 hunks)
  • examples/CMakeLists.txt (2 hunks)
  • lint-requirements.txt (1 hunks)
  • taskfiles/lint.yaml (5 hunks)
  • tests/CMakeLists.txt (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2024-11-13T22:25:54.168Z
Learnt from: SharafMohamed
PR: y-scope/log-surgeon#48
File: tests/test-tag.cpp:10-10
Timestamp: 2024-11-13T22:25:54.168Z
Learning: In the log-surgeon codebase (C++), particularly in the finite automata components involving the `Tag` class (`src/log_surgeon/finite_automata/Tag.hpp`), it's important to ensure that `Tag*` pointers in other objects cannot be `nullptr`. Test cases should focus on validating that these `Tag*` pointers are not null where they are used, and handle `nullptr` appropriately.

Applied to files:

  • tests/CMakeLists.txt
📚 Learning: 2025-07-22T02:00:47.620Z
Learnt from: davidlion
PR: y-scope/log-surgeon#142
File: taskfiles/examples.yaml:63-76
Timestamp: 2025-07-22T02:00:47.620Z
Learning: CMake's find_package() command automatically honors <PackageName>_ROOT variables (e.g., LOG_SURGEON_ROOT) during its search process. The CMakeLists.txt file does not need to explicitly reference these _ROOT variables - they are built into CMake's package discovery mechanism.

Applied to files:

  • .gersemirc
  • CMakeLists.txt
📚 Learning: 2024-11-27T21:56:13.425Z
Learnt from: SharafMohamed
PR: y-scope/log-surgeon#56
File: src/log_surgeon/finite_automata/RegisterHandler.hpp:0-0
Timestamp: 2024-11-27T21:56:13.425Z
Learning: In the `log_surgeon` project, header guards in C++ header files should include `_HPP` at the end to match the filename. For example, in `RegisterHandler.hpp`, the header guard should be `LOG_SURGEON_FINITE_AUTOMATA_REGISTER_HANDLER_HPP`.

Applied to files:

  • CMakeLists.txt
  • examples/CMakeLists.txt
📚 Learning: 2024-10-10T18:05:34.072Z
Learnt from: SharafMohamed
PR: y-scope/log-surgeon#42
File: src/log_surgeon/finite_automata/RegexAST.hpp:106-112
Timestamp: 2024-10-10T18:05:34.072Z
Learning: In the C++ codebase for `log_surgeon`, the convention is to use `false == condition` instead of `!condition` when checking conditions, for clarity.

Applied to files:

  • CMakeLists.txt
📚 Learning: 2025-05-01T14:47:57.016Z
Learnt from: davidlion
PR: y-scope/log-surgeon#106
File: src/log_surgeon/Lexer.hpp:114-114
Timestamp: 2025-05-01T14:47:57.016Z
Learning: When handling error cases in log-surgeon, prefer using the `Result<T, ErrorCode>` type from ystdlib-cpp (https://github.com/y-scope/ystdlib-cpp/blob/main/src/ystdlib/error_handling/Result.hpp) instead of `std::pair<ErrorCode, T>` for better type safety and clearer semantics.

Applied to files:

  • CMakeLists.txt
📚 Learning: 2025-05-05T14:55:34.455Z
Learnt from: SharafMohamed
PR: y-scope/log-surgeon#106
File: src/log_surgeon/Lalr1Parser.tpp:661-665
Timestamp: 2025-05-05T14:55:34.455Z
Learning: The log-surgeon codebase follows a design approach where function contracts (like `ErrorCode::Success` guaranteeing a valid token) are trusted, and contract violations are allowed to throw exceptions rather than being explicitly checked at every call site.

Applied to files:

  • CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build (ubuntu-24.04, release)
  • GitHub Check: build (ubuntu-22.04, debug)
  • GitHub Check: build (ubuntu-24.04, debug)
  • GitHub Check: lint (ubuntu-24.04)
🔇 Additional comments (4)
tests/CMakeLists.txt (1)

2-20: Formatting only – looks good

No functional changes detected; the multiline style matches the rest of the PR.

.gersemirc (1)

1-9: Validate paths & redundant lint directives

  1. definitions points to build/deps/Catch2-extracted/extras/Catch.cmake, which is generated after a configure step and may not exist in a clean checkout. This will cause gersemi to error when developers run task lint:check-cmake before generating the build/ tree. Consider pointing to the source-tree copy of Catch.cmake or using a glob that tolerates absence.

  2. Line 1 disables yamllint’s line-length rule, yet line_length: 100 is set below. The first directive is now redundant and can be removed to let yamllint enforce the same limit as gersemi.

taskfiles/lint.yaml (2)

4-6: deps.yaml correctly included

Adding the internal deps Taskfile resolves the previously-flagged dependency gap and allows gersemi to reuse the existing deps:install-all logic.


49-50: New CMake check wired into the main check task

check-cmake is now invoked alongside the existing C++ and YAML checks, addressing the earlier review note that it should be part of the default lint flow.

Comment on lines +143 to +152
target_compile_options(
log_surgeon
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4
/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-Wextra
-Wpedantic
-Werror>
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Same generator-expression split here – will break the top-level build

The target_compile_options(log_surgeon …) block contains the identical line-break issue as flagged in examples/CMakeLists.txt. Merge the arguments so each $<…> expression stays contiguous:

-        $<$<CXX_COMPILER_ID:MSVC>:/W4
-        /WX>
-        $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-        -Wextra
-        -Wpedantic
-        -Werror>
+        $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
+        $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>

Without this fix, cmake .. fails with “Error evaluating generator expression”.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target_compile_options(
log_surgeon
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4
/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-Wextra
-Wpedantic
-Werror>
)
target_compile_options(
log_surgeon
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
)
🤖 Prompt for AI Agents
In CMakeLists.txt lines 143 to 152, the target_compile_options call splits
generator expressions across multiple lines, causing CMake to fail with an
"Error evaluating generator expression." Fix this by merging each generator
expression into a single contiguous line without line breaks inside the $<...>
expressions, ensuring the entire expression is continuous and properly parsed by
CMake.

Comment on lines +30 to +39
target_compile_options(
${target}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4
/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-Wextra
-Wpedantic
-Werror>
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Broken generator expression – will fail CMake configure

target_compile_options splits each generator expression across two arguments:

$<$<CXX_COMPILER_ID:MSVC>:/W4
/WX>

CMake treats a generator expression as a single, unbroken argument; splitting it inserts an unintended line break that terminates the expression early and produces a “syntax error in generator expression” at configure time.

-    target_compile_options(
-        ${target}
-        PRIVATE
-            $<$<CXX_COMPILER_ID:MSVC>:/W4
-            /WX>
-            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-            -Wextra
-            -Wpedantic
-            -Werror>
-    )
+    target_compile_options(
+        ${target}
+        PRIVATE
+            $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
+            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
+    )

The same pattern recurs in the root CMakeLists.txt; please fix there as well.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target_compile_options(
${target}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4
/WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-Wextra
-Wpedantic
-Werror>
)
target_compile_options(
${target}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic -Werror>
)
🤖 Prompt for AI Agents
In examples/CMakeLists.txt around lines 30 to 39, the generator expressions in
target_compile_options are split across multiple lines, causing CMake to treat
them as separate arguments and resulting in a syntax error. To fix this, rewrite
each generator expression as a single continuous string without line breaks,
ensuring the entire expression is passed as one argument. Also, apply the same
fix to the root CMakeLists.txt where this pattern occurs.

@davidlion davidlion merged commit 29c2faf into y-scope:main Aug 7, 2025
11 checks passed
@davidlion davidlion deleted the lint-cmake branch August 7, 2025 23:03
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.

2 participants