Skip to content

Commit bfbc74b

Browse files
committed
Set the library version reported via CMake to 6.1.0-dev.
This PR updates the version reported when using CMake (i.e. when building in the toolchain) to 6.1.0-dev with optional trailing git status information, if available. The resulting string looks like: > 6.1.0-dev (0.0.0-initial-532-gd01c406 - modified) "0.0.0-initial-532-gd01c406" in this example refers to the most recent commit on the branch I was testing on via `git describe --tags`, 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.)
1 parent d01c406 commit bfbc74b

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

cmake/modules/LibraryVersion.cmake

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,37 @@
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.0-dev")
12+
913
find_package(Git QUIET)
1014
if(Git_FOUND)
15+
# Look for a tag (including non-annotated, i.e. commit-specific, ones.)
1116
execute_process(
12-
COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match
17+
COMMAND ${GIT_EXECUTABLE} describe --tags
1318
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
14-
OUTPUT_VARIABLE GIT_TAG
19+
OUTPUT_VARIABLE GIT_VERSION
1520
OUTPUT_STRIP_TRAILING_WHITESPACE
1621
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()
22+
23+
# Check if there are local changes.
24+
execute_process(
25+
COMMAND ${GIT_EXECUTABLE} status -s
26+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
27+
OUTPUT_VARIABLE GIT_STATUS
28+
OUTPUT_STRIP_TRAILING_WHITESPACE)
29+
if(GIT_STATUS)
30+
set(GIT_VERSION "${GIT_VERSION} - modified")
3831
endif()
3932
endif()
33+
34+
# Combine the hard-coded Swift version with available Git information.
35+
if(GIT_VERSION)
36+
set(SWT_TESTING_LIBRARY_VERSION "${SWT_TESTING_LIBRARY_VERSION} (${GIT_VERSION})")
37+
endif()
38+
39+
# All done!
40+
message(STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION}")
41+
add_compile_definitions(
42+
"$<$<COMPILE_LANGUAGE:CXX>:_SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">")

0 commit comments

Comments
 (0)