Skip to content

Commit 1271418

Browse files
committed
use faketime, if available, to set the build time based on the git commit
If the `faketime` utility is available, use it to fix the time of the build based on the time of the current git commit. This makes the build process reproducible since anyone who builds it from git will end up with a build that has the same exact timestamps. You can get faketime from various package systems: apt-get install faketime brew install faketime port install libfaketime
1 parent 72a8bfe commit 1271418

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Makefile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ RELEASE_DIR := sqlipher-for-android-${LATEST_TAG}
1313
CHANGE_LOG_HEADER := "Changes included in the ${LATEST_TAG} release of SQLCipher for Android:"
1414
README := ${RELEASE_DIR}/README
1515

16+
# Use faketime to freeze time to make for reproducible builds.
17+
# faketime needs to have a very specific timestamp format in order to freeze
18+
# time. The time needs to be frozen so that the timestamps don't depend on
19+
# the speed of the machine that the build process is running on. See `man
20+
# faketime` for more info on the "advanced timestamp format". Also, force
21+
# time to UTC so its always the same on all machines.
22+
ifeq ($(shell if which faketime > /dev/null; then echo faketime; fi),faketime)
23+
export TZ=UTC
24+
TIMESTAMP := $(shell faketime "`git log -n1 --format=format:%ai`" \
25+
date --utc '+%Y-%m-%d %H:%M:%S')
26+
# frozen time
27+
FAKETIME := faketime -f "$(TIMESTAMP)"
28+
# time moving at 5% of normal speed
29+
FAKETIME_5 := faketime -f "@$(TIMESTAMP) x0.05"
30+
endif
31+
1632
init:
1733
git submodule update --init
1834
android update project -p .
@@ -23,16 +39,16 @@ all: build-external build-jni build-java copy-libs
2339

2440
build-external:
2541
cd ${EXTERNAL_DIR} && \
26-
make -f Android.mk build-local-hack && \
27-
ndk-build NDK_LIBS_OUT=$(EXTERNAL_DIR)/libs && \
28-
make -f Android.mk copy-libs-hack
42+
$(FAKETIME) make -f Android.mk build-local-hack && \
43+
$(FAKETIME) ndk-build NDK_LIBS_OUT=$(EXTERNAL_DIR)/libs && \
44+
$(FAKETIME) make -f Android.mk copy-libs-hack
2945

3046
build-jni:
3147
cd ${JNI_DIR} && \
32-
ndk-build NDK_LIBS_OUT=$(JNI_DIR)/libs
48+
$(FAKETIME) ndk-build NDK_LIBS_OUT=$(JNI_DIR)/libs
3349

3450
build-java:
35-
ant release
51+
$(FAKETIME_5) ant release
3652

3753
release:
3854
-rm -rf ${RELEASE_DIR}

0 commit comments

Comments
 (0)