xref: /spdk/test/app/version.sh (revision b3bec07939ebe2ea2e0c43931705d32aa9e06719)
1#!/usr/bin/env bash
2# SPDX-License-Identifier: BSD-3-Clause
3# Copyright (C) 2023 Intel Corporation
4# All rights reserved.
5#
6
7testdir=$(readlink -f $(dirname $0))
8rootdir=$(readlink -f $testdir/../..)
9
10source "$rootdir/test/common/autotest_common.sh"
11
12get_header_version() {
13	grep -E "^#define SPDK_VERSION_${1^^}[[:space:]]+" "$rootdir/include/spdk/version.h" \
14		| cut -f2 | tr -d \"
15}
16
17major=$(get_header_version major)
18minor=$(get_header_version minor)
19patch=$(get_header_version patch)
20suffix=$(get_header_version suffix)
21
22version="${major}.${minor}"
23
24# If patch is zero, we don't keep it in the version
25((patch != 0)) && version="${version}.${patch}"
26# In python world, the version format is a little different than what we use (see PEP 440), so we
27# need to replace "-pre" with "rc0"
28version="${version}${suffix/-pre/rc0}"
29
30PYTHONPATH="$PYTHONPATH:$rootdir/python" py_version=$(python3 -c 'import spdk; print(spdk.__version__)')
31[[ "$py_version" == "$version" ]]
32