Skip to content

Commit e29b61e

Browse files
committedJul 31, 2015
Android: speed up rebuild, and prevent race condition fail
Speeding up rebuild: Before, we've written the android_version.h file at every rebuild. As it thought the file's content has changed, make has rebuilt files in the source tree that depended on that header file during rebuild, causing lots of files being rebuilt without there being a reason. The reasoning of make can be observed by passing -d and V=1 params to the ndk-build command. You then got logging entries like: Prerequisite `jni/src/android_version.h' is newer than target `obj/local/armeabi-v7a-hard/objs-debug/minetest/jni/src/areastore.o'. Preventing race condition build fail: Before, there was a race condition, where, if the prep_srcdir target was executed in parallel with the $(ROOT)/jni/src/android_version.h one, it could happen that the jni/src directory was nonexistent, and we were trying to write into a file inside. This resulted in a build failue: /bin/sh: 1: cannot create [...]/jni/src/android_version.h: Directory nonexistent Additionally, we now don't remove the link to src/ needlessly anymore. Keeping this wouldn't have affected the rebuild, but this way its more proper.
1 parent 7217fd3 commit e29b61e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

Diff for: ‎build/android/Makefile

+14-5
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,9 @@ apk: $(PATHCFGFILE) assets $(ICONV_LIB) $(IRRLICHT_LIB) $(CURL_LIB) $(GMP_LIB) $
791791
echo "You can install it with \`adb install -r bin/Minetest-$$BUILD_TYPE.apk\`"
792792

793793
prep_srcdir :
794-
@rm ${ROOT}/jni/src; \
795-
ln -s ${ROOT}/../../src ${ROOT}/jni/src
794+
@if [ ! -e ${ROOT}/jni/src ]; then \
795+
ln -s ${ROOT}/../../src ${ROOT}/jni/src; \
796+
fi
796797

797798
clean_apk : manifest
798799
@export PATH=$$PATH:${SDKFOLDER}platform-tools:${ANDROID_NDK}; \
@@ -818,8 +819,10 @@ clean_all :
818819
sleep 1; \
819820
$(RM) -r gen libs obj deps bin Debug and_env
820821

821-
$(ROOT)/jni/src/android_version.h :
822-
@ { \
822+
$(ROOT)/jni/src/android_version.h : prep_srcdir
823+
@export VERSION_FILE=${ROOT}/jni/src/android_version.h; \
824+
export VERSION_FILE_NEW=$${VERSION_FILE}.new; \
825+
{ \
823826
echo "#ifndef ANDROID_MT_VERSION_H"; \
824827
echo "#define ANDROID_MT_VERSION_H"; \
825828
export CMAKE_FILE=${ROOT}/../../CMakeLists.txt; \
@@ -838,7 +841,13 @@ $(ROOT)/jni/src/android_version.h :
838841
echo "#define VERSION_STRING STR(VERSION_MAJOR)\".\"STR(VERSION_MINOR)\
839842
\".\"STR(VERSION_PATCH)"; \
840843
echo "#endif"; \
841-
} > ${ROOT}/jni/src/android_version.h
844+
} > $${VERSION_FILE_NEW}; \
845+
if ! cmp -s $${VERSION_FILE} $${VERSION_FILE_NEW}; then \
846+
echo "android_version.h changed, updating..."; \
847+
mv $${VERSION_FILE_NEW} $${VERSION_FILE}; \
848+
else \
849+
rm $${VERSION_FILE_NEW}; \
850+
fi
842851

843852
manifest :
844853
@VERS_MAJOR=$$(cat ${ROOT}/../../CMakeLists.txt | \

0 commit comments

Comments
 (0)
Please sign in to comment.