diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2016-07-27 20:22:26 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-28 20:20:44 -0700 |
commit | 3531d6123bcc742b390fb8fa2b9b65362fa02777 (patch) | |
tree | a793789196f8ffd41efcd359d3a68fe17c0ccd92 /util/getversion.sh | |
parent | eb0660283d003f0fb999b8aad29997c8ddf98e87 (diff) | |
download | chrome-ec-3531d6123bcc742b390fb8fa2b9b65362fa02777.tar.gz |
util: refactor getversion.sh
It is necessary to collect information about more then one git
repositories status for the cr50 board. To facilitate this, separate
the code retrieving build version information into a function,
get_tree_version().
The function returns a two element string, the version information and
the 'dirty' marker in case the tree has any uncommitted changes. The
0x01 character is used to join the elements of the string, which makes
it easier to split the string when processing it.
BRANCH=ToT
BUG=chrome-os-partner:55373
TEST=ran the script before and after changes, observed that generated
output is identical.
Change-Id: I2c211cbda8c3cab3c8c21b4430e4b3102691e74a
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/362849
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'util/getversion.sh')
-rwxr-xr-x | util/getversion.sh | 88 |
1 files changed, 60 insertions, 28 deletions
diff --git a/util/getversion.sh b/util/getversion.sh index abf99eb186..bb1b7c5574 100755 --- a/util/getversion.sh +++ b/util/getversion.sh @@ -6,35 +6,67 @@ # # 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 - # Fall back to the VCSID provided by the packaging system if available. - if ghash=${VCSID##*-}; then - vbase="1.1.9999-${ghash:0:7}" - else - # then ultimately fails to "no_version" - vbase="no_version" - fi -fi +# Use this symbol as a separator to be able to reliably concatenate strings of +# text. +dc=$'\001' + +# This function examines the state of the current directory and attempts to +# extract its version information: the latest tag, if any, how many patches +# are there since the latest tag, the top sha1, and if there are local +# modifications. +# +# Local modifications are reported by concatenating the revision string and +# the string '-dirty' using the $dc symbol as the separator. +# +# If there is no tags defined in this git repository, the base version is +# considered to be 0.0. +# +# If current directory is not a git depository, this function prints out +# "no_version" + +get_tree_version() { + local ghash + local numcommits + local tag + local vbase + local ver_branch + local ver_major + + 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 + # Fall back to the VCSID provided by the packaging system if available. + if ghash=${VCSID##*-}; then + vbase="1.1.9999-${ghash:0:7}" + else + # then ultimately fails to "no_version" + vbase="no_version" + fi + fi + echo "${vbase}${dc}${dirty}" +} +IFS="${dc}" +values=( $(get_tree_version) ) +vbase="${values[0]}" # Retrieved version information. +dirty="${values[1]}" # Non-zero, if the repository is 'dirty' ver="${BOARD}_${vbase}" echo "/* This file is generated by util/getversion.sh */" |