Skip to content

Commit 1be2d32

Browse files
ShadowNinjaest31
authored andcommitted
Make Git version detection use VERSION_STRING instead of tags
This fixes the problem where 0.4.12-dev versions were erroneously shown as 0.4.11-dev because the tag was added on a separate branch. It also fixes a similar issue when builders didn't fetch new tags when updating. This also removes the number-of-commits-since-tag field, since it's incompatible with this. Said field doesn't seem to be useful anyway if you have the commit hash.
1 parent dfd7909 commit 1be2d32

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ set(VERSION_MINOR 4)
1616
set(VERSION_PATCH 12)
1717
set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
1818

19+
# Change to false for releases
20+
set(DEVELOPMENT_BUILD TRUE)
21+
1922
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
2023
if(VERSION_EXTRA)
2124
set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
22-
else()
23-
# Comment the following line during release
25+
elseif(DEVELOPMENT_BUILD)
2426
set(VERSION_STRING "${VERSION_STRING}-dev")
2527
endif()
2628

cmake/Modules/GenerateVersion.cmake

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
# Always run during 'make'
22

3-
if(VERSION_EXTRA)
4-
set(VERSION_GITHASH "${VERSION_STRING}")
5-
else()
6-
execute_process(COMMAND git describe --tag --dirty
3+
if(DEVELOPMENT_BUILD)
4+
execute_process(COMMAND git rev-parse --short HEAD
75
WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}"
86
OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE
97
ERROR_QUIET)
10-
118
if(VERSION_GITHASH)
12-
message(STATUS "*** Detected Git version ${VERSION_GITHASH} ***")
13-
else()
14-
execute_process(COMMAND git describe --always --tag --dirty
9+
set(VERSION_GITHASH "${VERSION_STRING}-${VERSION_GITHASH}")
10+
execute_process(COMMAND git diff-index --quiet HEAD
1511
WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}"
16-
OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE
17-
ERROR_QUIET)
18-
if(VERSION_GITHASH)
19-
set(VERSION_GITHASH "${VERSION_STRING}-${VERSION_GITHASH}")
20-
message(STATUS "*** Detected shallow Git version ${VERSION_GITHASH} ***")
21-
else()
22-
set(VERSION_GITHASH "${VERSION_STRING}")
12+
RESULT_VARIABLE IS_DIRTY)
13+
if(IS_DIRTY)
14+
set(VERSION_GITHASH "${VERSION_GITHASH}-dirty")
2315
endif()
16+
message(STATUS "*** Detected Git version ${VERSION_GITHASH} ***")
2417
endif()
2518
endif()
19+
if(NOT VERSION_GITHASH)
20+
set(VERSION_GITHASH "${VERSION_STRING}")
21+
endif()
2622

2723
configure_file(
2824
${GENERATE_VERSION_SOURCE_DIR}/cmake_config_githash.h.in

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ add_custom_target(GenerateVersion
269269
-D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
270270
-D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
271271
-D "VERSION_STRING=${VERSION_STRING}"
272-
-D "VERSION_EXTRA=${VERSION_EXTRA}"
272+
-D "DEVELOPMENT_BUILD=${DEVELOPMENT_BUILD}"
273273
-P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateVersion.cmake"
274274
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
275275

util/bump_version.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEW_VERSION_MINOR
8787

8888
sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEW_VERSION_PATCH)/" CMakeLists.txt || die "Failed to update VERSION_PATCH"
8989

90-
sed -i -re "s/^\tset\(VERSION_PATCH \\\$.VERSION_PATCH}-dev\)$/\t#set(VERSION_PATCH \${VERSION_PATCH}-dev)/" CMakeLists.txt || die "Failed to disable -dev suffix"
90+
sed -i -re "s/^set\(DEVELOPMENT_BUILD TRUE\)$/set(DEVELOPMENT_BUILD FALSE)/" CMakeLists.txt || die "Failed to unset DEVELOPMENT_BUILD"
9191

9292
sed -i -re "s/^ANDROID_VERSION_CODE = [0-9]+$/ANDROID_VERSION_CODE = $NEW_ANDROID_VERSION_CODE/" build/android/Makefile || die "Failed to update ANDROID_VERSION_CODE"
9393

@@ -98,3 +98,24 @@ sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" doc/menu_lua_api.txt || di
9898
git add -f CMakeLists.txt build/android/Makefile doc/lua_api.txt doc/menu_lua_api.txt || die "git add failed"
9999

100100
git commit -m "Bump version to $NEW_VERSION" || die "git commit failed"
101+
102+
############
103+
# Create tag
104+
############
105+
106+
echo "Tagging $NEW_VERSION"
107+
108+
git tag -a "$NEW_VERSION" -m "$NEW_VERSION" || die 'Adding tag failed'
109+
110+
######################
111+
# Create revert commit
112+
######################
113+
114+
echo 'Creating "revert to development" commit'
115+
116+
sed -i -re 's/^set\(DEVELOPMENT_BUILD FALSE\)$/set(DEVELOPMENT_BUILD TRUE)/' CMakeLists.txt || die 'Failed to set DEVELOPMENT_BUILD'
117+
118+
git add -f CMakeLists.txt || die 'git add failed'
119+
120+
git commit -m "Continue with $NEW_VERSION-dev" || die 'git commit failed'
121+

0 commit comments

Comments
 (0)