Skip to content

Commit a907113

Browse files
authored
Set the library version reported via CMake to 6.1-dev. (#637)
This PR updates the version reported when using CMake (i.e. when building in the toolchain) to `"6.1-dev"` with optional trailing git commit hash, if available. The resulting string looks like: > `6.1.0-dev (c6450e0 - modified)` "c6450e02cc76cd7" in this example refers to the most recent commit on the branch I was testing on via `git rev-parse --verify HEAD`, and "modified" is present because I had uncommitted changes. (We'll want to double-check that CMake used in CI can see the git repository and has access to the git tool.) ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 9773daa commit a907113

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

Diff for: cmake/modules/LibraryVersion.cmake

+27-23
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,38 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
# The current version of the Swift Testing release. For release branches,
10+
# remember to remove -dev.
11+
set(SWT_TESTING_LIBRARY_VERSION "6.1-dev")
12+
913
find_package(Git QUIET)
1014
if(Git_FOUND)
15+
# Get the commit hash corresponding to the current build. Limit length to 15
16+
# to match `swift --version` output format.
1117
execute_process(
12-
COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match
18+
COMMAND ${GIT_EXECUTABLE} rev-parse --short=15 --verify HEAD
1319
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
14-
OUTPUT_VARIABLE GIT_TAG
20+
OUTPUT_VARIABLE GIT_VERSION
1521
OUTPUT_STRIP_TRAILING_WHITESPACE
1622
ERROR_QUIET)
17-
if(GIT_TAG)
18-
add_compile_definitions(
19-
"$<$<COMPILE_LANGUAGE:CXX>:_SWT_TESTING_LIBRARY_VERSION=${GIT_TAG}>")
20-
else()
21-
execute_process(
22-
COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD
23-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
24-
OUTPUT_VARIABLE GIT_REVISION
25-
OUTPUT_STRIP_TRAILING_WHITESPACE)
26-
execute_process(
27-
COMMAND ${GIT_EXECUTABLE} status -s
28-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
29-
OUTPUT_VARIABLE GIT_STATUS
30-
OUTPUT_STRIP_TRAILING_WHITESPACE)
31-
if(GIT_STATUS)
32-
add_compile_definitions(
33-
"$<$<COMPILE_LANGUAGE:CXX>:_SWT_TESTING_LIBRARY_VERSION=${GIT_REVISION} (modified)>")
34-
else()
35-
add_compile_definitions(
36-
"$<$<COMPILE_LANGUAGE:CXX>:_SWT_TESTING_LIBRARY_VERSION=${GIT_REVISION}>")
37-
endif()
23+
24+
# Check if there are local changes.
25+
execute_process(
26+
COMMAND ${GIT_EXECUTABLE} status -s
27+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
28+
OUTPUT_VARIABLE GIT_STATUS
29+
OUTPUT_STRIP_TRAILING_WHITESPACE)
30+
if(GIT_STATUS)
31+
set(GIT_VERSION "${GIT_VERSION} - modified")
3832
endif()
3933
endif()
34+
35+
# Combine the hard-coded Swift version with available Git information.
36+
if(GIT_VERSION)
37+
set(SWT_TESTING_LIBRARY_VERSION "${SWT_TESTING_LIBRARY_VERSION} (${GIT_VERSION})")
38+
endif()
39+
40+
# All done!
41+
message(STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION}")
42+
add_compile_definitions(
43+
"$<$<COMPILE_LANGUAGE:CXX>:_SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">")

0 commit comments

Comments
 (0)