diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2019-12-20 10:47:35 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-13 21:19:33 +0000 |
commit | b40d0ebfe31a1ed5503f6ae834dbac5a06487f22 (patch) | |
tree | 5b7f87bd3a340e8bddf8751c2f45e5ae55bbaacb | |
parent | 8e7d2cfac6cc60599c22fe4f072d5744b772fdf5 (diff) | |
download | chrome-ec-b40d0ebfe31a1ed5503f6ae834dbac5a06487f22.tar.gz |
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>
-rw-r--r-- | Makefile.rules | 5 | ||||
-rwxr-xr-x | util/getversion.sh | 41 |
2 files changed, 30 insertions, 16 deletions
diff --git a/Makefile.rules b/Makefile.rules index 2bfcf88957..7106091fe5 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -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} && \ diff --git a/util/getversion.sh b/util/getversion.sh index d775100e8d..913c0894ec 100755 --- a/util/getversion.sh +++ b/util/getversion.sh @@ -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)" |