From e1486c3234b7dc6fc5b58681b271a65a09141e20 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 30 Oct 2014 17:41:51 -0700 Subject: futility: add version command BUG=none BRANCH=none TEST=manual make && ./build/futility/futility version Change-Id: I362b13d3befba62a33bc9fd2e87ad68f4bc62a84 Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/226779 Reviewed-by: Randall Spangler --- scripts/getversion.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/getversion.sh (limited to 'scripts/getversion.sh') 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}\";"; -- cgit v1.2.1