Skip to content

Conversation

@vaind
Copy link
Contributor

@vaind vaind commented Oct 17, 2025

Summary

Adds SENTRY_SDK_VERSION CMake cache variable to allow downstream SDKs to override the SDK version at configuration time without modifying sentry.h.

Problem

The previous PR (#1416) attempted to solve the build ID extraction by parsing sentry.h after it was modified by downstream SDKs. However, this approach only worked on the second CMake configuration run, after sentry.h had been patched. This is not ideal for downstream SDK workflows.

Solution

Instead of modifying and re-reading sentry.h, downstream SDKs can now set the SDK version directly via CMake:

cmake -DSENTRY_SDK_VERSION="0.11.3+20251016-9e31c9f-dirty" ...

How it works:

  1. Version Override: If SENTRY_SDK_VERSION is set, it takes precedence over the version in sentry.h
  2. Build ID Extraction: The build metadata is automatically extracted from the version string (anything after +)
  3. Compile Definition: The overridden version is passed as a compile definition to the code
  4. Header Update: sentry.h checks if SENTRY_SDK_VERSION is already defined (similar to how SENTRY_SDK_NAME works)

Result

Embedded library info correctly separates version and build ID on the first CMake configuration:

SENTRY_VERSION:0.11.3;PLATFORM:scarlett;BUILD:20251016-9e31c9f-dirty;VARIANT:unity;CONFIG:RelWithDebInfo;GDK_VERSION:250401;END

Changes

Testing

Verified three scenarios:

  1. With SDK version override: SENTRY_VERSION:0.11.3;BUILD:20251016-9e31c9f-dirty
  2. Without override (default): SENTRY_VERSION:0.11.3;BUILD:20251017-132848 (timestamp in YYYYMMDD-HHMMSS format)
  3. With explicit BUILD_ID: SENTRY_VERSION:0.11.3;BUILD:custom-id

All embedded info tests pass ✓

Python integration tests added:

  • test_sdk_version_override: Verifies build ID extraction from version string
  • test_sdk_version_override_with_explicit_build_id: Verifies explicit build ID takes precedence

🤖 Generated with Claude Code

vaind and others added 8 commits October 17, 2025 15:18
When downstream SDKs modify sentry.h to include build metadata in the
version string (e.g., 0.11.3+20251016-9e31c9f-dirty), the embedded
library info now automatically extracts the build ID from the version.

Changes:
- Parse build metadata from SENTRY_VERSION_FULL if present
- Use base version (major.minor.patch) for SENTRY_VERSION field
- Use extracted build ID for BUILD field
- SENTRY_BUILD_ID cache variable still takes precedence
- Update template to use new SENTRY_EMBEDDED_VERSION and SENTRY_EMBEDDED_BUILD_ID
- Update tests to validate base version format
- Add test for build ID field

This ensures the embedded info format is:
SENTRY_VERSION:0.11.3;BUILD:20251016-9e31c9f-dirty
instead of:
SENTRY_VERSION:0.11.3+20251016-9e31c9f-dirty;BUILD:0.11.3+20251016-9e31c9f-dirty

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

Co-Authored-By: Claude <noreply@anthropic.com>
…_VERSION

Simplifies the code by reusing the existing SENTRY_VERSION_BASE variable
which already contains the major.minor.patch format without build metadata.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Optimizes the logic to check SENTRY_BUILD_ID cache variable first.
Only attempts to extract build ID from version string if not explicitly provided.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Cleaner and more readable conditional structure.

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

Co-Authored-By: Claude <noreply@anthropic.com>
According to semver.org spec, build metadata must contain only ASCII
alphanumerics and hyphens [0-9A-Za-z-]. Spaces are not allowed.

Changed from: "2025-10-17 10:59:00 UTC"
Changed to: "20251017-105900"

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

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Downstream SDKs can now override the SDK version at CMake configuration time
using -DSENTRY_SDK_VERSION="version+build-id". This allows setting the version
without modifying sentry.h.

When SENTRY_SDK_VERSION is set:
- The full version (with build metadata) is used for embedded library info
- Build ID is automatically extracted from the version string
- sentry.h uses the overridden version via compile definition
- Version parsing happens at CMake configuration time

Example usage:
cmake -DSENTRY_SDK_VERSION="0.11.3+20251016-9e31c9f-dirty" ...

Results in embedded info:
SENTRY_VERSION:0.11.3;BUILD:20251016-9e31c9f-dirty;...

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

Co-Authored-By: Claude <noreply@anthropic.com>
Aligns with the pattern used for SENTRY_SDK_NAME check.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Oct 17, 2025

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

Generated by 🚫 dangerJS against 30c6ab4

vaind and others added 3 commits October 17, 2025 15:24
Added two new integration tests:

1. test_sdk_version_override: Verifies that setting SENTRY_SDK_VERSION
   correctly separates version and build ID in the embedded library info.

2. test_sdk_version_override_with_explicit_build_id: Verifies that
   explicit SENTRY_BUILD_ID takes precedence over extracted build ID
   from the version string.

Both tests inspect the actual binary using the strings command to
validate the embedded information.

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

Co-Authored-By: Claude <noreply@anthropic.com>
The #ifndef guard adds leading whitespace to the #define line, so the
regex needs to handle optional leading whitespace and whitespace between
tokens.

This fixes the issue where CMake couldn't parse the version from sentry.h
when SENTRY_SDK_VERSION was not overridden.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@vaind vaind marked this pull request as ready for review October 17, 2025 15:58
@vaind
Copy link
Contributor Author

vaind commented Oct 17, 2025

the failing test is unrelated to the changes in this PR. see #1418

@vaind vaind requested a review from supervacuus October 17, 2025 15:59
Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

Looks very sensible.

@vaind vaind merged commit 516c150 into master Oct 20, 2025
40 checks passed
@vaind vaind deleted the feat/sdk-version-override-for-downstream branch October 20, 2025 14:29
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