From 38650d0b5de0df77d5c3985c17ac38f9865f6cbb Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Wed, 13 Sep 2017 13:55:33 -0700 Subject: util: move 'dirty' marker to be a prefix, not a suffix With longer git SHA1s reported by git commands and longer version strings, the entire SHA1 could be not fitting into the 32 byte version of the VERSION string. So, instead of adding the 'dirty' marker to the end of SHA1 let's replace the prefix dash with it in case the tree is dirty. This way the length of the version string does not change (as long as the 'dirty' marker is one character long). BRANCH=cr50 BUG=b:64698702 TEST=verified output of running getversion.sh with a clean tree $ ./util/getversion.sh | grep VERSION32 #define CROS_EC_VERSION32 "_v1.1.7046-591608e2e" and a 'dirty' tree $ ./util/getversion.sh | grep VERSION32 #define CROS_EC_VERSION32 "_v1.1.7046+591608e2e" Change-Id: I42684522beaff9e9714206cfaddaf97e6cd644be Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/665958 Reviewed-by: Vincent Palatin --- util/getversion.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'util/getversion.sh') diff --git a/util/getversion.sh b/util/getversion.sh index 18a6ee9ba1..660ca24baf 100755 --- a/util/getversion.sh +++ b/util/getversion.sh @@ -28,7 +28,7 @@ dirty_marker='+' # "no_version" get_tree_version() { - local dirty + local marker local ghash local numcommits local tag @@ -54,9 +54,11 @@ get_tree_version() { git status > /dev/null 2>&1 if [ -n "$(git diff-index --name-only HEAD 2>/dev/null)" ]; then - dirty="${dirty_marker}" + marker="${dirty_marker}" + else + marker="-" fi - vbase="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}" + vbase="${ver_major}.${ver_branch}.${numcommits}${marker}${ghash}" else # Fall back to the VCSID provided by the packaging system if available. if ghash=${VCSID##*-}; then @@ -66,7 +68,11 @@ get_tree_version() { vbase="no_version" fi fi - echo "${vbase}${dc}${dirty}" + if [[ "${marker}" == "${dirty_marker}" ]]; then + echo "${vbase}${dc}${marker}" + else + echo "${vbase}${dc}" + fi } -- cgit v1.2.1