summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2020-09-03 14:21:06 -0700
committerCommit Bot <commit-bot@chromium.org>2020-09-14 21:02:32 +0000
commit1a02d7691e8dbccfe03cbb1aab896c2af2e76216 (patch)
tree5568c73639cec70923a2d080c3f76c73b6e35c16
parent1e0753b2ad142d1de9a03b1b667cadcdc13b9d13 (diff)
downloadchrome-ec-1a02d7691e8dbccfe03cbb1aab896c2af2e76216.tar.gz
util: modify getversion to use proper timestamps.
The getversion.sh utility even when compiling the version string based on the state of several git trees always uses the ec tree for timestamps, be it the latest modified file if the tree is 'dirty' or the last commit time if the tree is clean. It should be using the latest time from all of the trees included in the build. BUG=none TEST=verified operation for Cr50 with both main and secondary trees clean and dirty Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I72dc1d49ec997c789697b15f7d79fa9f4a8f8adc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2393101 Reviewed-by: Craig Hesling <hesling@chromium.org> (cherry picked from commit 5ab4bd06261abf1204638c8ef877a9adb041d6e8) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2410700 Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rwxr-xr-xutil/getversion.sh27
1 files changed, 18 insertions, 9 deletions
diff --git a/util/getversion.sh b/util/getversion.sh
index eb1f310396..c19282d3bb 100755
--- a/util/getversion.sh
+++ b/util/getversion.sh
@@ -80,7 +80,7 @@ main() {
local component
local dir_list
local gitdate
- local global_dirty
+ local most_recents
local most_recent_file
local root
local timestamp
@@ -92,7 +92,7 @@ main() {
IFS="${dc}"
ver="${CR50_DEV:+DBG/}${CRYPTO_TEST:+CT/}${BOARD}_"
tool_ver=""
- global_dirty= # set if any of the component repos is 'dirty'.
+ most_recents=() # Non empty if any of the component repos is 'dirty'.
dir_list=( . ) # list of component directories, always includes the EC tree
if [[ -n ${BOARD} ]]; then
@@ -119,7 +119,13 @@ main() {
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 [[ -n "${values[1]}" ]]; then
+ # From each modified repo get the most recently modified file.
+ most_recent_file="$(git status --porcelain | \
+ awk '$1 ~ /[M|A|?]/ {print $2}' | \
+ xargs ls -t | head -1)"
+ most_recents+=("$(realpath "${most_recent_file}")")
+ fi
if [ "${component}" != "." ]; then
ver+=" ${component}:"
fi
@@ -153,18 +159,21 @@ main() {
echo "#define BUILDER \"${USER}@`hostname`\""
fi
- if [ -n "$global_dirty" ]; then
- most_recent_file="$(git status --porcelain | \
- awk '$1 ~ /[M|A|?]/ {print $2}' | \
- xargs ls -t | head -1)"
+ if [[ ${#most_recents[@]} != 0 ]]; then
+ # There are modified files, use the timestamp of the most recent one as
+ # the build version timestamp.
+ most_recent_file="$(ls -t "${most_recents[@]}" | head -1)"
timestamp="$(stat -c '%y' "${most_recent_file}" | sed 's/\..*//')"
echo "/* Repo is dirty, using time of most recent file modification. */"
echo "#define DATE \"${timestamp}\""
else
- echo "/* Repo is clean, use the commit date of the last commit */"
+ 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')
+ gitdate="$(
+ for git_dir in "${dir_list[@]}"; do
+ git -C "${git_dir}" log -1 --format='%ct %ci' HEAD 2>/dev/null
+ done | sort | tail -1 | cut -d ' ' -f '2 3')"
echo "#define DATE \"${gitdate}\""
fi
}