release-version-fn.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #! /bin/sh
  2. # Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # These functions load, manipulate and store the current version information
  9. # for OpenSSL 3.0 and on.
  10. # They are meant to be minimalistic for easy refactoring depending on OpenSSL
  11. # version.
  12. #
  13. # Version information is stored in the following variables:
  14. #
  15. # |MAJOR|, |MINOR|, |PATCH| are the three parts of a version number.
  16. # |MAJOR| is to be increased for new major releases, |MINOR| for new
  17. # minor releases, and |PATCH| for update releases.
  18. #
  19. # |SERIES| tells what release series the current version belongs to, and
  20. # is composed from |MAJOR| and |MINOR|.
  21. # |VERSION| tells what the current version is, and is composed from |MAJOR|,
  22. # |MINOR| and |PATCH|.
  23. # |TYPE| tells what state the source is in. It may have an empty value
  24. # for released source, or 'dev' for "in development".
  25. # |PRE_LABEL| may be "alpha" or "beta" to signify an ongoing series of
  26. # alpha or beta releases. |PRE_NUM| is a pre-release counter for the
  27. # alpha and beta release series, but isn't necessarily strictly tied
  28. # to the prerelease label.
  29. #
  30. # Scripts loading this file are not allowed to manipulate these
  31. # variables directly. They must use functions such as fixup_version()
  32. # below, or next_release_state(), found in release-state-fn.sh.
  33. # These functions depend on |SOURCEDIR|, which must have the intended
  34. # OpenSSL source directory as value.
  35. get_version () {
  36. eval $(git cat-file blob HEAD:VERSION)
  37. VERSION="$MAJOR.$MINOR.$PATCH"
  38. SERIES="$MAJOR.$MINOR"
  39. TYPE=$( echo "$PRE_RELEASE_TAG" \
  40. | sed -E \
  41. -e 's|^dev$|dev|' \
  42. -e 's|^alpha([0-9]+)(-(dev))?$|\3|' \
  43. -e 's|^beta([0-9]+)(-(dev))?$|\3|' )
  44. PRE_LABEL=$( echo "$PRE_RELEASE_TAG" \
  45. | sed -E \
  46. -e 's|^dev$||' \
  47. -e 's|^alpha([0-9]+)(-(dev))?$|alpha|' \
  48. -e 's|^beta([0-9]+)(-(dev))?$|beta|' )
  49. PRE_NUM=$( echo "$PRE_RELEASE_TAG" \
  50. | sed -E \
  51. -e 's|^dev$|0|' \
  52. -e 's|^alpha([0-9]+)(-(dev))?$|\1|' \
  53. -e 's|^beta([0-9]+)(-(dev))?$|\1|' )
  54. }
  55. # $1 is one of "alpha", "beta", "final", "", or "minor"
  56. fixup_version () {
  57. local new_label="$1"
  58. case "$new_label" in
  59. alpha | beta )
  60. if [ "$new_label" != "$PRE_LABEL" ]; then
  61. PRE_LABEL="$new_label"
  62. PRE_NUM=1
  63. elif [ "$TYPE" = 'dev' ]; then
  64. PRE_NUM=$(expr $PRE_NUM + 1)
  65. fi
  66. ;;
  67. final | '' )
  68. if [ "$TYPE" = 'dev' ]; then
  69. PATCH=$(expr $PATCH + 1)
  70. fi
  71. PRE_LABEL=
  72. PRE_NUM=0
  73. ;;
  74. minor )
  75. if [ "$TYPE" = 'dev' ]; then
  76. MINOR=$(expr $MINOR + 1)
  77. PATCH=0
  78. fi
  79. PRE_LABEL=
  80. PRE_NUM=0
  81. ;;
  82. esac
  83. VERSION="$MAJOR.$MINOR.$PATCH"
  84. SERIES="$MAJOR.$MINOR"
  85. }
  86. set_version () {
  87. case "$TYPE+$PRE_LABEL+$PRE_NUM" in
  88. *++* )
  89. PRE_RELEASE_TAG="$TYPE"
  90. ;;
  91. dev+* )
  92. PRE_RELEASE_TAG="$PRE_LABEL$PRE_NUM-dev"
  93. ;;
  94. +* )
  95. PRE_RELEASE_TAG="$PRE_LABEL$PRE_NUM"
  96. ;;
  97. esac
  98. cat > "$SOURCEDIR/VERSION" <<EOF
  99. MAJOR=$MAJOR
  100. MINOR=$MINOR
  101. PATCH=$PATCH
  102. PRE_RELEASE_TAG=$PRE_RELEASE_TAG
  103. BUILD_METADATA=$BUILD_METADATA
  104. RELEASE_DATE="$RELEASE_DATE"
  105. SHLIB_VERSION=$SHLIB_VERSION
  106. EOF
  107. }