2
0

release-version-fn.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.dat)
  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. _BUILD_METADATA=''
  55. if [ -n "$PRE_RELEASE_TAG" ]; then _PRE_RELEASE_TAG="-${PRE_RELEASE_TAG}"; fi
  56. if [ -n "$BUILD_METADATA" ]; then _BUILD_METADATA="+${BUILD_METADATA}"; fi
  57. }
  58. # $1 is one of "alpha", "beta", "final", "", or "minor"
  59. fixup_version () {
  60. local new_label="$1"
  61. case "$new_label" in
  62. alpha | beta )
  63. if [ "$new_label" != "$PRE_LABEL" ]; then
  64. PRE_LABEL="$new_label"
  65. PRE_NUM=1
  66. elif [ "$TYPE" = 'dev' ]; then
  67. PRE_NUM=$(expr $PRE_NUM + 1)
  68. fi
  69. ;;
  70. final | '' )
  71. if [ "$TYPE" = 'dev' ]; then
  72. PATCH=$(expr $PATCH + 1)
  73. fi
  74. PRE_LABEL=
  75. PRE_NUM=0
  76. ;;
  77. minor )
  78. if [ "$TYPE" = 'dev' ]; then
  79. MINOR=$(expr $MINOR + 1)
  80. PATCH=0
  81. fi
  82. PRE_LABEL=
  83. PRE_NUM=0
  84. ;;
  85. esac
  86. VERSION="$MAJOR.$MINOR.$PATCH"
  87. SERIES="$MAJOR.$MINOR"
  88. }
  89. set_version () {
  90. case "$TYPE+$PRE_LABEL+$PRE_NUM" in
  91. *++* )
  92. PRE_RELEASE_TAG="$TYPE"
  93. ;;
  94. dev+* )
  95. PRE_RELEASE_TAG="$PRE_LABEL$PRE_NUM-dev"
  96. ;;
  97. +* )
  98. PRE_RELEASE_TAG="$PRE_LABEL$PRE_NUM"
  99. ;;
  100. esac
  101. if [ -n "$PRE_RELEASE_TAG" ]; then _PRE_RELEASE_TAG="-${PRE_RELEASE_TAG}"; fi
  102. cat > "$SOURCEDIR/VERSION.dat" <<EOF
  103. MAJOR=$MAJOR
  104. MINOR=$MINOR
  105. PATCH=$PATCH
  106. PRE_RELEASE_TAG=$PRE_RELEASE_TAG
  107. BUILD_METADATA=$BUILD_METADATA
  108. RELEASE_DATE="$RELEASE_DATE"
  109. SHLIB_VERSION=$SHLIB_VERSION
  110. EOF
  111. }