diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2019-02-03 14:07:03 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-05 10:40:09 -0800 |
commit | 8d9d2ace61857cf683273a4c9cac3083074a3a33 (patch) | |
tree | fe728005e3d2f0a28658f2857cd3ca3191898578 /util/getversion.sh | |
parent | 95188606b215bfb4e31b1e9d0172a72bd2c55ecb (diff) | |
download | chrome-ec-8d9d2ace61857cf683273a4c9cac3083074a3a33.tar.gz |
getversion.sh: use better timestamp algorithm
When running ./util/getversion.sh in a 'dirty' tree do not generate
the timestamp containing the current time, find out outstanding files
(including those not yet included in git) and use the timestamp of the
most recent of these files.
The generated date is not accurate in some cases: files not included
in the tree possibly are not part of the build either, so their
modification should not be causing the generated timestamp change.
Also, if a previously modified file was checked out from git HEAD, it
will not be included in the timestamp string generation.
These inaccuracies are not that important: worst case one of the
builds would have incorrect timestamp, not a big deal for the case
when there are local tree modifications.
The big advantage of the new timestamp generation scheme is that if
there has been no changes in the tree, the new ec_version.h file is
not generated, which prevents re-compilation of board.c. This is
necessary to achieve no rebuilds when make is invoked on a tree which
has not been modified since previous make invocation.
BRANCH=none
BUG=none
TEST=running 'make BOARD=cr50' does not trigger re-compiling of
board.c any more, the timestamp included in the build is the
timestamp of the most recent modification of the checked out
files in the tree
Change-Id: I7c931e4965811faa8079d6762b9b9a57a6bb20bb
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1450182
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'util/getversion.sh')
-rwxr-xr-x | util/getversion.sh | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/util/getversion.sh b/util/getversion.sh index 2d5abf7941..3fc74b7c39 100755 --- a/util/getversion.sh +++ b/util/getversion.sh @@ -81,6 +81,8 @@ main() { local dir_list local gitdate local global_dirty + local most_recent_file + local timestamp local tool_ver local values local vbase @@ -136,8 +138,12 @@ main() { fi if [ -n "$global_dirty" ]; then - echo "/* Repo is dirty, using time of last compilation */" - echo "#define DATE \"$(date '+%F %T')\"" + most_recent_file="$(git status --porcelain | \ + awk '$1 ~ /[M|A|?]/ {print $2}' | \ + xargs ls -t | 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 */" # If called from an ebuild we won't have a git repo, so redirect stderr |