Skip to content

Commit 5a7a3d2

Browse files
cmake: Update versioning scheme (cvc5#12116)
The current versioning scheme follows the format: ``` <version-in-last-tag>-dev.<number-of-commits-since-last-tag>.<commit-sha>[-modified] ``` This leads to two main practical issues: 1. To retrieve `<number-of-commits-since-last-tag>`, a clone of the repository with access to the full Git history is required. This is not always desirable, since it introduces unnecessary overhead. For example, the GitHub `checkout` action retrieves only the latest commit by default. When this information is not available, the build system does not include other useful details such as the branch name or commit SHA in the `CVC5_GIT_INFO` constant. 2. Even when the full history is available, the list of tags may not be. This is common when a user or developer works on their own fork of the repository. This PR changes the format to: ``` <latest-release-version>-dev.<branch-name>@<commit-sha>[-modified] ``` This makes the version scheme more robust when the Git history or list of tags is not available. In addition, this PR preserves the old behavior of incrementing the patch version by one when a development version is detected.
1 parent e0ec61e commit 5a7a3d2

File tree

1 file changed

+48
-53
lines changed

1 file changed

+48
-53
lines changed

cmake/version.cmake

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,48 @@ endif()
3636
# include basic version information
3737
include(version-base)
3838

39+
if(CVC5_IS_RELEASE STREQUAL "false")
40+
# increment patch part of version (CVC5_LAST_RELEASE + 0.0.1)
41+
set(NEXT_CVC5_VERSION ${CVC5_LAST_RELEASE})
42+
string(REGEX MATCHALL "[0-9]+" VERSION_LIST "${NEXT_CVC5_VERSION}")
43+
list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
44+
# append .0 until we have a patch part
45+
while(VERSION_LIST_LENGTH LESS "3")
46+
list(APPEND VERSION_LIST "0")
47+
list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
48+
endwhile()
49+
# increment patch part
50+
list(GET VERSION_LIST 2 VERSION_LAST_NUMBER)
51+
list(REMOVE_AT VERSION_LIST 2)
52+
math(EXPR VERSION_LAST_NUMBER "${VERSION_LAST_NUMBER} + 1")
53+
list(APPEND VERSION_LIST ${VERSION_LAST_NUMBER})
54+
# join version string into NEXT_CVC5_VERSION
55+
list(GET VERSION_LIST 0 NEXT_CVC5_VERSION)
56+
while(VERSION_LIST_LENGTH GREATER "1")
57+
list(REMOVE_AT VERSION_LIST 0)
58+
list(GET VERSION_LIST 0 TMP)
59+
set(NEXT_CVC5_VERSION "${NEXT_CVC5_VERSION}.${TMP}")
60+
list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
61+
endwhile()
62+
63+
set(CVC5_VERSION "${NEXT_CVC5_VERSION}-dev")
64+
set(CVC5_FULL_VERSION "${NEXT_CVC5_VERSION}-dev")
65+
endif()
66+
3967
# now use git to retrieve additional version information
4068
find_package(Git)
4169
if(GIT_FOUND)
4270
# git is available
4371

44-
# call git describe. If result is not 0 this is not a git repository
72+
# Call git. If result is 0 and prints "true", it is a git repository
4573
execute_process(
46-
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} describe --long --tags --match cvc5-*
74+
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} rev-parse --is-inside-work-tree
4775
RESULT_VARIABLE GIT_RESULT
48-
OUTPUT_VARIABLE GIT_DESCRIBE
76+
OUTPUT_VARIABLE GIT_INSIDE_WORK_TREE
4977
OUTPUT_STRIP_TRAILING_WHITESPACE
5078
)
5179

52-
if(GIT_RESULT EQUAL 0)
80+
if(GIT_RESULT EQUAL 0 AND GIT_INSIDE_WORK_TREE STREQUAL "true")
5381
# it is a git working copy
5482

