blob: d505579f2b4e3715babd5349eb0343a485969bcd [file] [log] [blame]
Bill Richardsone1486c32014-10-30 17:41:51 -07001#!/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
Bill Richardsone1486c32014-10-30 17:41:51 -070024 dirty=$(sh -c "[ '$(git diff-index --name-only HEAD)' ] \
25 && echo '-dirty'")
26 ver="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
27else
28 ver="unknown"
29fi
30
31date=$(date '+%F %T')
32
33echo "const char futility_version[] = \"${ver} ${date} ${USER}\";";