Skip to content

Commit ad53f57

Browse files
committed
Add general function for matching tags
1 parent 8632743 commit ad53f57

3 files changed

Lines changed: 42 additions & 21 deletions

File tree

scripts/utils-general.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,42 @@ check_folder_age() {
4848
fi
4949
}
5050

51+
# Usage: check_git_match <target_ref> [<repo_dir>]
52+
check_git_match() {
53+
local target_ref="$1"
54+
local repo_dir="${2:-.}"
55+
56+
# Save current directory and move to repo
57+
local oldpwd="$PWD"
58+
cd "$repo_dir" || return 2
59+
60+
local current_tag current_branch current_commit_long current_commit_short
61+
current_tag=$(git describe --tags --exact-match 2>/dev/null || true)
62+
current_branch=$(git symbolic-ref --short HEAD 2>/dev/null || true)
63+
current_commit_long=$(git rev-parse HEAD 2>/dev/null || true)
64+
current_commit_short=$(git rev-parse --short HEAD 2>/dev/null || true)
65+
66+
if [[ -n "$current_tag" && "$target_ref" == "$current_tag" ]]; then
67+
echo "match: tag ($current_tag)"
68+
cd "$oldpwd"
69+
return 0
70+
elif [[ -n "$current_branch" && "$target_ref" == "$current_branch" ]]; then
71+
echo "match: branch ($current_branch)"
72+
cd "$oldpwd"
73+
return 0
74+
elif [[ -n "$current_commit_long" && "$target_ref" == "$current_commit_long" ]]; then
75+
echo "match: commit (long $current_commit_long)"
76+
cd "$oldpwd"
77+
return 0
78+
elif [[ -n "$current_commit_short" && "$target_ref" == "$current_commit_short" ]]; then
79+
echo "match: commit (short $current_commit_short)"
80+
cd "$oldpwd"
81+
return 0
82+
else
83+
echo "no match found for $target_ref"
84+
printf "Version inconsistency. Please fix ${repo_dir}\n"
85+
printf "(expected: ${target_ref}, got: ${current_tag} ${current_branch} ${current_commit_long} ${current_commit_short})\n"
86+
cd "$oldpwd"
87+
exit 1
88+
fi
89+
}

scripts/utils-openssl.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,7 @@ USE_CUR_TAG=${USE_CUR_TAG:-0}
3939

4040
clone_openssl() {
4141
if [ -d ${OPENSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then
42-
if [[ "${OPENSSL_TAG}" == openssl-* ]]; then
43-
OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current 2>/dev/null))
44-
else
45-
OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git branch --show-current 2>/dev/null || git describe --tags 2>/dev/null))
46-
fi
47-
if [ "${OPENSSL_TAG_CUR}" != "${OPENSSL_TAG}" ]; then # force a rebuild
48-
printf "Version inconsistency. Please fix ${OPENSSL_SOURCE_DIR} (expected: ${OPENSSL_TAG}, got: ${OPENSSL_TAG_CUR})\n"
49-
do_cleanup
50-
exit 1
51-
fi
42+
check_git_match "${OPENSSL_TAG}" "${OPENSSL_SOURCE_DIR}"
5243
fi
5344

5445
if [ ! -d ${OPENSSL_SOURCE_DIR} ]; then
@@ -87,7 +78,7 @@ clone_openssl() {
8778
}
8879

8980
install_openssl() {
90-
printf "\nInstalling OpenSSL ${OPENSSL_TAG} ..."
81+
printf "\nInstalling OpenSSL ${OPENSSL_TAG} ...\n"
9182
clone_openssl
9283
cd ${OPENSSL_SOURCE_DIR}
9384

scripts/utils-wolfssl.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ clone_wolfssl() {
4444
cp -pr ${WOLFSSL_FIPS_BUNDLE}/* ${WOLFSSL_SOURCE_DIR}/
4545
else
4646
if [ -d ${WOLFSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then
47-
if [[ "${WOLFSSL_TAG}" == v* ]] || [[ "${WOLFSSL_TAG}" == *-stable ]]; then
48-
WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current 2>/dev/null))
49-
else
50-
WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git branch --show-current 2>/dev/null || git describe --tags 2>/dev/null))
51-
fi
52-
if [ "${WOLFSSL_TAG_CUR}" != "${WOLFSSL_TAG}" ]; then # force a rebuild
53-
printf "Version inconsistency. Please fix ${WOLFSSL_SOURCE_DIR} (expected: ${WOLFSSL_TAG}, got: ${WOLFSSL_TAG_CUR})\n"
54-
do_cleanup
55-
exit 1
56-
fi
47+
check_git_match "${WOLFSSL_TAG}" "${WOLFSSL_SOURCE_DIR}"
5748
fi
5849

5950
if [ ! -d ${WOLFSSL_SOURCE_DIR} ]; then

0 commit comments

Comments
 (0)