Skip to content

Conversation

@vaind
Copy link
Collaborator

@vaind vaind commented Sep 18, 2025

Summary

Implements support for updating CMake FetchContent_Declare() statements in the updater system, addressing issue #91.

This allows automatic dependency updates for console SDK repositories that use CMake FetchContent for dependency management.

Key Features

  • Path Syntax: Supports path/to/file.cmake#DepName and auto-detection for single dependencies
  • Hash & Tag Support: Handles both semantic version tags and 40-char git hashes
  • Format Preservation: Hash values are preserved as hashes with tag comments (e.g., abc123... # v1.2.3)
  • Hash Resolution: Converts hashes to tag names for version comparison logic
  • GitHub Actions Integration: Full compatibility with existing output variables and workflows
  • Comprehensive Testing: 23 unit and integration tests with real repository validation

Implementation Details

New Files

  • updater/scripts/cmake-functions.ps1 - CMake helper functions (extracted for testability)
  • updater/tests/update-dependency-cmake.Tests.ps1 - Unit tests for CMake functions
  • updater/tests/testdata/cmake/ - Test data files covering various CMake patterns

Modified Files

  • updater/scripts/update-dependency.ps1 - Main integration point
  • updater/tests/update-dependency.Tests.ps1 - Integration tests

Usage Examples

# Update specific dependency in CMake file
./update-dependency.ps1 vendor/sentry-native.cmake#sentry-native

# Auto-detect single dependency
./update-dependency.ps1 vendor/sentry-native.cmake

# With version pattern filtering
./update-dependency.ps1 vendor/deps.cmake#googletest -Pattern "^v?1\."

Test Coverage

  • 15 unit tests - Function isolation and error handling
  • 8 integration tests - End-to-end workflows with real repositories
  • Cross-platform compatibility - Works on Windows, Linux, macOS
  • Real repository testing - Validates against sentry-native and googletest

Testing

# Run all CMake tests
Invoke-Pester updater/tests/update-dependency-cmake.Tests.ps1
Invoke-Pester updater/tests/update-dependency.Tests.ps1 -FullName "*cmake-fetchcontent*"

# Run full test suite
Invoke-Pester updater/

Backward Compatibility

This change is fully backward compatible. All existing functionality for submodules, properties files, and scripts remains unchanged.

Related

Resolves #91

🤖 Generated with Claude Code

Implements support for updating CMake FetchContent_Declare() statements
in addition to existing submodules, properties files, and scripts.

Key features:
- Support for path.cmake#DepName and auto-detection syntax
- Hash vs tag detection with hash format preservation
- Hash-to-tag resolution for version comparison
- GitHub Actions output integration
- Comprehensive test coverage (23 tests)

Resolves: #91

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 58cef75

@vaind vaind marked this pull request as draft September 18, 2025 20:41
Critical fixes and improvements:
- Fix GitHub Actions workflow validation to allow # character in paths
- Update documentation with CMake examples and usage
- Improve comment handling in hash updates
- Implement proper ancestry validation for hash updates
- Test with real console SDK CMake files

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- sentry-native.cmake now uses auto-detection (single dependency)
- dependencies.cmake now shows explicit dependency name syntax
- Better reflects real-world usage patterns
- Split long bullet point into structured sublist
- Clear separation of different path format types
- Better readability for CMake file options
- Replace $env:TEMP with [System.IO.Path]::GetTempPath()
- Use [System.Guid]::NewGuid() for unique directory names
- More robust cross-platform compatibility
- Return false instead of true when ancestry validation fails
- Change warning to error message for clarity
- Prevents potentially incorrect updates when validation is uncertain
- Follows fail-safe principle for security-critical operations
- Always replace entire line content after GIT_TAG
- Removes potentially outdated version-specific comments
- Simplifies regex pattern (no separate hash/tag logic needed)
- Cleaner and more predictable behavior
- Check $LASTEXITCODE after git ls-remote calls
- Prevent parsing error messages as commit hashes
- Fixes potential corruption of CMake files with 'fatal:' etc.
- Applies to both Update-CMakeFile and Find-TagForHash functions

Fixes critical bug where network failures could corrupt dependency files.
- Tests updating from one git hash to a newer tag's hash
- Covers important scenario of hash-to-hash updates
- Verifies hash format preservation and comment replacement
- Ensures old hash and comments are properly removed
- Move CMake test data from external files to inline here-strings
- Group related test scenarios into single test cases for better readability
- Reduce test count from 16 to 6 while maintaining same coverage
- Remove external testdata/cmake/ directory (no longer needed)
- Improve test maintainability - all test input/output visible in one place

Test groupings:
- Parse scenarios: basic, auto-detect, hash, complex formatting
- Multiple deps: auto-detection errors, explicit selection
- Error scenarios: missing deps, missing repo/tag
- Hash resolution: null results, network failures
- Update scenarios: tag-to-tag, hash-to-hash, complex formatting
- Update errors: missing dependency updates
- Move test data creation to Context BeforeAll level
- Restore individual test cases (16 total) for focused testing
- Eliminate data duplication while keeping inline visibility
- Best of both worlds: shared setup + granular test cases

Structure:
- Context BeforeAll: Creates shared test files with inline data
- Individual It blocks: Reference shared files for specific scenarios
- Clear test names and focused assertions per test case
- Promote function names to Describe level (Parse-CMakeFetchContent, Find-TagForHash, Update-CMakeFile)
- Group tests by CMake file type at Context level
- Each Context has its own test data (no duplication)
- Clear logical organization: function -> file type -> specific tests

Structure:
├── Describe 'Parse-CMakeFetchContent'
│   ├── Context 'Basic single dependency file' (3 tests)
│   ├── Context 'Hash-based dependency file' (1 test)
│   ├── Context 'Complex formatting file' (1 test)
│   ├── Context 'Multiple dependencies file' (2 tests)
│   └── Context 'Malformed files' (2 tests)
├── Describe 'Find-TagForHash'
│   └── Context 'Hash resolution scenarios' (2 tests)
└── Describe 'Update-CMakeFile'
    ├── Context 'Basic tag updates' (3 tests)
    ├── Context 'Hash updates' (1 test)
    └── Context 'Complex formatting' (1 test)
- Replace generic pattern [a-f0-9]{40} with actual 0.11.0 hash
- More precise assertion: 3bd091313ae97be90be62696a2babe591a988eb8
- Consistent with integration test data expectations
- Eliminates ambiguity in test validation
- Replace generic pattern [a-f0-9]{40} # \d+\.\d+\.\d+ with exact values
- More precise assertion: 3bd091313ae97be90be62696a2babe591a988eb8 # 0\.11\.0
- Matches unit test precision and validates exact expected output
- Eliminates ambiguity in hash-to-tag update validation
- Replace generic \d+\.\d+\.\d+ patterns with exact 0\.11\.0
- More precise assertions for explicit dependency and auto-detection tests
- Completes migration from generic patterns to exact expected values
- Ensures deterministic test validation across all CMake tests
…straints

- Revert exact version assertions where UpdateDependency gets latest version
- Keep generic patterns \d+\.\d+\.\d+ and [a-f0-9]{40} for future-proof tests
- Integration tests call UpdateDependency without pattern constraints
- Latest version will change over time (0.11.0 → 0.12.0, etc.)
- Unit tests can keep exact values since they specify exact versions
- Document new CMake FetchContent functionality in CHANGELOG.md
- References PR #104 for automated dependency updates
- Follows existing changelog format and conventions
@vaind vaind marked this pull request as ready for review September 19, 2025 08:03
@vaind
Copy link
Collaborator Author

vaind commented Sep 19, 2025

@sentry review

vaind and others added 2 commits September 19, 2025 11:01
Added robust parameter validation with type constraints to all CMake helper functions:
- Parse-CMakeFetchContent: Validates file path exists and dependency name format
- Find-TagForHash: Validates repository URL and 40-char hash format
- Test-HashAncestry: Validates repository URL and hash formats
- Update-CMakeFile: Validates file path, dependency name, and new value

This prevents misuse, improves error handling, and addresses security concerns around parameter injection attacks.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Added validation to ensure CMake dependency names follow proper naming conventions and prevent potential regex injection attacks. Dependency names must start with a letter and contain only alphanumeric characters, underscores, dots, or hyphens.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@vaind vaind merged commit a4ff0c2 into main Sep 19, 2025
21 checks passed
@vaind vaind deleted the cmake-fetchcontent-support branch September 19, 2025 13:52
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.

updater: support cmake FetchContent

2 participants