Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove explicit need of uname and lsb_release file #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

koudis
Copy link
Member

@koudis koudis commented Jan 21, 2025

Summary by CodeRabbit

  • Chores

    • Updated minimum required CMake version from 3.21 to 3.22
    • Improved system information retrieval method using integrated CMake commands
    • Enhanced error handling for system configuration detection
    • Added a new cleanup module inclusion to the workflow
  • Bug Fixes

    • Added more robust validation for system architecture and distribution identification
    • Provided clearer feedback on errors related to system configuration
    • Corrected spelling errors in documentation and variable names for improved clarity

Copy link

coderabbitai bot commented Jan 21, 2025

Walkthrough

The pull request introduces several changes across multiple CMake-related files. Key modifications include updating the minimum required CMake version from 3.21 to 3.22 in FindCMDEF.cmake, adding the inclusion of CMDEF_CLEANUP.cmake, and revising the method of retrieving system architecture and distribution information in system_modules/CMDEF_ENV.cmake to utilize CMAKE_HOST_SYSTEM_INFORMATION. Additionally, various spelling corrections and documentation clarifications have been made throughout the codebase, enhancing clarity without altering functionality.

Changes

File Change Summary
FindCMDEF.cmake Increased minimum CMake version from 3.21 to 3.22; added inclusion of CMDEF_CLEANUP.cmake module.
system_modules/CMDEF_ENV.cmake Replaced external command execution with CMAKE_HOST_SYSTEM_INFORMATION for system information retrieval; added validation for architecture and distribution information.
doc/CacheVariables.md Corrected spelling errors and improved clarity in documentation for cache variables.
example/executable/CMakeLists.txt Added dump_cmake_variables function to list all CMake variables; corrected spelling of "visibility."
example/library-interface/CMakeLists.txt Corrected spelling of "VISIBILITY" in compile options for testlib-shared.
example/library-interface/main.cpp Corrected "exacutable" to "executable" in comments.
example/library/CMakeLists.txt Corrected spelling of "VISIBILITY" in compile options for testlib-shared.
system_modules/CMDEF_BUILD_TYPE.cmake Corrected spelling errors in comments related to variable names.
system_modules/CMDEF_COMPILE_DEFINITION.cmake Corrected spelling of "language" and "VISIBILITY" in comments and variable names.
system_modules/CMDEF_COMPILE_OPTION.cmake Corrected spelling of "language" and "VISIBILITY" in comments and function parameters.
system_modules/CMDEF_LINK_OPTION.cmake Corrected spelling of "language" and "VISIBILITY" in comments and function parameters.
system_modules/CMDEF_RESOURCE.cmake Corrected spelling errors in comments.

Sequence Diagram

sequenceDiagram
    participant CMake
    participant CMDEF_ENV
    participant System
    
    CMake->>CMDEF_ENV: Request system information
    CMDEF_ENV->>System: Use CMAKE_HOST_SYSTEM_INFORMATION
    System-->>CMDEF_ENV: Return system details
    CMDEF_ENV->>CMDEF_ENV: Normalize and validate system info
    CMDEF_ENV-->>CMake: Provide system configuration
Loading

Poem

🐰 Cmake's rabbit hops with glee,
Upgrading versions, setting systems free!
From commands old to new and bright,
System info now shines so light!
A version bump, a coding dance,
Our modules leap with newfound chance! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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: 1

🧹 Nitpick comments (1)
system_modules/CMDEF_ENV.cmake (1)

Line range hint 432-510: Great improvements to system information detection!

The changes successfully:

  • Remove dependencies on external commands (uname and lsb_release)
  • Use CMake's built-in CMAKE_HOST_SYSTEM_INFORMATION command consistently
  • Implement consistent string normalization patterns
  • Add robust error handling with descriptive messages

Consider extracting the common string normalization pattern into a helper function to reduce code duplication, as it's used in three places:

STRING(REGEX REPLACE "[^a-zA-Z0-9.]" "-" _mapped "${_value}")
STRING(TOLOWER "${_mapped}" _normalized)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdbe766 and 3736d2e.

📒 Files selected for processing (2)
  • FindCMDEF.cmake (1 hunks)
  • system_modules/CMDEF_ENV.cmake (3 hunks)
🔇 Additional comments (3)
FindCMDEF.cmake (1)

12-12: LGTM! Version bump is necessary.

The increase in minimum CMake version from 3.21 to 3.22 is required to support the new CMAKE_HOST_SYSTEM_INFORMATION queries (DISTRIB_ID and DISTRIB_VERSION_ID) that replace the external command dependencies.

system_modules/CMDEF_ENV.cmake (2)

432-440: LGTM! Improved system architecture detection.

The changes effectively:

  • Remove dependency on external uname command
  • Add proper validation for empty/invalid architecture strings
  • Normalize architecture string consistently

467-475: LGTM! Improved distribution ID detection.

The changes effectively:

  • Remove dependency on external lsb_release command
  • Add proper validation for empty/invalid distribution IDs
  • Normalize distribution ID string consistently

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: 0

