Skip to content

Commit

Permalink
Fix interpreting version numbers as octal
Browse files Browse the repository at this point in the history
Bash interprets any number with leading zero as an octal instead of
decimal, so make sure it doesn't happen if any version number has a
leading zero in version input file.

Signed-off-by: Rafal Stefanowski <rafal.stefanowski@huawei.com>
Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
  • Loading branch information
Rafal Stefanowski authored and robertbaldyga committed Sep 10, 2024
1 parent 72026ce commit 69c4ca2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/cas_version_gen.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#
# Copyright(c) 2020-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#

Expand Down Expand Up @@ -30,13 +31,19 @@ if [[ -d "$SOURCES_DIR/.git" ]] && which git &>/dev/null &&\
if [[ ! -r "$MANUAL_VERSION_INPUT" ]]; then
error "can't read version input file '$MANUAL_VERSION_INPUT'"
fi
. "$MANUAL_VERSION_INPUT"
source "$MANUAL_VERSION_INPUT"
if [[ ! "$CAS_VERSION_MAIN" || ! "$CAS_VERSION_MAJOR" || ! "$CAS_VERSION_MINOR" ]]; then
error "'$MANUAL_VERSION_INPUT' - wrong version input file format;"\
"file should contain CAS_VERSION_MAIN, CAS_VERSION_MAJOR and CAS_VERSION_MINOR"\
"variables along with their respective values"
fi

# Make sure version numbers are interpreted by bash as decimal numbers in case any of
# them were being input with leading zeros, which is interpreted as an octal by default.
CAS_VERSION_MAIN=$((10#$CAS_VERSION_MAIN))
CAS_VERSION_MAJOR=$((10#$CAS_VERSION_MAJOR))
CAS_VERSION_MINOR=$((10#$CAS_VERSION_MINOR))

CAS_VERSION_BUILD=$(cd "$SOURCES_DIR" && git log --merges --oneline | wc -l)
LAST_COMMIT_HASH=$(cd "$SOURCES_DIR" && git log -1 --pretty=format:%H)
LAST_COMMIT_HASH_ABBR=$(cd "$SOURCES_DIR" && git log -1 --pretty=format:%h)
Expand Down Expand Up @@ -80,7 +87,7 @@ if [[ -d "$SOURCES_DIR/.git" ]] && which git &>/dev/null &&\
echo "FILE_CREATION_DATE=$FILE_CREATION_DATE" >> "$VERSION_FILE"
echo "FILE_CREATION_TIMESTAMP=$FILE_CREATION_TIMESTAMP" >> "$VERSION_FILE"
elif [[ -r "$VERSION_FILE" ]]; then
. "$VERSION_FILE" >/dev/null
source "$VERSION_FILE" >/dev/null
if [[ ! "$CAS_VERSION" ]]; then
error "'$VERSION_FILE' - wrong version file format; file does not contain CAS_VERSION"
fi
Expand Down

0 comments on commit 69c4ca2

Please sign in to comment.