Files
OpenCellular/util/getversion.sh
Bill Richardson 8a94ea4fbd 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 <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/252751
Reviewed-by: Randall Spangler <rspangler@chromium.org>
2015-02-25 03:33:18 +00:00

57 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Generate version information for the EC binary
if ghash=`git rev-parse --short --verify HEAD 2>/dev/null`; then
if gdesc=`git describe --dirty --match='v*' 2>/dev/null`; then
IFS="-" fields=($gdesc)
tag="${fields[0]}"
IFS="." vernum=($tag)
numcommits=$((${vernum[2]}+${fields[1]:-0}))
ver_major="${vernum[0]}"
ver_branch="${vernum[1]}"
else
numcommits=`git rev-list HEAD | wc -l`
ver_major="v0"
ver_branch="0"
fi
# avoid putting the -dirty attribute if only the timestamp
# changed
git status > /dev/null 2>&1
dirty=`sh -c "[ '$(git diff-index --name-only HEAD)' ] && echo '-dirty'"`
vbase="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
else
vbase="no_version"
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 */"
echo "#ifdef SHIFT_CODE_FOR_TEST"
echo "#define CROS_EC_VERSION \"${ver}_shift\""
echo "#else"
echo "#define CROS_EC_VERSION \"${ver}\""
echo "#endif"
echo "/* Version string, truncated to 31 chars (+ terminating null = 32) */"
echo "#define CROS_EC_VERSION32 \"${ver:0:31}\""
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"