From 863274373b5dc6714af251b3c05a004ac0b1ede3 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Fri, 18 Jul 2025 11:21:28 -0700 Subject: [PATCH 1/3] Fix tag logic in build script --- scripts/utils-openssl.sh | 6 +++++- scripts/utils-wolfssl.sh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/utils-openssl.sh b/scripts/utils-openssl.sh index aa2eb5c7..62bd9564 100755 --- a/scripts/utils-openssl.sh +++ b/scripts/utils-openssl.sh @@ -39,7 +39,11 @@ USE_CUR_TAG=${USE_CUR_TAG:-0} clone_openssl() { if [ -d ${OPENSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then - OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current)) + if [[ "${OPENSSL_TAG}" == openssl-* ]]; then + OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current 2>/dev/null)) + else + OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git branch --show-current 2>/dev/null || git describe --tags 2>/dev/null)) + fi if [ "${OPENSSL_TAG_CUR}" != "${OPENSSL_TAG}" ]; then # force a rebuild printf "Version inconsistency. Please fix ${OPENSSL_SOURCE_DIR} (expected: ${OPENSSL_TAG}, got: ${OPENSSL_TAG_CUR})\n" do_cleanup diff --git a/scripts/utils-wolfssl.sh b/scripts/utils-wolfssl.sh index 9dfae91a..ff9572cd 100755 --- a/scripts/utils-wolfssl.sh +++ b/scripts/utils-wolfssl.sh @@ -44,7 +44,11 @@ clone_wolfssl() { cp -pr ${WOLFSSL_FIPS_BUNDLE}/* ${WOLFSSL_SOURCE_DIR}/ else if [ -d ${WOLFSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then - WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current)) + if [[ "${WOLFSSL_TAG}" == v* ]] || [[ "${WOLFSSL_TAG}" == *-stable ]]; then + WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current 2>/dev/null)) + else + WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git branch --show-current 2>/dev/null || git describe --tags 2>/dev/null)) + fi if [ "${WOLFSSL_TAG_CUR}" != "${WOLFSSL_TAG}" ]; then # force a rebuild printf "Version inconsistency. Please fix ${WOLFSSL_SOURCE_DIR} (expected: ${WOLFSSL_TAG}, got: ${WOLFSSL_TAG_CUR})\n" do_cleanup From ad53f573f4d9dc002f1f53bd603971db07d35b36 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Tue, 22 Jul 2025 16:26:27 -0700 Subject: [PATCH 2/3] Add general function for matching tags --- scripts/utils-general.sh | 39 +++++++++++++++++++++++++++++++++++++++ scripts/utils-openssl.sh | 13 ++----------- scripts/utils-wolfssl.sh | 11 +---------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/scripts/utils-general.sh b/scripts/utils-general.sh index a553624b..b32ed857 100644 --- a/scripts/utils-general.sh +++ b/scripts/utils-general.sh @@ -48,3 +48,42 @@ check_folder_age() { fi } +# Usage: check_git_match [] +check_git_match() { + local target_ref="$1" + local repo_dir="${2:-.}" + + # Save current directory and move to repo + local oldpwd="$PWD" + cd "$repo_dir" || return 2 + + local current_tag current_branch current_commit_long current_commit_short + current_tag=$(git describe --tags --exact-match 2>/dev/null || true) + current_branch=$(git symbolic-ref --short HEAD 2>/dev/null || true) + current_commit_long=$(git rev-parse HEAD 2>/dev/null || true) + current_commit_short=$(git rev-parse --short HEAD 2>/dev/null || true) + + if [[ -n "$current_tag" && "$target_ref" == "$current_tag" ]]; then + echo "match: tag ($current_tag)" + cd "$oldpwd" + return 0 + elif [[ -n "$current_branch" && "$target_ref" == "$current_branch" ]]; then + echo "match: branch ($current_branch)" + cd "$oldpwd" + return 0 + elif [[ -n "$current_commit_long" && "$target_ref" == "$current_commit_long" ]]; then + echo "match: commit (long $current_commit_long)" + cd "$oldpwd" + return 0 + elif [[ -n "$current_commit_short" && "$target_ref" == "$current_commit_short" ]]; then + echo "match: commit (short $current_commit_short)" + cd "$oldpwd" + return 0 + else + echo "no match found for $target_ref" + printf "Version inconsistency. Please fix ${repo_dir}\n" + printf "(expected: ${target_ref}, got: ${current_tag} ${current_branch} ${current_commit_long} ${current_commit_short})\n" + cd "$oldpwd" + exit 1 + fi +} diff --git a/scripts/utils-openssl.sh b/scripts/utils-openssl.sh index 62bd9564..7cf043a9 100755 --- a/scripts/utils-openssl.sh +++ b/scripts/utils-openssl.sh @@ -39,16 +39,7 @@ USE_CUR_TAG=${USE_CUR_TAG:-0} clone_openssl() { if [ -d ${OPENSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then - if [[ "${OPENSSL_TAG}" == openssl-* ]]; then - OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current 2>/dev/null)) - else - OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git branch --show-current 2>/dev/null || git describe --tags 2>/dev/null)) - fi - if [ "${OPENSSL_TAG_CUR}" != "${OPENSSL_TAG}" ]; then # force a rebuild - printf "Version inconsistency. Please fix ${OPENSSL_SOURCE_DIR} (expected: ${OPENSSL_TAG}, got: ${OPENSSL_TAG_CUR})\n" - do_cleanup - exit 1 - fi + check_git_match "${OPENSSL_TAG}" "${OPENSSL_SOURCE_DIR}" fi if [ ! -d ${OPENSSL_SOURCE_DIR} ]; then @@ -87,7 +78,7 @@ clone_openssl() { } install_openssl() { - printf "\nInstalling OpenSSL ${OPENSSL_TAG} ..." + printf "\nInstalling OpenSSL ${OPENSSL_TAG} ...\n" clone_openssl cd ${OPENSSL_SOURCE_DIR} diff --git a/scripts/utils-wolfssl.sh b/scripts/utils-wolfssl.sh index ff9572cd..5827205b 100755 --- a/scripts/utils-wolfssl.sh +++ b/scripts/utils-wolfssl.sh @@ -44,16 +44,7 @@ clone_wolfssl() { cp -pr ${WOLFSSL_FIPS_BUNDLE}/* ${WOLFSSL_SOURCE_DIR}/ else if [ -d ${WOLFSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then - if [[ "${WOLFSSL_TAG}" == v* ]] || [[ "${WOLFSSL_TAG}" == *-stable ]]; then - WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current 2>/dev/null)) - else - WOLFSSL_TAG_CUR=$(cd ${WOLFSSL_SOURCE_DIR} && (git branch --show-current 2>/dev/null || git describe --tags 2>/dev/null)) - fi - if [ "${WOLFSSL_TAG_CUR}" != "${WOLFSSL_TAG}" ]; then # force a rebuild - printf "Version inconsistency. Please fix ${WOLFSSL_SOURCE_DIR} (expected: ${WOLFSSL_TAG}, got: ${WOLFSSL_TAG_CUR})\n" - do_cleanup - exit 1 - fi + check_git_match "${WOLFSSL_TAG}" "${WOLFSSL_SOURCE_DIR}" fi if [ ! -d ${WOLFSSL_SOURCE_DIR} ]; then From a43888abbf83033ba7efc027b7781937a9ed50e9 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Wed, 23 Jul 2025 10:57:32 -0700 Subject: [PATCH 3/3] Use pushd and popd --- scripts/utils-general.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/utils-general.sh b/scripts/utils-general.sh index b32ed857..2c0fff12 100644 --- a/scripts/utils-general.sh +++ b/scripts/utils-general.sh @@ -53,9 +53,7 @@ check_git_match() { local target_ref="$1" local repo_dir="${2:-.}" - # Save current directory and move to repo - local oldpwd="$PWD" - cd "$repo_dir" || return 2 + pushd "$repo_dir" > /dev/null || return 2 local current_tag current_branch current_commit_long current_commit_short current_tag=$(git describe --tags --exact-match 2>/dev/null || true) @@ -65,25 +63,25 @@ check_git_match() { if [[ -n "$current_tag" && "$target_ref" == "$current_tag" ]]; then echo "match: tag ($current_tag)" - cd "$oldpwd" + popd > /dev/null return 0 elif [[ -n "$current_branch" && "$target_ref" == "$current_branch" ]]; then echo "match: branch ($current_branch)" - cd "$oldpwd" + popd > /dev/null return 0 elif [[ -n "$current_commit_long" && "$target_ref" == "$current_commit_long" ]]; then echo "match: commit (long $current_commit_long)" - cd "$oldpwd" + popd > /dev/null return 0 elif [[ -n "$current_commit_short" && "$target_ref" == "$current_commit_short" ]]; then echo "match: commit (short $current_commit_short)" - cd "$oldpwd" + popd > /dev/null return 0 else echo "no match found for $target_ref" printf "Version inconsistency. Please fix ${repo_dir}\n" printf "(expected: ${target_ref}, got: ${current_tag} ${current_branch} ${current_commit_long} ${current_commit_short})\n" - cd "$oldpwd" + popd > /dev/null exit 1 fi }