Skip to content

Commit 7a882d3

Browse files
olbacksupervacuus
andauthored
Provide version information in DLL (#1076)
* Provide version information in DLL * Update changelog * only include rc file when building dll * move rc code gen, change product name, make FileVersion the same as ProductVersion * Further clean-ups and reuse for crashpad * moved code to utility function * that function uses the target argument to generate all required files (only manual parameter is the file description) * switched from manual string replacement to `configure_file()` which creates another intermediate file * to generate the final *.rc file we use file(GENERATE) together with `TARGET_FILE_NAME` generator expression to retrieve "OriginFilename" during the generate-time (between configure and build phase). * ensure that unit-tests don't pick up unnecessary resource-sources * update changelog * update changelog * replace `TARGET` parameter with `TGT` for good measure * add test-fixture checks for binaries * conditionally include windows-specific module * don't include utils.cmake only for shared-libs build... ...because even if we generate static client libraries crashpad_handler.exe and crashpad_wer.dll should still be versioned. * update crashpad submodule to getsentry ref --------- Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
1 parent d241dbc commit 7a882d3

File tree

10 files changed

+100
-5
lines changed

10 files changed

+100
-5
lines changed

CHANGELOG.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Features**:
6+
7+
- 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))
8+
9+
**Thank you**:
10+
11+
[olback](https://github.com/olback)
12+
313
## 0.7.12
414

515
**Features**:
616

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

919
**Fixes**:
1020

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

1323
## 0.7.11
1424

1525
**Fixes**:
1626

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

2131
## 0.7.10
2232

2333
**Fixes**:
2434

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

37+
**Thank you**:
38+
39+
- [ShawnCZek](https://github.com/ShawnCZek)
40+
2741
## 0.7.9
2842

2943
**Fixes**:

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ if(WIN32)
369369
endif()
370370
endif()
371371

372+
include(cmake/utils.cmake)
373+
if (WIN32 AND SENTRY_BUILD_SHARED_LIBS)
374+
sentry_add_version_resource(sentry "Client Library")
375+
endif()
376+
372377
# handle platform libraries
373378
if(ANDROID)
374379
set(_SENTRY_PLATFORM_LIBS "dl" "log")

cmake/utils.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generates a version resource file from the `sentry.rc.in` template for the `TGT` argument and adds it as a source.
2+
function(sentry_add_version_resource TGT FILE_DESCRIPTION)
3+
# generate a resource output-path from the target name
4+
set(RESOURCE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TGT}.rc")
5+
set(RESOURCE_PATH_TMP "${RESOURCE_PATH}.in")
6+
7+
# Extract major, minor and patch version from SENTRY_VERSION
8+
string(REPLACE "." ";" _SENTRY_VERSION_LIST "${SENTRY_VERSION}")
9+
list(GET _SENTRY_VERSION_LIST 0 SENTRY_VERSION_MAJOR)
10+
list(GET _SENTRY_VERSION_LIST 1 SENTRY_VERSION_MINOR)
11+
list(GET _SENTRY_VERSION_LIST 2 SENTRY_VERSION_PATCH)
12+
13+
# Produce the resource file with configure-time replacements
14+
configure_file("${CMAKE_SOURCE_DIR}/sentry.rc.in" "${RESOURCE_PATH_TMP}" @ONLY)
15+
16+
# Replace the `ORIGINAL_FILENAME` at generate-time using the generator expression `TARGET_FILE_NAME`
17+
file(GENERATE OUTPUT ${RESOURCE_PATH} INPUT ${RESOURCE_PATH_TMP})
18+
19+
# Finally add the generated resource file to the target sources
20+
target_sources("${TGT}" PRIVATE "${RESOURCE_PATH}")
21+
endfunction()

external/crashpad

scripts/bump-version.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ perl -pi -e "s/^#define SENTRY_SDK_VERSION.*/#define SENTRY_SDK_VERSION \"${NEW_
1818
perl -pi -e "s/\"version\": \"[^\"]+\"/\"version\": \"${NEW_VERSION}\"/" tests/assertions.py
1919
perl -pi -e "s/sentry.native\/[^\"]+\"/sentry.native\/${NEW_VERSION}\"/" tests/test_integration_http.py
2020
perl -pi -e "s/^versionName\=.*/versionName\=${NEW_VERSION}/" ndk/gradle.properties
21+
perl -pi -e "s/^sentry_version \=.*/sentry_version \= \"${NEW_VERSION}\"/" tests/win_utils.py

sentry.rc.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
1 VERSIONINFO
2+
FILEVERSION @SENTRY_VERSION_MAJOR@,@SENTRY_VERSION_MINOR@,@SENTRY_VERSION_PATCH@,0
3+
PRODUCTVERSION @SENTRY_VERSION_MAJOR@,@SENTRY_VERSION_MINOR@,@SENTRY_VERSION_PATCH@,0
4+
BEGIN
5+
BLOCK "StringFileInfo"
6+
BEGIN
7+
BLOCK "040904E4"
8+
BEGIN
9+
VALUE "FileDescription", "@FILE_DESCRIPTION@"
10+
VALUE "FileVersion", "@SENTRY_VERSION@"
11+
VALUE "InternalName", "sentry-native"
12+
VALUE "LegalCopyright", "https://sentry.io"
13+
VALUE "OriginalFilename", "$<TARGET_FILE_NAME:@TGT@>"
14+
VALUE "ProductName", "Sentry Native SDK"
15+
VALUE "ProductVersion", "@SENTRY_VERSION@"
16+
END
17+
END
18+
BLOCK "VarFileInfo"
19+
BEGIN
20+
VALUE "Translation", 0x409, 1252
21+
END
22+
END

tests/cmake.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import shutil
44
import subprocess
55
import sys
6+
import platform
7+
from pathlib import Path
68

79
import pytest
810

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

209+
# check if the DLL and EXE artifacts contain version-information
210+
if platform.system() == "Windows":
211+
from tests.win_utils import check_binary_version
212+
213+
check_binary_version(Path(cwd) / "sentry.dll")
214+
check_binary_version(Path(cwd) / "crashpad_wer.dll")
215+
check_binary_version(Path(cwd) / "crashpad_handler.exe")
216+
207217
if "code-checker" in os.environ.get("RUN_ANALYZER", ""):
208218
# For whatever reason, the compilation summary contains duplicate entries,
209219
# one with the correct absolute path, and the other one just with the basename,

tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pytest-httpserver==1.0.10
44
msgpack==1.0.8
55
pytest-xdist==3.5.0
66
clang-format==19.1.3
7+
pywin32==308; sys_platform == "win32"

tests/unit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ sentry_get_property(INCLUDE_DIRECTORIES)
1313
sentry_get_property(LINK_LIBRARIES)
1414
sentry_get_property(INTERFACE_LINK_LIBRARIES)
1515

16+
list(FILTER SENTRY_SOURCES EXCLUDE REGEX "\\.rc$")
17+
1618
add_executable(sentry_test_unit
1719
${SENTRY_SOURCES}
1820
main.c

tests/win_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pathlib
2+
import win32api
3+
4+
sentry_version = "0.7.12"
5+
6+
7+
def check_binary_version(binary_path: pathlib.Path):
8+
if not binary_path.exists():
9+
return
10+
11+
info = win32api.GetFileVersionInfo(str(binary_path), "\\")
12+
ms = info["FileVersionMS"]
13+
ls = info["FileVersionLS"]
14+
file_version = (ms >> 16, ms & 0xFFFF, ls >> 16, ls & 0xFFFF)
15+
file_version = f"{file_version[0]}.{file_version[1]}.{file_version[2]}"
16+
if sentry_version != file_version:
17+
raise RuntimeError(
18+
f"Binary {binary_path.parts[-1]} has a different version ({file_version}) than expected ({sentry_version})."
19+
)

0 commit comments

Comments
 (0)