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

Provide version information in DLL #1076

Merged
merged 12 commits into from
Nov 12, 2024
22 changes: 18 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
# Changelog

## Unreleased

**Features**:

- Provide version information for non-static Windows binaries. ([#1076](https://github.com/getsentry/sentry-native/pull/1076), [crashpad#110](https://github.com/getsentry/crashpad/pull/110))

**Thank you**:

[olback](https://github.com/olback)

## 0.7.12

**Features**:

- Add `sentry_capture_minidump()` to capture independently created minidumps ([#1067](https://github.com/getsentry/sentry-native/pull/1067))
- Add `sentry_capture_minidump()` to capture independently created minidumps. ([#1067](https://github.com/getsentry/sentry-native/pull/1067))

**Fixes**:

- Add breadcrumb ringbuffer to avoid O(n) memmove on adding more than max breadcrumbs ([#1060](https://github.com/getsentry/sentry-native/pull/1060))
- Add breadcrumb ringbuffer to avoid O(n) memmove on adding more than max breadcrumbs. ([#1060](https://github.com/getsentry/sentry-native/pull/1060))

## 0.7.11

**Fixes**:

- Reject invalid trace- and span-ids in context update from header ([#1046](https://github.com/getsentry/sentry-native/pull/1046))
- Reject invalid trace- and span-ids in context update from header. ([#1046](https://github.com/getsentry/sentry-native/pull/1046))
- Lookup `GetSystemTimePreciseAsFileTime()` at runtime and fall back to `GetSystemTimeAsFileTime()` to allow running on Windows < 8. ([#1051](https://github.com/getsentry/sentry-native/pull/1051))
- Allow for empty DSN to still initialize crash handler ([#1059](https://github.com/getsentry/sentry-native/pull/1059))
- Allow for empty DSN to still initialize crash handler. ([#1059](https://github.com/getsentry/sentry-native/pull/1059))

## 0.7.10

**Fixes**:

- Correct the timestamp resolution to microseconds on Windows. ([#1039](https://github.com/getsentry/sentry-native/pull/1039))

**Thank you**:

- [ShawnCZek](https://github.com/ShawnCZek)

## 0.7.9

**Fixes**:
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ if(WIN32)
endif()
endif()

include(cmake/utils.cmake)
if (WIN32 AND SENTRY_BUILD_SHARED_LIBS)
sentry_add_version_resource(sentry "Client Library")
endif()

# handle platform libraries
if(ANDROID)
set(_SENTRY_PLATFORM_LIBS "dl" "log")
Expand Down
21 changes: 21 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generates a version resource file from the `sentry.rc.in` template for the `TGT` argument and adds it as a source.
function(sentry_add_version_resource TGT FILE_DESCRIPTION)
# generate a resource output-path from the target name
set(RESOURCE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TGT}.rc")
set(RESOURCE_PATH_TMP "${RESOURCE_PATH}.in")

# Extract major, minor and patch version from SENTRY_VERSION
string(REPLACE "." ";" _SENTRY_VERSION_LIST "${SENTRY_VERSION}")
list(GET _SENTRY_VERSION_LIST 0 SENTRY_VERSION_MAJOR)
list(GET _SENTRY_VERSION_LIST 1 SENTRY_VERSION_MINOR)
list(GET _SENTRY_VERSION_LIST 2 SENTRY_VERSION_PATCH)

# Produce the resource file with configure-time replacements
configure_file("${CMAKE_SOURCE_DIR}/sentry.rc.in" "${RESOURCE_PATH_TMP}" @ONLY)

# Replace the `ORIGINAL_FILENAME` at generate-time using the generator expression `TARGET_FILE_NAME`
file(GENERATE OUTPUT ${RESOURCE_PATH} INPUT ${RESOURCE_PATH_TMP})

# Finally add the generated resource file to the target sources
target_sources("${TGT}" PRIVATE "${RESOURCE_PATH}")
endfunction()
2 changes: 1 addition & 1 deletion external/crashpad
1 change: 1 addition & 0 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ perl -pi -e "s/^#define SENTRY_SDK_VERSION.*/#define SENTRY_SDK_VERSION \"${NEW_
perl -pi -e "s/\"version\": \"[^\"]+\"/\"version\": \"${NEW_VERSION}\"/" tests/assertions.py
perl -pi -e "s/sentry.native\/[^\"]+\"/sentry.native\/${NEW_VERSION}\"/" tests/test_integration_http.py
perl -pi -e "s/^versionName\=.*/versionName\=${NEW_VERSION}/" ndk/gradle.properties
perl -pi -e "s/^sentry_version \=.*/sentry_version \= \"${NEW_VERSION}\"/" tests/win_utils.py
22 changes: 22 additions & 0 deletions sentry.rc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1 VERSIONINFO
FILEVERSION @SENTRY_VERSION_MAJOR@,@SENTRY_VERSION_MINOR@,@SENTRY_VERSION_PATCH@,0
PRODUCTVERSION @SENTRY_VERSION_MAJOR@,@SENTRY_VERSION_MINOR@,@SENTRY_VERSION_PATCH@,0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "FileDescription", "@FILE_DESCRIPTION@"
VALUE "FileVersion", "@SENTRY_VERSION@"
VALUE "InternalName", "sentry-native"
VALUE "LegalCopyright", "https://sentry.io"
VALUE "OriginalFilename", "$<TARGET_FILE_NAME:@TGT@>"
VALUE "ProductName", "Sentry Native SDK"
VALUE "ProductVersion", "@SENTRY_VERSION@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1252
END
END
10 changes: 10 additions & 0 deletions tests/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import shutil
import subprocess
import sys
import platform
from pathlib import Path

import pytest

Expand Down Expand Up @@ -204,6 +206,14 @@ def cmake(cwd, targets, options=None):
except subprocess.CalledProcessError:
raise pytest.fail.Exception("cmake build failed") from None

# check if the DLL and EXE artifacts contain version-information
if platform.system() == "Windows":
from tests.win_utils import check_binary_version

check_binary_version(Path(cwd) / "sentry.dll")
check_binary_version(Path(cwd) / "crashpad_wer.dll")
check_binary_version(Path(cwd) / "crashpad_handler.exe")

if "code-checker" in os.environ.get("RUN_ANALYZER", ""):
# For whatever reason, the compilation summary contains duplicate entries,
# one with the correct absolute path, and the other one just with the basename,
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-httpserver==1.0.10
msgpack==1.0.8
pytest-xdist==3.5.0
clang-format==19.1.3
pywin32==308; sys_platform == "win32"
2 changes: 2 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sentry_get_property(INCLUDE_DIRECTORIES)
sentry_get_property(LINK_LIBRARIES)
sentry_get_property(INTERFACE_LINK_LIBRARIES)

list(FILTER SENTRY_SOURCES EXCLUDE REGEX "\\.rc$")

add_executable(sentry_test_unit
${SENTRY_SOURCES}
main.c
Expand Down
19 changes: 19 additions & 0 deletions tests/win_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pathlib
import win32api

sentry_version = "0.7.12"


def check_binary_version(binary_path: pathlib.Path):
if not binary_path.exists():
return

info = win32api.GetFileVersionInfo(str(binary_path), "\\")
ms = info["FileVersionMS"]
ls = info["FileVersionLS"]
file_version = (ms >> 16, ms & 0xFFFF, ls >> 16, ls & 0xFFFF)
file_version = f"{file_version[0]}.{file_version[1]}.{file_version[2]}"
if sentry_version != file_version:
raise RuntimeError(
f"Binary {binary_path.parts[-1]} has a different version ({file_version}) than expected ({sentry_version})."
)
Loading