You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

150 lines
3.6 KiB

  1. #!/bin/bash
  2. # version.sh: openocd version process automation
  3. # Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net>
  4. # Release under the GNU GPL v2 (or later versions).
  5. # FIXME Remove more bash-isms. Fix errors making "ash -e" lose.
  6. # NOTE Use with care! "RC" should only follow x.x.x, with
  7. # vendor tags after that. Be traditional; avoid "rc0".
  8. # NOTE: This *ONLY* updates the "configure.ac" version tag.
  9. # It does not affect GIT tags. Use this script immediately
  10. # before making a release, to remove the "-dev" tag and to
  11. # update the version label. Then commit the change and tag
  12. # that commit to match the version label.
  13. . "tools/release/helpers.sh"
  14. do_version_usage() {
  15. cat << USAGE
  16. usage: $0 <command>
  17. Version Commands:
  18. tag {add|remove} <label> Add or remove the specified tag.
  19. bump {major|minor|micro|rc} Bump the specified version number, and
  20. reset less-significant numbers to zero.
  21. bump tag <label> Add or bump a versioned tag (e.g. -rcN).
  22. bump final <label> Remove a versioned tag (e.g. -rcN).
  23. USAGE
  24. # REVISIT ... "commit" not listed.
  25. }
  26. do_version_sed() {
  27. local OLD_VERSION="${PACKAGE_VERSION}"
  28. local NEW_VERSION="$1"
  29. local MSG="$2"
  30. sed -i -e "/AC_INIT/ s|${OLD_VERSION}|${NEW_VERSION}|" configure.ac
  31. package_info_load
  32. echo "${MSG}: ${OLD_VERSION} -> ${NEW_VERSION}"
  33. }
  34. do_version_bump_sed() {
  35. local NEW_VERSION="$1"
  36. [ -z "${PACKAGE_VERSION_TAGS}" ] || \
  37. NEW_VERSION="${NEW_VERSION}${PACKAGE_VERSION_TAGS}"
  38. do_version_sed "${NEW_VERSION}" \
  39. "Bump ${CMD} package version number"
  40. }
  41. do_version_bump_major() {
  42. do_version_bump_sed "$((PACKAGE_MAJOR + 1)).0.0"
  43. }
  44. do_version_bump_minor() {
  45. do_version_bump_sed "${PACKAGE_MAJOR}.$((PACKAGE_MINOR + 1)).0"
  46. }
  47. do_version_bump_micro() {
  48. do_version_bump_sed "${PACKAGE_MAJOR_AND_MINOR}.$((PACKAGE_MICRO + 1))"
  49. }
  50. do_version_bump_tag() {
  51. local TAG="$1"
  52. [ "${TAG}" ] || die "TAG argument is missing"
  53. local TAGS="${PACKAGE_VERSION_TAGS}"
  54. if has_version_tag "${TAG}"; then
  55. local RC=$(do_version_tag_value "${TAG}")
  56. RC=$((${RC} + 1))
  57. TAGS=$(echo ${TAGS} | perl -npe "s/-${TAG}[\\d]*/-${TAG}${RC}/")
  58. else
  59. TAGS="-${TAG}0${PACKAGE_VERSION_TAGS}"
  60. fi
  61. PACKAGE_VERSION_TAGS="${TAGS}"
  62. do_version_bump_sed "${PACKAGE_VERSION_BASE}"
  63. }
  64. do_version_bump_final() {
  65. local TAG="$1"
  66. [ "${TAG}" ] || die "TAG argument is missing"
  67. has_version_tag "${TAG}" || die "-${TAG} tag is missing"
  68. do_version_tag_remove "${TAG}$(do_version_tag_value "${TAG}")"
  69. }
  70. do_version_bump() {
  71. CMD="$1"
  72. shift
  73. case "${CMD}" in
  74. major|minor|micro|final|tag)
  75. "do_version_bump_${CMD}" "$@"
  76. ;;
  77. rc)
  78. do_version_bump_tag "rc"
  79. ;;
  80. *)
  81. do_version_usage
  82. ;;
  83. esac
  84. }
  85. has_version_tag() {
  86. test "${PACKAGE_VERSION/-${1}/}" != "${PACKAGE_VERSION}"
  87. }
  88. do_version_tag_value() {
  89. local TAG="$1"
  90. echo ${PACKAGE_VERSION_TAGS} | perl -ne "/-${TAG}"'(\d+)/ && print $1'
  91. }
  92. do_version_tag_add() {
  93. local TAG="$1"
  94. has_version_tag "${TAG}" && \
  95. die "error: tag '-${TAG}' exists in '${PACKAGE_VERSION}'"
  96. do_version_sed "${PACKAGE_VERSION}-${TAG}" \
  97. "Add '-${TAG}' version tag"
  98. }
  99. do_version_tag_remove() {
  100. local TAG="$1"
  101. has_version_tag "${TAG}" || \
  102. die "error: tag '-${TAG}' missing from '${PACKAGE_VERSION}'"
  103. do_version_sed "${PACKAGE_VERSION/-${TAG}/}" \
  104. "Remove '-${TAG}' version tag"
  105. }
  106. do_version_tag() {
  107. CMD="$1"
  108. shift
  109. case "${CMD}" in
  110. add|remove)
  111. local i=
  112. for i in "$@"; do
  113. "do_version_tag_${CMD}" "${i}"
  114. done
  115. ;;
  116. *)
  117. do_version_usage
  118. ;;
  119. esac
  120. }
  121. do_version() {
  122. CMD="$1"
  123. shift
  124. case "${CMD}" in
  125. tag|bump)
  126. "do_version_${CMD}" "$@"
  127. ;;
  128. commit)
  129. do_version_commit "$@"
  130. ;;
  131. *)
  132. do_version_usage
  133. ;;
  134. esac
  135. }
  136. package_info_load
  137. do_version "$@"