5583
set(GIT_BUILD "true")
@@ -60,66 +88,33 @@ if(GIT_FOUND)
6088
OUTPUT_VARIABLE GIT_BRANCH
6189
OUTPUT_STRIP_TRAILING_WHITESPACE
6290
)
91+
# get current git commit
92+
execute_process(
93+
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} rev-parse --short HEAD
94+
RESULT_VARIABLE GIT_RESULT
95+
OUTPUT_VARIABLE GIT_COMMIT
96+
OUTPUT_STRIP_TRAILING_WHITESPACE
97+
)
98+
99+
if(CVC5_IS_RELEASE STREQUAL "false")
100+
set(CVC5_FULL_VERSION "${CVC5_FULL_VERSION}-${GIT_BRANCH}@${GIT_COMMIT}")
101+
endif()
102+
63103
# result is != 0 if worktree is dirty
64104
# note: git diff HEAD shows both staged and unstaged changes.
65105
execute_process(
66-
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} diff HEAD --quiet
106+
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} diff-index --quiet HEAD
67107
RESULT_VARIABLE GIT_RESULT
68108
)
69109
if(GIT_RESULT EQUAL 0)
70110
set(GIT_DIRTY_MSG "")
71111
else()
72112
set(GIT_DIRTY_MSG " with local modifications")
113+
set(CVC5_VERSION "${CVC5_VERSION}-modified")
114+
set(CVC5_FULL_VERSION "${CVC5_FULL_VERSION}-modified")
73115
endif()
74116

75-
string(REGEX MATCH "^cvc5-([0-9.]+)-([0-9]+)-g([0-9a-f]+)$" MATCH "${GIT_DESCRIBE}")
76-
if(NOT MATCH)
77-
message(SEND_ERROR "Unexpected format from 'git describe': '${GIT_DESCRIBE}'")
78-
endif()
79-
set(GIT_LAST_TAG "${CMAKE_MATCH_1}")
80-
set(GIT_COMMITS_SINCE_TAG "${CMAKE_MATCH_2}")
81-
set(GIT_COMMIT "${CMAKE_MATCH_3}")
82-
83-
if(GIT_COMMITS_SINCE_TAG EQUAL "0")
84-
# this version *is* a tag
85-
set(CVC5_IS_RELEASE "true")
86-
set(CVC5_VERSION "${GIT_LAST_TAG}")
87-
set(CVC5_FULL_VERSION "${GIT_LAST_TAG}")
88-
set(CVC5_GIT_INFO "git tag ${GIT_LAST_TAG} branch ${GIT_BRANCH}${GIT_DIRTY_MSG}")
89-
else()
90-
# this version is not a tag
91-
92-
# increment patch part of version
93-
string(REGEX MATCHALL "[0-9]+" VERSION_LIST "${GIT_LAST_TAG}")
94-
list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
95-
# append .0 until we have a patch part
96-
while(VERSION_LIST_LENGTH LESS "3")
97-
list(APPEND VERSION_LIST "0")
98-
list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
99-
endwhile()
100-
# increment patch part
101-
list(GET VERSION_LIST 2 VERSION_LAST_NUMBER)
102-
list(REMOVE_AT VERSION_LIST 2)
103-
math(EXPR VERSION_LAST_NUMBER "${VERSION_LAST_NUMBER} + 1")
104-
list(APPEND VERSION_LIST ${VERSION_LAST_NUMBER})
105-
# join version string into GIT_LAST_TAG
106-
list(GET VERSION_LIST 0 GIT_LAST_TAG)
107-
while(VERSION_LIST_LENGTH GREATER "1")
108-
list(REMOVE_AT VERSION_LIST 0)
109-
list(GET VERSION_LIST 0 TMP)
110-
set(GIT_LAST_TAG "${GIT_LAST_TAG}.${TMP}")
111-
list(LENGTH VERSION_LIST VERSION_LIST_LENGTH)
112-
endwhile()
113-
114-
if(CVC5_IS_RELEASE)
115-
set(CVC5_VERSION "${CVC5_VERSION}-modified")
116-
set(CVC5_FULL_VERSION "${CVC5_FULL_VERSION}-modified")
117-
else()
118-
set(CVC5_VERSION "${GIT_LAST_TAG}-dev")
119-
set(CVC5_FULL_VERSION "${GIT_LAST_TAG}-dev.${GIT_COMMITS_SINCE_TAG}.${GIT_COMMIT}")
120-
endif()
121-
set(CVC5_GIT_INFO "git ${GIT_COMMIT} on branch ${GIT_BRANCH}${GIT_DIRTY_MSG}")
122-
endif()
117+
set(CVC5_GIT_INFO "git ${GIT_COMMIT} on branch ${GIT_BRANCH}${GIT_DIRTY_MSG}")
123118
endif()
124119
endif()
125120

0 commit comments

Comments
 (0)