summaryrefslogtreecommitdiff
path: root/util/getversion.sh
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2019-02-03 14:00:14 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-05 02:49:43 -0800
commit95188606b215bfb4e31b1e9d0172a72bd2c55ecb (patch)
treeeec71b200712d8c898dd8a1ea5ae754a28886be8 /util/getversion.sh
parent21c470bab4d9f1182ff52f965ed8005c10fe798e (diff)
downloadchrome-ec-95188606b215bfb4e31b1e9d0172a72bd2c55ecb.tar.gz
getversion: move main code into function
This is a no-op change of moving the main script program into a function as is. This will make it easier to modify script behavior when necessary. BRANCH=none BUG=none TEST=verified that script output is the same as before this modification. Change-Id: I721f88feace5e29e6dcc20086a113cb185f4d699 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1450181 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'util/getversion.sh')
-rwxr-xr-xutil/getversion.sh115
1 files changed, 64 insertions, 51 deletions
diff --git a/util/getversion.sh b/util/getversion.sh
index c0ab6ff89f..2d5abf7941 100755
--- a/util/getversion.sh
+++ b/util/getversion.sh
@@ -76,62 +76,75 @@ get_tree_version() {
}
-IFS="${dc}"
-ver="${CR50_DEV:+DBG/}${BOARD}_"
-tool_ver=""
-global_dirty= # set if any of the component repos is 'dirty'.
-dir_list=( . ) # list of component directories, always includes the EC tree
-
-case "${BOARD}" in
- (cr50)
- dir_list+=( ../../third_party/tpm2 ../../third_party/cryptoc )
- ;;
-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
- ver+=" ${component}:"
+main() {
+ local component
+ local dir_list
+ local gitdate
+ local global_dirty
+ local tool_ver
+ local values
+ local vbase
+ local ver
+
+ IFS="${dc}"
+ ver="${CR50_DEV:+DBG/}${BOARD}_"
+ tool_ver=""
+ global_dirty= # set if any of the component repos is 'dirty'.
+ dir_list=( . ) # list of component directories, always includes the EC tree
+
+ case "${BOARD}" in
+ (cr50)
+ dir_list+=( ../../third_party/tpm2 ../../third_party/cryptoc )
+ ;;
+ 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
+ ver+=" ${component}:"
+ fi
+ ver+="${vbase}"
+ tool_ver+="${vbase}"
+ popd > /dev/null
+ done
+
+ # 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
+ # EC tree.
+ IFS=' ' first_word=(${ver})
+
+ echo "/* This file is generated by util/getversion.sh */"
+
+ echo "/* Version string, truncated to 31 chars (+ terminating null = 32) */"
+ echo "#define CROS_EC_VERSION32 \"${first_word:0:31}\""
+
+ echo "/* Version string for ectool. */"
+ echo "#define CROS_ECTOOL_VERSION \"${tool_ver}\""
+
+ 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
+ echo '#define BUILDER "reproducible@build"'
+ else
+ echo "#define BUILDER \"${USER}@`hostname`\""
fi
- ver+="${vbase}"
- tool_ver+="${vbase}"
- popd > /dev/null
-done
-
-# 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
-# EC tree.
-IFS=' ' first_word=(${ver})
-
-echo "/* This file is generated by util/getversion.sh */"
-
-echo "/* Version string, truncated to 31 chars (+ terminating null = 32) */"
-echo "#define CROS_EC_VERSION32 \"${first_word:0:31}\""
-
-echo "/* Version string for ectool. */"
-echo "#define CROS_ECTOOL_VERSION \"${tool_ver}\""
-
-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
- echo '#define BUILDER "reproducible@build"'
-else
- echo "#define BUILDER \"${USER}@`hostname`\""
-fi
-
-if [ -n "$global_dirty" ]; then
+
+ if [ -n "$global_dirty" ]; then
echo "/* Repo is dirty, using time of last compilation */"
echo "#define DATE \"$(date '+%F %T')\""
-else
+ else
echo "/* Repo is clean, use the commit date of the last commit */"
# If called from an ebuild we won't have a git repo, so redirect stderr
# to avoid annoying 'Not a git repository' errors.
gitdate=$(git log -1 --format='%ci' HEAD 2>/dev/null | cut -d ' ' -f '1 2')
echo "#define DATE \"${gitdate}\""
-fi
+ fi
+}
+
+main