From 8a94ea4fbd7ef283af35ec5aa472a819f5a2a337 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Tue, 24 Feb 2015 08:55:01 -0800 Subject: [PATCH] Add USE_GIT_DATE=1 to make args to build repeatable images Up until now, every image includes the time of compilation in the build information. This makes it impossible to verify that a particular image came from a particular source code snapshot. With this change, specifying USE_GIT_DATE=1 to the make command will use the author date of HEAD as the timestamp. That means that successive builds from the same source will produce bitwise-identical output (assuming the same toolchain, of course). BUG=none BRANCH=none TEST=manual Do this twice: \rm -rf build make BOARD=cr50 USE_GIT_DATE=1 md5sum build/cr50/ec.bin The md5sum should be the same for both runs. Change-Id: If64307101a453cb13c62fa003f1bf432f4998273 Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/252751 Reviewed-by: Randall Spangler --- Makefile.rules | 2 +- util/getversion.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile.rules b/Makefile.rules index 204988036e..80ac99d9b3 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -53,7 +53,7 @@ cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) \ cmd_c_to_host = $(HOSTCC) $(HOST_CFLAGS) -MMD -MF $@.d -o $@ \ $(sort $(foreach c,$($(*F)-objs),util/$(c:%.o=%.c)) $*.c) cmd_host_test = ./util/run_host_test $* $(silent) -cmd_date = ./util/getdate.sh > $@ +cmd_date = $(if $(USE_GIT_DATE),cat /dev/null,./util/getdate.sh) > $@ cmd_version = ./util/getversion.sh > $@ cmd_mv_from_tmp = mv $(out)/$*.bin.tmp $(out)/$*.bin cmd_extractrw-y = dd if=$(out)/$(PROJECT).bin.tmp of=$(out)/$(PROJECT).RW.bin \ diff --git a/util/getversion.sh b/util/getversion.sh index c1da044690..798bb51448 100755 --- a/util/getversion.sh +++ b/util/getversion.sh @@ -31,6 +31,8 @@ fi ver="${BOARD}_${vbase}" +gitdate=$(git log -1 --format='%ai' HEAD | cut -d ' ' -f '1 2') + echo "/* This file is generated by util/getversion.sh */" echo "/* Version string for use by common/version.c */" @@ -47,3 +49,8 @@ echo "/* Sub-fields for use in Makefile.rules and to form build info string" echo " * in common/version.c. */" echo "#define VERSION \"${ver}\"" echo "#define BUILDER \"${USER}@`hostname`\"" + +echo "/* Author date of last commit, in case compile-time is not used. */" +echo "#ifndef DATE" +echo "#define DATE \"${gitdate}\"" +echo "#endif"