xref: /aosp_15_r20/external/vboot_reference/scripts/getversion.sh (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1#!/usr/bin/env bash
2#
3# Copyright 2014 The ChromiumOS Authors
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=12 --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  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
31echo "const char futility_version[] = \"${ver}\";";
32