Skip to content

Commit c39a85a

Browse files
committedAug 1, 2015
Android: Add githash header to spare rebuilds after new commits
Before, android_version.h got changed at every new commit. Now, we only change it with new minetest releases. Analogous to how cmake does it, we add an android_version_githash.h file that communicates the git hash to C++ code. Also, unify VERS_MAJOR, VERS_MINOR and VERS_PATCH variable calculation inside the whole makefile.
1 parent 7919318 commit c39a85a

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed
 

Diff for: ‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ doc/doxygen_*
3939
CMakeFiles/*
4040
src/CMakeFiles/*
4141
src/Makefile
42+
src/android_config_githash.h
4243
src/android_version.h
4344
src/cmake_config.h
4445
src/cmake_config_githash.h

Diff for: ‎build/android/Makefile

+36-24
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ ROOT = $(shell pwd)
1515

1616
GAMES_TO_COPY = minetest_game
1717

18+
19+
VERSION_MAJOR := $(shell cat $(ROOT)/../../CMakeLists.txt | \
20+
grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | cut -f2 -d' ')
21+
VERSION_MINOR := $(shell cat $(ROOT)/../../CMakeLists.txt | \
22+
grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | cut -f2 -d' ')
23+
VERSION_PATCH := $(shell cat $(ROOT)/../../CMakeLists.txt | \
24+
grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | cut -f2 -d' ')
25+
1826
################################################################################
1927
# Android Version code
2028
# Increase for each build!
@@ -161,7 +169,8 @@ endif
161169
$(OPENAL_TIMESTAMP) $(OGG_TIMESTAMP) \
162170
$(IRRLICHT_TIMESTAMP) $(CURL_TIMESTAMP) \
163171
$(OPENSSL_TIMESTAMP) curl_binary \
164-
$(ROOT)/jni/src/android_version.h
172+
$(ROOT)/jni/src/android_version.h \
173+
$(ROOT)/jni/src/android_version_githash.h
165174

166175
debug : $(PATHCFGFILE)
167176
export NDEBUG=; \
@@ -773,7 +782,7 @@ clean_assets :
773782

774783
apk: $(PATHCFGFILE) assets $(ICONV_LIB) $(IRRLICHT_LIB) $(CURL_LIB) $(GMP_LIB) $(LEVELDB_TARGET) \
775784
$(OPENAL_LIB) $(OGG_LIB) prep_srcdir $(ROOT)/jni/src/android_version.h \
776-
sqlite3_download
785+
$(ROOT)/jni/src/android_version_githash.h sqlite3_download
777786
@export NDEBUG=$$NDEBUG; $(MAKE) manifest; \
778787
export PATH=$$PATH:${SDKFOLDER}/platform-tools:${ANDROID_NDK}; \
779788
export ANDROID_HOME=${SDKFOLDER}; \
@@ -819,44 +828,47 @@ clean_all :
819828
sleep 1; \
820829
$(RM) -r gen libs obj deps bin Debug and_env
821830

831+
$(ROOT)/jni/src/android_version_githash.h : prep_srcdir
832+
@export VERSION_FILE=${ROOT}/jni/src/android_version_githash.h; \
833+
export VERSION_FILE_NEW=$${VERSION_FILE}.new; \
834+
{ \
835+
echo "#ifndef ANDROID_MT_VERSION_GITHASH_H"; \
836+
echo "#define ANDROID_MT_VERSION_GITHASH_H"; \
837+
export GITHASH=$$(git rev-parse --short=8 HEAD); \
838+
export VERSION_STR="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"; \
839+
echo "#define VERSION_GITHASH \"$$VERSION_STR-$$GITHASH-Android\""; \
840+
echo "#endif"; \
841+
} > "$${VERSION_FILE_NEW}"; \
842+
if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \
843+
echo "android_version_githash.h changed, updating..."; \
844+
mv "$${VERSION_FILE_NEW}" "$${VERSION_FILE}"; \
845+
else \
846+
rm "$${VERSION_FILE_NEW}"; \
847+
fi
848+
849+
822850
$(ROOT)/jni/src/android_version.h : prep_srcdir
823851
@export VERSION_FILE=${ROOT}/jni/src/android_version.h; \
824852
export VERSION_FILE_NEW=$${VERSION_FILE}.new; \
825853
{ \
826854
echo "#ifndef ANDROID_MT_VERSION_H"; \
827855
echo "#define ANDROID_MT_VERSION_H"; \
828-
export CMAKE_FILE=${ROOT}/../../CMakeLists.txt; \
829-
export VERSION_MAJOR=$$(cat $${CMAKE_FILE} | \
830-
grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | cut -f2 -d' '); \
831-
export VERSION_MINOR=$$(cat $${CMAKE_FILE} | \
832-
grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | cut -f2 -d' '); \
833-
export VERSION_PATCH=$$(cat $${CMAKE_FILE} | \
834-
grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | cut -f2 -d' '); \
835-
echo "#define VERSION_MAJOR $${VERSION_MAJOR}"; \
836-
echo "#define VERSION_MINOR $${VERSION_MINOR}"; \
837-
echo "#define VERSION_PATCH $${VERSION_PATCH}"; \
838-
export GITHASH=$$(git rev-parse --short=8 HEAD); \
839-
export VERSION_STR="$${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_PATCH}";\
840-
echo "#define VERSION_GITHASH \"$$VERSION_STR-$$GITHASH-Android\""; \
856+
echo "#define VERSION_MAJOR ${VERSION_MAJOR}"; \
857+
echo "#define VERSION_MINOR ${VERSION_MINOR}"; \
858+
echo "#define VERSION_PATCH ${VERSION_PATCH}"; \
841859
echo "#define VERSION_STRING STR(VERSION_MAJOR)\".\"STR(VERSION_MINOR)\
842860
\".\"STR(VERSION_PATCH)"; \
843861
echo "#endif"; \
844862
} > $${VERSION_FILE_NEW}; \
845863
if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \
846864
echo "android_version.h changed, updating..."; \
847-
mv $${VERSION_FILE_NEW} $${VERSION_FILE}; \
865+
mv "$${VERSION_FILE_NEW}" "$${VERSION_FILE}"; \
848866
else \
849-
rm $${VERSION_FILE_NEW}; \
867+
rm "$${VERSION_FILE_NEW}"; \
850868
fi
851869

852870
manifest :
853-
@VERS_MAJOR=$$(cat ${ROOT}/../../CMakeLists.txt | \
854-
grep ^set\(VERSION_MAJOR\ | sed 's/)/ /' | awk '{print $$2;}'); \
855-
VERS_MINOR=$$(cat ${ROOT}/../../CMakeLists.txt | \
856-
grep ^set\(VERSION_MINOR\ | sed 's/)/ /' | awk '{print $$2;}'); \
857-
VERS_PATCH=$$(cat ${ROOT}/../../CMakeLists.txt | \
858-
grep ^set\(VERSION_PATCH\ | sed 's/)/ /' | awk '{print $$2;}'); \
859-
BASE_VERSION="$$VERS_MAJOR.$$VERS_MINOR.$$VERS_PATCH"; \
871+
@BASE_VERSION="${VERS_MAJOR}.${VERS_MINOR}.${VERS_PATCH}"; \
860872
if [ "${NDEBUG}x" != "x" ] ; then \
861873
DBG=''; \
862874
DBG_FLAG="android:debuggable=\"false\""; \

Diff for: ‎src/version.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#if defined(__ANDROID__)
2424
#include "android_version.h"
25+
#include "android_version_githash.h"
2526
#elif defined(USE_CMAKE_CONFIG_H)
2627
#include "cmake_config_githash.h"
2728
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.