Make Git version detection use VERSION_STRING instead of tags
authorShadowNinja <shadowninja@minetest.net>
Mon, 4 May 2015 22:46:49 +0000 (18:46 -0400)
committerest31 <MTest31@outlook.com>
Tue, 5 May 2015 15:13:05 +0000 (17:13 +0200)
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.

CMakeLists.txt
cmake/Modules/GenerateVersion.cmake
src/CMakeLists.txt
util/bump_version.sh

index 639c070777229f03746650beac31aebdd69362ff..d1353e16c3f9761f4f19d02cea54e07af310bc37 100644 (file)
@@ -16,11 +16,13 @@ set(VERSION_MINOR 4)
 set(VERSION_PATCH 12)
 set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string")
 
+# Change to false for releases
+set(DEVELOPMENT_BUILD TRUE)
+
 set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
 if(VERSION_EXTRA)
        set(VERSION_STRING ${VERSION_STRING}-${VERSION_EXTRA})
-else()
-       # Comment the following line during release
+elseif(DEVELOPMENT_BUILD)
        set(VERSION_STRING "${VERSION_STRING}-dev")
 endif()
 
index 9b5304ad53939e32324cd24f5ce22519a832d998..ad0e38263be20c6b5d3dbdf5e8b70636834d6e00 100644 (file)
@@ -1,28 +1,24 @@
 # Always run during 'make'
 
-if(VERSION_EXTRA)
-       set(VERSION_GITHASH "${VERSION_STRING}")
-else()
-       execute_process(COMMAND git describe --tag --dirty
+if(DEVELOPMENT_BUILD)
+       execute_process(COMMAND git rev-parse --short HEAD
                WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}"
                OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE
                ERROR_QUIET)
-
        if(VERSION_GITHASH)
-               message(STATUS "*** Detected Git version ${VERSION_GITHASH} ***")
-       else()
-               execute_process(COMMAND git describe --always --tag --dirty
+               set(VERSION_GITHASH "${VERSION_STRING}-${VERSION_GITHASH}")
+               execute_process(COMMAND git diff-index --quiet HEAD
                        WORKING_DIRECTORY "${GENERATE_VERSION_SOURCE_DIR}"
-                       OUTPUT_VARIABLE VERSION_GITHASH OUTPUT_STRIP_TRAILING_WHITESPACE
-                       ERROR_QUIET)
-               if(VERSION_GITHASH)
-                       set(VERSION_GITHASH "${VERSION_STRING}-${VERSION_GITHASH}")
-                       message(STATUS "*** Detected shallow Git version ${VERSION_GITHASH} ***")
-               else()
-                       set(VERSION_GITHASH "${VERSION_STRING}")
+                       RESULT_VARIABLE IS_DIRTY)
+               if(IS_DIRTY)
+                       set(VERSION_GITHASH "${VERSION_GITHASH}-dirty")
                endif()
+               message(STATUS "*** Detected Git version ${VERSION_GITHASH} ***")
        endif()
 endif()
+if(NOT VERSION_GITHASH)
+       set(VERSION_GITHASH "${VERSION_STRING}")
+endif()
 
 configure_file(
        ${GENERATE_VERSION_SOURCE_DIR}/cmake_config_githash.h.in
index 66c8170cbc0c4649f739405cd0a9ba238fef8a3a..044afa367a03e672a459e5914c90e04afda53d1e 100644 (file)
@@ -269,7 +269,7 @@ add_custom_target(GenerateVersion
        -D "GENERATE_VERSION_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
        -D "GENERATE_VERSION_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
        -D "VERSION_STRING=${VERSION_STRING}"
-       -D "VERSION_EXTRA=${VERSION_EXTRA}"
+       -D "DEVELOPMENT_BUILD=${DEVELOPMENT_BUILD}"
        -P "${CMAKE_SOURCE_DIR}/cmake/Modules/GenerateVersion.cmake"
        WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
 
index b45c636646b49fdae8dc16c881da79262dec791f..5ff69c8af7874be450796b3ee8d2fcc35d72a01c 100755 (executable)
@@ -87,7 +87,7 @@ sed -i -re "s/^set\(VERSION_MINOR [0-9]+\)$/set(VERSION_MINOR $NEW_VERSION_MINOR
 
 sed -i -re "s/^set\(VERSION_PATCH [0-9]+\)$/set(VERSION_PATCH $NEW_VERSION_PATCH)/" CMakeLists.txt || die "Failed to update VERSION_PATCH"
 
-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"
+sed -i -re "s/^set\(DEVELOPMENT_BUILD TRUE\)$/set(DEVELOPMENT_BUILD FALSE)/" CMakeLists.txt || die "Failed to unset DEVELOPMENT_BUILD"
 
 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"
 
@@ -98,3 +98,24 @@ sed -i -re "1s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" doc/menu_lua_api.txt || di
 git add -f CMakeLists.txt build/android/Makefile doc/lua_api.txt doc/menu_lua_api.txt || die "git add failed"
 
 git commit -m "Bump version to $NEW_VERSION" || die "git commit failed"
+
+############
+# Create tag
+############
+
+echo "Tagging $NEW_VERSION"
+
+git tag -a "$NEW_VERSION" -m "$NEW_VERSION" || die 'Adding tag failed'
+
+######################
+# Create revert commit
+######################
+
+echo 'Creating "revert to development" commit'
+
+sed -i -re 's/^set\(DEVELOPMENT_BUILD FALSE\)$/set(DEVELOPMENT_BUILD TRUE)/' CMakeLists.txt || die 'Failed to set DEVELOPMENT_BUILD'
+
+git add -f CMakeLists.txt || die 'git add failed'
+
+git commit -m "Continue with $NEW_VERSION-dev" || die 'git commit failed'
+