get_version.sh: add an option for non-changing version file
I've made a hack similar to this a few times when I needed to test that applying commit(s) did not change a certain ec.bin file. get_version.sh already had a REPRODUCIBLE_BUILD option, which is useful for testing that compiling under a different user/host would not change the build, but did not allow testing compiling under a different commit. This adds another option, STATIC_VERSION, which allows different user, host, and commit/repository state. Usage: make BOARD=foo STATIC_VERSION=1 BUG=none BRANCH=none TEST=compile at different commits, observe ec.bin file does not change. Change-Id: I5fc277791cb272317fac2471f763b40290118e1d Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1997735 Reviewed-by: Jett Rink <jettrink@chromium.org>
This commit is contained in:
parent
8e7d2cfac6
commit
b40d0ebfe3
|
@ -52,6 +52,11 @@ quiet = $(cmd_$(1))
|
|||
endif
|
||||
endif
|
||||
|
||||
# Provide an option to use a consistent ec_version.h file when
|
||||
# compiling, which is useful to verify that a commit does not modify
|
||||
# the resulting ec.bin
|
||||
export STATIC_VERSION
|
||||
|
||||
# commands to build all targets
|
||||
cmd_libec = $(LD) -r $^ -o $@.1.o ${silent_err} && \
|
||||
$(OBJCOPY) --localize-hidden $@.1.o $@.2.o ${silent_err} && \
|
||||
|
|
|
@ -89,8 +89,13 @@ main() {
|
|||
local ver
|
||||
|
||||
IFS="${dc}"
|
||||
ver="${CR50_SQA:+SQA/}${CR50_DEV:+DBG/}${CRYPTO_TEST:+CT/}${BOARD}_"
|
||||
tool_ver=""
|
||||
if [[ -z "${STATIC_VERSION}" ]]; then
|
||||
ver="${CR50_SQA:+SQA/}${CR50_DEV:+DBG/}${CRYPTO_TEST:+CT/}${BOARD}_"
|
||||
tool_ver=""
|
||||
else
|
||||
ver="STATIC_VERSION"
|
||||
tool_ver="STATIC_VERSION_TOOL"
|
||||
fi
|
||||
global_dirty= # set if any of the component repos is 'dirty'.
|
||||
dir_list=( . ) # list of component directories, always includes the EC tree
|
||||
|
||||
|
@ -104,19 +109,21 @@ main() {
|
|||
esac
|
||||
|
||||
# Create a combined version string for all component directories.
|
||||
for git_dir in ${dir_list[@]}; do
|
||||
pushd "${git_dir}" > /dev/null
|
||||
component="$(basename "${git_dir}")"
|
||||
values=( $(get_tree_version) )
|
||||
vbase="${values[0]}" # Retrieved version information.
|
||||
global_dirty+="${values[1]}" # Non-zero, if the repository is 'dirty'
|
||||
if [ "${component}" != "." ]; then
|
||||
if [[ -z "${STATIC_VERSION}" ]]; then
|
||||
for git_dir in ${dir_list[@]}; do
|
||||
pushd "${git_dir}" > /dev/null
|
||||
component="$(basename "${git_dir}")"
|
||||
values=( $(get_tree_version) )
|
||||
vbase="${values[0]}" # Retrieved version information.
|
||||
global_dirty+="${values[1]}" # Non-zero, if the repository is 'dirty'
|
||||
if [ "${component}" != "." ]; then
|
||||
ver+=" ${component}:"
|
||||
fi
|
||||
ver+="${vbase}"
|
||||
tool_ver+="${vbase}"
|
||||
popd > /dev/null
|
||||
done
|
||||
fi
|
||||
ver+="${vbase}"
|
||||
tool_ver+="${vbase}"
|
||||
popd > /dev/null
|
||||
done
|
||||
fi
|
||||
|
||||
# On some boards where the version number consists of multiple components we
|
||||
# want to separate the first word of the version string as the version of the
|
||||
|
@ -137,13 +144,15 @@ main() {
|
|||
echo "/* Sub-fields for use in Makefile.rules and to form build info string"
|
||||
echo " * in common/version.c. */"
|
||||
echo "#define VERSION \"${ver}\""
|
||||
if [ "$REPRODUCIBLE_BUILD" = 1 ]; then
|
||||
if [[ -n "${STATIC_VERSION}" ]] || [[ "$REPRODUCIBLE_BUILD" = 1 ]]; then
|
||||
echo '#define BUILDER "reproducible@build"'
|
||||
else
|
||||
echo "#define BUILDER \"${USER}@`hostname`\""
|
||||
fi
|
||||
|
||||
if [ -n "$global_dirty" ]; then
|
||||
if [[ -n "${STATIC_VERSION}" ]]; then
|
||||
echo "#define DATE \"STATIC_VERSION_DATE\""
|
||||
elif [[ -n "$global_dirty" ]]; then
|
||||
most_recent_file="$(git status --porcelain | \
|
||||
awk '$1 ~ /[M|A|?]/ {print $2}' | \
|
||||
xargs ls -t | head -1)"
|
||||
|
|
Loading…
Reference in New Issue