🧹 Nitpick comments (4)
system_modules/CMDEF_ENV.cmake (4)

432-440: LGTM! Clean replacement of uname dependency.

The use of CMAKE_HOST_SYSTEM_INFORMATION with proper string normalization is a good approach. The error handling is thorough and provides clear guidance.

Consider adding quotes around the error message components for better readability:

-			MESSAGE(FATAL_ERROR "Cannot determine system architecture."
-				" It seems the system has system arch set to empty or invalid string."
-				" Consult os-release file."
+			MESSAGE(FATAL_ERROR "Cannot determine system architecture."
+				" It seems the system has system arch set to empty or invalid string."
+				" Please consult 'os-release' file."

467-475: LGTM! Clean replacement of lsb_release dependency.

The implementation follows the same pattern as _CMDEF_ENV_GET_ARCH, maintaining consistency in the codebase.

Fix the error message formatting for consistency with other messages:

-			MESSAGE(FATAL_ERROR "Cannot determine Distro ID."
-				"It seems the system has Distro ID set to empty or invalid string."
-				" Consult os-release file."
+			MESSAGE(FATAL_ERROR "Cannot determine Distro ID."
+				" It seems the system has Distro ID set to empty or invalid string."
+				" Please consult 'os-release' file."

502-510: LGTM! Clean replacement of lsb_release dependency.

The implementation maintains consistency with the other system information retrieval functions.

Fix the error message formatting for consistency:

-			MESSAGE(FATAL_ERROR "Cannot determine Distro Version ID."
-				" It seems the system has Distro Version ID set to empty or invalid string."
-				" Consult os-release file."
+			MESSAGE(FATAL_ERROR "Cannot determine Distro Version ID."
+				" It seems the system has Distro Version ID set to empty or invalid string."
+				" Please consult 'os-release' file."

Line range hint 432-510: Consider centralizing error messages for better maintainability.

The three functions have similar error messages. Consider defining these at the top of the file as variables for better maintainability and consistency.

Example implementation:

# At the top of the file
SET(_CMDEF_ENV_ERROR_MESSAGE_PREFIX "Cannot determine")
SET(_CMDEF_ENV_ERROR_MESSAGE_SUFFIX "Please consult 'os-release' file.")

# In the functions
MESSAGE(FATAL_ERROR "${_CMDEF_ENV_ERROR_MESSAGE_PREFIX} system architecture."
    " It seems the system has system arch set to empty or invalid string."
    " ${_CMDEF_ENV_ERROR_MESSAGE_SUFFIX}")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3736d2e and 7c92895.

📒 Files selected for processing (1)
  • system_modules/CMDEF_ENV.cmake (3 hunks)

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: 0

🧹 Nitpick comments (3)
system_modules/CMDEF_ENV.cmake (3)

431-439: Add documentation for the string normalization process.

The architecture detection logic looks good, but could benefit from a comment explaining the string normalization steps (regex replacement and lowercase conversion) for better maintainability.

Add this comment before line 432:

+		# Normalize architecture string:
+		# 1. Replace non-alphanumeric chars with hyphens
+		# 2. Convert to lowercase for consistency

466-474: Extract common string normalization logic.

The string normalization and error handling logic is duplicated across functions. Consider extracting it into a helper function for better maintainability.

Create a new helper function:

## Helper
#
# Normalize system information string and validate result
#
# <function>(
#   <output_var_name>     # Output variable name
#   <input_string>        # Input string to normalize
#   <info_type>          # Type of info (for error message)
# )
#
FUNCTION(_CMDEF_ENV_NORMALIZE_SYSTEM_INFO output input info_type)
  STRING(REGEX REPLACE "[^a-zA-Z0-9.]" "-" _mapped "${input}")
  STRING(TOLOWER "${_mapped}" _normalized)
  
  IF(NOT _normalized)
    MESSAGE(FATAL_ERROR "Cannot determine ${info_type}."
      " It seems the system has ${info_type} set to empty or invalid string."
      " Consult os-release file."
    )
  ENDIF()
  
  SET(${output} "${_normalized}" PARENT_SCOPE)
ENDFUNCTION()

Then update the functions to use it:

 FUNCTION(_CMDEF_ENV_GET_DISTRO_ID distro_id)
   # ... existing OS checks ...
   IF(CMDEF_OS_LINUX)
     CMAKE_HOST_SYSTEM_INFORMATION(RESULT _distro_id QUERY DISTRIB_ID)
-    STRING(REGEX REPLACE "[^a-zA-Z0-9.]" "-" _distro_id_mapped "${_distro_id}")
-    STRING(TOLOWER "${_distro_id_mapped}" _distro_id_normalized)
-    IF(NOT _distro_id_normalized)
-      MESSAGE(FATAL_ERROR "Cannot determine Distro ID."
-        "It seems the system has Distro ID set to empty or invalid string."
-        " Consult os-release file."
-      )
-    ENDIF()
-    SET(${distro_id} "${_distro_id_normalized}" PARENT_SCOPE)
+    _CMDEF_ENV_NORMALIZE_SYSTEM_INFO(${distro_id} "${_distro_id}" "Distro ID")
     RETURN()
   ENDIF()
   # ... existing error message ...
 ENDFUNCTION()

505-508: Fix error message formatting inconsistency.

The error message has inconsistent spacing in the concatenation.

-			MESSAGE(FATAL_ERROR "Cannot determine Distro Version ID."
-				" It seems the system has Distro Version ID set to empty or invalid string."
+			MESSAGE(FATAL_ERROR "Cannot determine Distro Version ID. "
+				"It seems the system has Distro Version ID set to empty or invalid string."
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c92895 and c3b28ae.

📒 Files selected for processing (2)
  • FindCMDEF.cmake (2 hunks)
  • system_modules/CMDEF_ENV.cmake (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • FindCMDEF.cmake
🔇 Additional comments (2)
system_modules/CMDEF_ENV.cmake (2)

501-509: Use the suggested helper function here as well.

This function has the same string normalization and validation logic as the other functions. It would benefit from using the suggested _CMDEF_ENV_NORMALIZE_SYSTEM_INFO helper function.


Line range hint 431-509: Overall changes look good! 👍

The changes successfully replace external command dependencies with CMake's built-in CMAKE_HOST_SYSTEM_INFORMATION command, making the code more portable and reliable. The implementation includes proper error handling and string normalization.

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: 0

🧹 Nitpick comments (2)
example/executable/CMakeLists.txt (1)

99-106: Consider moving dump_cmake_variables to a debug utilities module.

The dump_cmake_variables function is a useful debugging tool. Consider moving it to a separate debug utilities module (e.g., CMDEF_DEBUG.cmake) to make it reusable across different CMake files.

doc/CacheVariables.md (1)

34-37: Add a comma after the introductory phrase.

For better readability, add a comma after "In this case":

-In this case the variable is set to ON.
+In this case, the variable is set to ON.
🧰 Tools
🪛 LanguageTool

[formatting] ~37-~37: Consider inserting a comma after an introductory phrase for better readability.
Context: ...d in CMDEF_BUILD_TYPE_DEFAULT variable. In this case the variable is set to ON. - If the CMA...

(IN_THAT_CASE_COMMA)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3b28ae and e201587.

📒 Files selected for processing (11)
  • doc/CacheVariables.md (2 hunks)
  • example/executable/CMakeLists.txt (5 hunks)
  • example/library-interface/CMakeLists.txt (1 hunks)
  • example/library-interface/main.cpp (1 hunks)
  • example/library/CMakeLists.txt (1 hunks)
  • system_modules/CMDEF_BUILD_TYPE.cmake (2 hunks)
  • system_modules/CMDEF_COMPILE_DEFINITION.cmake (4 hunks)
  • system_modules/CMDEF_COMPILE_OPTION.cmake (4 hunks)
  • system_modules/CMDEF_ENV.cmake (6 hunks)
  • system_modules/CMDEF_LINK_OPTION.cmake (4 hunks)
  • system_modules/CMDEF_RESOURCE.cmake (2 hunks)
✅ Files skipped from review due to trivial changes (7)
  • system_modules/CMDEF_RESOURCE.cmake
  • example/library-interface/main.cpp
  • system_modules/CMDEF_COMPILE_OPTION.cmake
  • example/library/CMakeLists.txt
  • system_modules/CMDEF_BUILD_TYPE.cmake
  • system_modules/CMDEF_LINK_OPTION.cmake
  • example/library-interface/CMakeLists.txt
🧰 Additional context used
🪛 LanguageTool
doc/CacheVariables.md

[formatting] ~37-~37: Consider inserting a comma after an introductory phrase for better readability.
Context: ...d in CMDEF_BUILD_TYPE_DEFAULT variable. In this case the variable is set to ON. - If the CMA...

(IN_THAT_CASE_COMMA)

🔇 Additional comments (4)
system_modules/CMDEF_ENV.cmake (3)

431-439: LGTM! Improved system architecture detection.

The switch to CMAKE_HOST_SYSTEM_INFORMATION for architecture detection is a good improvement that removes the external dependency on uname. The added validation for empty/invalid architecture strings enhances error handling.


466-474: LGTM! Improved distribution ID detection.

The use of CMAKE_HOST_SYSTEM_INFORMATION for distribution ID detection is consistent with the architecture detection changes. The validation and error handling are well-implemented.


501-509: LGTM! Improved distribution version detection.

The implementation follows the same pattern as architecture and distribution ID detection, providing consistent error handling and validation.

system_modules/CMDEF_COMPILE_DEFINITION.cmake (1)

94-94: Breaking Change: VISIBILITY parameter is now required.

The VISIBILITY parameter has been made mandatory in CMDEF_COMPILE_DEFINITIONS_TARGET. While this enforces better practice by requiring explicit visibility specification, it may break existing code that doesn't provide this parameter.

Run this script to find potentially affected code:

Also applies to: 104-104, 106-106

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