• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# Generate version information
8
9if ghash=$(git rev-parse --short --verify HEAD 2>/dev/null); then
10	if gdesc=$(git describe --dirty --match='v*' 2>/dev/null); then
11		IFS="-" fields=($gdesc)
12		tag="${fields[0]}"
13		IFS="." vernum=($tag)
14		numcommits=$((${vernum[2]}+${fields[1]:-0}))
15		ver_major="${vernum[0]}"
16		ver_branch="${vernum[1]}"
17	else
18		numcommits=$(git rev-list HEAD | wc -l)
19		ver_major="v0"
20		ver_branch="0"
21	fi
22	# avoid putting the -dirty attribute if only the timestamp
23	# changed
24	git status > /dev/null 2>&1
25
26	dirty=$(sh -c "[ '$(git diff-index --name-only HEAD)' ] \
27                && echo '-dirty'")
28	ver="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
29else
30	ver="unknown"
31fi
32
33date=$(date '+%F %T')
34
35echo "const char futility_version[] = \"${ver} ${date} ${USER}\";";
36