feat: add function for parsing version from version.txt#4
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a new public CMake function Changes
Sequence Diagram(s)sequenceDiagram
participant Config as CMake Configure
participant Func as CMUTIL_VERSION_GET_FROM_VERSION_FILE
participant Reader as CMUTIL_PROPERTY_FILE_READ
participant Checker as CMUTIL_VERSION_CHECK
Config->>Func: call(output_var [, path])
Func->>Reader: read properties from version file (default or given path)
Reader-->>Func: returns properties (including inject_version)
Func->>Func: if inject_version == NOT DEFINED or empty -> FATAL_ERROR
Func->>Checker: CMUTIL_VERSION_CHECK("inject_version")
Checker-->>Func: validation result
Func-->>Config: set validated version via PARENT_SCOPE or abort
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
test/VERSION/CMakeLists.txt (1)
35-41: Add a dedicated fail test for invalid/missingversionkey for this new function.The new test only covers success. Please add a fail-case directory that calls
CMUTIL_VERSION_GET_FROM_VERSION_FILE(...)with invalid input and register it viaTEST_INVALID_CMAKE_RUN(...)in the parent test file.If you want, I can draft the exact fail test layout and expected error pattern.
Based on learnings: In this project, failure tests are structured usingTEST_INVALID_CMAKE_RUNin parent test files, while fail-case files directly triggerFATAL_ERROR.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/VERSION/CMakeLists.txt` around lines 35 - 41, Add a failing test case for CMUTIL_VERSION_GET_FROM_VERSION_FILE by creating a fail-case directory that contains a CMakeLists.txt that calls CMUTIL_VERSION_GET_FROM_VERSION_FILE(parsed_version) but with an invalid or missing "version" key so it triggers MESSAGE(FATAL_ERROR ...) (use the same pattern as existing failure tests); then register that directory in the parent test file using TEST_INVALID_CMAKE_RUN(<fail-case-dir> ...) and supply the expected error pattern matching the FATAL_ERROR message from CMUTIL_VERSION_GET_FROM_VERSION_FILE so the CI recognizes the negative test.system_modules/CMUTIL_VERSION.cmake (1)
120-123: Harden optional argument parsing for clearer API behavior.Line 120 currently consumes all
ARGNas one value. If multiple optional args are passed, CMake builds a list and error handling becomes unclear. Prefer explicit arity checks andARGV1.Suggested refactor
FUNCTION(CMUTIL_VERSION_GET_FROM_VERSION_FILE output_var) - SET(version_file ${ARGN}) - IF("${version_file}" STREQUAL "") - SET(version_file "${CMAKE_CURRENT_SOURCE_DIR}/version.txt") - ENDIF() + IF(ARGC GREATER 2) + MESSAGE(FATAL_ERROR "CMUTIL_VERSION_GET_FROM_VERSION_FILE expects: <output_var> [version_file]") + ENDIF() + IF(ARGC EQUAL 2) + SET(version_file "${ARGV1}") + ELSE() + SET(version_file "${CMAKE_CURRENT_SOURCE_DIR}/version.txt") + ENDIF() @@ - SET(${output_var} ${inject_version} PARENT_SCOPE) + SET(${output_var} "${inject_version}" PARENT_SCOPE) ENDFUNCTION()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@system_modules/CMUTIL_VERSION.cmake` around lines 120 - 123, The code currently uses SET(version_file ${ARGN}) which conflates multiple optional arguments into a CMake list; change to explicit arity checks (use ARGC or IF(DEFINED ARGV1)) and read only ARGV1 as the optional path: if no optional arg provided, set version_file to the default "${CMAKE_CURRENT_SOURCE_DIR}/version.txt"; if more than one optional arg is given, fail with a clear message. Update the logic around SET(version_file ...), the IF("${version_file}" STREQUAL "") check, and replace ARGN usage with ARGV1/ARGC validation so the API is deterministic and reports misuse.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@system_modules/CMUTIL_VERSION.cmake`:
- Around line 111-123: The comment above CMUTIL_VERSION_GET_FROM_VERSION_FILE
states the default path is ${CMAKE_CURRENT_LIST_DIR}/version.txt but the
function sets version_file to ${CMAKE_CURRENT_SOURCE_DIR}/version.txt; update
one to match the other: either change the comment to say
${CMAKE_CURRENT_SOURCE_DIR}/version.txt or change the implementation to set
version_file to ${CMAKE_CURRENT_LIST_DIR}/version.txt (modify the assignment of
version_file in CMUTIL_VERSION_GET_FROM_VERSION_FILE accordingly) so the
documentation and code are consistent.
---
Nitpick comments:
In `@system_modules/CMUTIL_VERSION.cmake`:
- Around line 120-123: The code currently uses SET(version_file ${ARGN}) which
conflates multiple optional arguments into a CMake list; change to explicit
arity checks (use ARGC or IF(DEFINED ARGV1)) and read only ARGV1 as the optional
path: if no optional arg provided, set version_file to the default
"${CMAKE_CURRENT_SOURCE_DIR}/version.txt"; if more than one optional arg is
given, fail with a clear message. Update the logic around SET(version_file ...),
the IF("${version_file}" STREQUAL "") check, and replace ARGN usage with
ARGV1/ARGC validation so the API is deterministic and reports misuse.
In `@test/VERSION/CMakeLists.txt`:
- Around line 35-41: Add a failing test case for
CMUTIL_VERSION_GET_FROM_VERSION_FILE by creating a fail-case directory that
contains a CMakeLists.txt that calls
CMUTIL_VERSION_GET_FROM_VERSION_FILE(parsed_version) but with an invalid or
missing "version" key so it triggers MESSAGE(FATAL_ERROR ...) (use the same
pattern as existing failure tests); then register that directory in the parent
test file using TEST_INVALID_CMAKE_RUN(<fail-case-dir> ...) and supply the
expected error pattern matching the FATAL_ERROR message from
CMUTIL_VERSION_GET_FROM_VERSION_FILE so the CI recognizes the negative test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: afe62d89-09b0-48c1-998a-ae6a6fa16dc6
📒 Files selected for processing (2)
system_modules/CMUTIL_VERSION.cmaketest/VERSION/CMakeLists.txt
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@system_modules/CMUTIL_VERSION.cmake`:
- Around line 125-131: Clear the local inject_version before calling
CMUTIL_PROPERTY_FILE_READ so a stale parent-scope value cannot be picked up;
specifically, add a local set(inject_version "") (or otherwise unset
inject_version in the current scope) immediately before the
CMUTIL_PROPERTY_FILE_READ call in the CMUTIL_VERSION_GET_FROM_VERSION_FILE
implementation and apply the identical change to
CMUTIL_VERSION_VALIDATE_VERSION_FILE_FOR so the IF(NOT inject_version) fatal
check always validates the freshly-read value rather than a leaked parent value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b25b31e0-203b-4e11-9a2a-0c95b05912db
📒 Files selected for processing (1)
system_modules/CMUTIL_VERSION.cmake
There was a problem hiding this comment.
♻️ Duplicate comments (1)
system_modules/CMUTIL_VERSION.cmake (1)
125-127:⚠️ Potential issue | 🟠 Major
UNSET(inject_version)still allows parent-scope leakage.At Line 125 and Line 155,
UNSET(inject_version)removes only the local binding; if a parentinject_versionexists, CMake can still resolve it. If the file lacksversion=..., Line 127 / Line 157 may validate stale data instead of failing.Use an explicit local shadow value before read.
🔧 Proposed fix
- UNSET(inject_version) + SET(inject_version "") CMUTIL_PROPERTY_FILE_READ("${version_file}" inject) IF(NOT DEFINED inject_version OR "${inject_version}" STREQUAL "") MESSAGE(FATAL_ERROR "${version_file} is not valid") ENDIF()- UNSET(inject_version) + SET(inject_version "") CMUTIL_PROPERTY_FILE_READ("${version_file}" inject) IF(NOT DEFINED inject_version OR "${inject_version}" STREQUAL "") MESSAGE(FATAL_ERROR "${version_file} is not valid") ENDIF()In CMake function scope, if a parent variable exists, does `unset(var)` in the function make the parent value visible again? What is the recommended pattern to prevent stale parent-scope values when expecting `var` to be populated via a child function using `PARENT_SCOPE`?Also applies to: 155-157
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@system_modules/CMUTIL_VERSION.cmake` around lines 125 - 127, The current UNSET(inject_version) can let a parent-scope inject_version leak back into this scope; replace the UNSET with an explicit local shadow assignment (e.g., set(inject_version "")) before calling CMUTIL_PROPERTY_FILE_READ("${version_file}" inject) so the function starts with a known-empty local inject_version and the subsequent IF(NOT DEFINED inject_version OR "${inject_version}" STREQUAL "") correctly detects a missing value; apply the same change for the second occurrence around lines 155–157 referencing inject_version.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@system_modules/CMUTIL_VERSION.cmake`:
- Around line 125-127: The current UNSET(inject_version) can let a parent-scope
inject_version leak back into this scope; replace the UNSET with an explicit
local shadow assignment (e.g., set(inject_version "")) before calling
CMUTIL_PROPERTY_FILE_READ("${version_file}" inject) so the function starts with
a known-empty local inject_version and the subsequent IF(NOT DEFINED
inject_version OR "${inject_version}" STREQUAL "") correctly detects a missing
value; apply the same change for the second occurrence around lines 155–157
referencing inject_version.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 65b7c352-9c87-41c8-b3f4-e4635739f1cc
📒 Files selected for processing (1)
system_modules/CMUTIL_VERSION.cmake
Summary by CodeRabbit
New Features
Tests
Bug Fixes