getversion.sh 952 B

12345678910111213141516171819202122232425262728293031323334
  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. if ghash=$(git rev-parse --short --verify HEAD 2>/dev/null); then
  9. if gdesc=$(git describe --dirty --match='v*' 2>/dev/null); then
  10. IFS="-" fields=($gdesc)
  11. tag="${fields[0]}"
  12. IFS="." vernum=($tag)
  13. numcommits=$((${vernum[2]}+${fields[1]:-0}))
  14. ver_major="${vernum[0]}"
  15. ver_branch="${vernum[1]}"
  16. else
  17. numcommits=$(git rev-list HEAD | wc -l)
  18. ver_major="v0"
  19. ver_branch="0"
  20. fi
  21. # avoid putting the -dirty attribute if only the timestamp
  22. # changed
  23. dirty=$(sh -c "[ '$(git diff-index --name-only HEAD)' ] \
  24. && echo '-dirty'")
  25. ver="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}"
  26. else
  27. ver="unknown"
  28. fi
  29. date=$(date '+%F %T')
  30. echo "const char futility_version[] = \"${ver} ${date} ${USER}\";";