From e0be19d297aeeef88d90fa5dc1352c56d57efcab Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Thu, 22 Aug 2024 09:29:08 -0400 Subject: [PATCH 1/2] 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.) --- cmake/modules/LibraryVersion.cmake | 49 ++++++++++++++++-------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/cmake/modules/LibraryVersion.cmake b/cmake/modules/LibraryVersion.cmake index 9713175c4..3fc8444e7 100644 --- a/cmake/modules/LibraryVersion.cmake +++ b/cmake/modules/LibraryVersion.cmake @@ -6,34 +6,37 @@ # See http://swift.org/LICENSE.txt for license information # See http://swift.org/CONTRIBUTORS.txt for Swift project authors +# The current version of the Swift Testing release. For release branches, +# remember to remove -dev. +set(SWT_TESTING_LIBRARY_VERSION "6.1.0-dev") + find_package(Git QUIET) if(Git_FOUND) + # Look for a tag (including non-annotated, i.e. commit-specific, ones.) execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match + COMMAND ${GIT_EXECUTABLE} describe --tags WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_TAG + OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) - if(GIT_TAG) - add_compile_definitions( - "$<$:_SWT_TESTING_LIBRARY_VERSION=${GIT_TAG}>") - else() - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse --verify HEAD - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_REVISION - OUTPUT_STRIP_TRAILING_WHITESPACE) - execute_process( - COMMAND ${GIT_EXECUTABLE} status -s - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - OUTPUT_VARIABLE GIT_STATUS - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(GIT_STATUS) - add_compile_definitions( - "$<$:_SWT_TESTING_LIBRARY_VERSION=${GIT_REVISION} (modified)>") - else() - add_compile_definitions( - "$<$:_SWT_TESTING_LIBRARY_VERSION=${GIT_REVISION}>") - endif() + + # Check if there are local changes. + execute_process( + COMMAND ${GIT_EXECUTABLE} status -s + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_STATUS + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(GIT_STATUS) + set(GIT_VERSION "${GIT_VERSION} - modified") endif() endif() + +# Combine the hard-coded Swift version with available Git information. +if(GIT_VERSION) +set(SWT_TESTING_LIBRARY_VERSION "${SWT_TESTING_LIBRARY_VERSION} (${GIT_VERSION})") +endif() + +# All done! +message(STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION}") +add_compile_definitions( + "$<$:_SWT_TESTING_LIBRARY_VERSION=\"${SWT_TESTING_LIBRARY_VERSION}\">") From c6450e02cc76cd76484cc8ebc72b4254656ae7ea Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Thu, 22 Aug 2024 11:06:37 -0400 Subject: [PATCH 2/2] Tweak format to match swift --version more closely --- cmake/modules/LibraryVersion.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/modules/LibraryVersion.cmake b/cmake/modules/LibraryVersion.cmake index 3fc8444e7..e4e7fe24e 100644 --- a/cmake/modules/LibraryVersion.cmake +++ b/cmake/modules/LibraryVersion.cmake @@ -8,13 +8,14 @@ # The current version of the Swift Testing release. For release branches, # remember to remove -dev. -set(SWT_TESTING_LIBRARY_VERSION "6.1.0-dev") +set(SWT_TESTING_LIBRARY_VERSION "6.1-dev") find_package(Git QUIET) if(Git_FOUND) - # Look for a tag (including non-annotated, i.e. commit-specific, ones.) + # Get the commit hash corresponding to the current build. Limit length to 15 + # to match `swift --version` output format. execute_process( - COMMAND ${GIT_EXECUTABLE} describe --tags + COMMAND ${GIT_EXECUTABLE} rev-parse --short=15 --verify HEAD WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE