summaryrefslogtreecommitdiff
path: root/dev/release-aux/release-version-fn.sh
blob: e9e1ac3850785f779867e4e8233b24364d5428fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /bin/sh
# Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html

# These functions load, manipulate and store the current version information
# for OpenSSL 3.0 and on.
# They are meant to be minimalistic for easy refactoring depending on OpenSSL
# version.
#
# Version information is stored in the following variables:
#
# |MAJOR|, |MINOR|, |PATCH| are the three parts of a version number.
# |MAJOR| is to be increased for new major releases, |MINOR| for new
# minor releases, and |PATCH| for update releases.
#
# |SERIES| tells what release series the current version belongs to, and
# is composed from |MAJOR| and |MINOR|.
# |VERSION| tells what the current version is, and is composed from |MAJOR|,
# |MINOR| and |PATCH|.
# |TYPE| tells what state the source is in.  It may have an empty value
# for released source, or 'dev' for "in development".
# |PRE_LABEL| may be "alpha" or "beta" to signify an ongoing series of
# alpha or beta releases.  |PRE_NUM| is a pre-release counter for the
# alpha and beta release series, but isn't necessarily strictly tied
# to the prerelease label.
#
# Scripts loading this file are not allowed to manipulate these
# variables directly.  They must use functions such as fixup_version()
# below, or next_release_state(), found in release-state-fn.sh.

# These functions depend on |SOURCEDIR|, which must have the intended
# OpenSSL source directory as value.

get_version () {
    eval $(git cat-file blob HEAD:VERSION.dat)
    VERSION="$MAJOR.$MINOR.$PATCH"
    SERIES="$MAJOR.$MINOR"
    TYPE=$( echo "$PRE_RELEASE_TAG" \
                | sed -E \
                      -e 's|^dev$|dev|' \
                      -e 's|^alpha([0-9]+)(-(dev))?$|\3|' \
                      -e 's|^beta([0-9]+)(-(dev))?$|\3|' )
    PRE_LABEL=$( echo "$PRE_RELEASE_TAG" \
                     | sed -E \
                           -e 's|^dev$||' \
                           -e 's|^alpha([0-9]+)(-(dev))?$|alpha|' \
                           -e 's|^beta([0-9]+)(-(dev))?$|beta|' )
    PRE_NUM=$( echo "$PRE_RELEASE_TAG" \
                   | sed -E \
                         -e 's|^dev$|0|' \
                         -e 's|^alpha([0-9]+)(-(dev))?$|\1|' \
                         -e 's|^beta([0-9]+)(-(dev))?$|\1|' )
}

# $1 is one of "alpha", "beta", "final", "", or "minor"
fixup_version () {
    local new_label="$1"

    case "$new_label" in
        alpha | beta )
            if [ "$new_label" != "$PRE_LABEL" ]; then
                PRE_LABEL="$new_label"
                PRE_NUM=1
            elif [ "$TYPE" = 'dev' ]; then
                PRE_NUM=$(expr $PRE_NUM + 1)
            fi
            ;;
        final | '' )
            if [ "$TYPE" = 'dev' ]; then
                PATCH=$(expr $PATCH + 1)
            fi
            PRE_LABEL=
            PRE_NUM=0
            ;;
        minor )
            if [ "$TYPE" = 'dev' ]; then
                MINOR=$(expr $MINOR + 1)
                PATCH=0
            fi
            PRE_LABEL=
            PRE_NUM=0
            ;;
    esac

    VERSION="$MAJOR.$MINOR.$PATCH"
    SERIES="$MAJOR.$MINOR"
}

set_version () {
    case "$TYPE+$PRE_LABEL+$PRE_NUM" in
        *++* )
            PRE_RELEASE_TAG="$TYPE"
            ;;
        dev+* )
            PRE_RELEASE_TAG="$PRE_LABEL$PRE_NUM-dev"
            ;;
        +* )
            PRE_RELEASE_TAG="$PRE_LABEL$PRE_NUM"
            ;;
    esac
    cat > "$SOURCEDIR/VERSION.dat" <<EOF
MAJOR=$MAJOR
MINOR=$MINOR
PATCH=$PATCH
PRE_RELEASE_TAG=$PRE_RELEASE_TAG
BUILD_METADATA=$BUILD_METADATA
RELEASE_DATE="$RELEASE_DATE"
SHLIB_VERSION=$SHLIB_VERSION
EOF
}