summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-10-30 17:41:51 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-31 20:55:24 +0000
commite1486c3234b7dc6fc5b58681b271a65a09141e20 (patch)
tree34b0d3f6344cf168605547772bec9d7d0b113e32
parentd274a2e9536907d0474d988f32f602cd64ed1ae6 (diff)
downloadvboot-e1486c3234b7dc6fc5b58681b271a65a09141e20.tar.gz
futility: add version command
BUG=none BRANCH=none TEST=manual make && ./build/futility/futility version Change-Id: I362b13d3befba62a33bc9fd2e87ad68f4bc62a84 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226779 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--Makefile1
-rw-r--r--futility/futility.c10
-rw-r--r--futility/futility.h3
-rwxr-xr-xscripts/getversion.sh35
4 files changed, 49 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 2a3585ce..8dee03ce 100644
--- a/Makefile
+++ b/Makefile
@@ -1052,6 +1052,7 @@ ${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
| sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
| sort >>$@_commands
+ ${Q}./scripts/getversion.sh >> $@_t
${Q}echo '#define _CMD(NAME) extern const struct' \
'futil_cmd_t __cmd_##NAME;' >> $@_t
${Q}cat $@_commands >> $@_t
diff --git a/futility/futility.c b/futility/futility.c
index b4070618..c74bba61 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -237,6 +237,16 @@ DECLARE_FUTIL_COMMAND(help, do_help,
"Show a bit of help (you're looking at it)",
print_help);
+static int do_version(int argc, char *argv[])
+{
+ printf("%s\n", futility_version);
+ return 0;
+}
+
+DECLARE_FUTIL_COMMAND(version, do_version,
+ "Show the futility source revision and build date",
+ NULL);
+
/*
* These are built-in functions that we'd like to abandon completely someday.
* TODO: If no one complains, get rid of them.
diff --git a/futility/futility.h b/futility/futility.h
index 52c007cc..652b5fbc 100644
--- a/futility/futility.h
+++ b/futility/futility.h
@@ -14,6 +14,9 @@
/* This program */
#define MYNAME "futility"
+/* Version string (autogenerated) */
+extern const char futility_version[];
+
/* Here's a structure to define the commands that futility implements. */
struct futil_cmd_t {
const char *const name;
diff --git a/scripts/getversion.sh b/scripts/getversion.sh
new file mode 100755
index 00000000..b6f2bd4c
--- /dev/null
+++ b/scripts/getversion.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Generate version information
+
+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'")
+ ver="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
+else
+ ver="unknown"
+fi
+
+date=$(date '+%F %T')
+
+echo "const char futility_version[] = \"${ver} ${date} ${USER}\";";