Skip to content

Commit

Permalink
Merge pull request Mbed-TLS#67 from Mbed-TLS/issue-39
Browse files Browse the repository at this point in the history
Add project and branch detection in shell
  • Loading branch information
davidhorstmann-arm authored Nov 27, 2024
2 parents f1119c2 + c3cee62 commit df0144c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 16 deletions.
17 changes: 2 additions & 15 deletions scripts/all-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,9 @@ pre_set_shell_options () {
set -e -o pipefail -u
}

# For project detection
in_mbedtls_repo () {
test "$PROJECT_NAME" = "Mbed TLS"
}

in_tf_psa_crypto_repo () {
test "$PROJECT_NAME" = "TF-PSA-Crypto"
}

pre_check_environment () {
# For project detection
PROJECT_NAME_FILE='./scripts/project_name.txt'
if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else
echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2
exit 1
fi

source $FRAMEWORK/scripts/project_detection.sh

if in_mbedtls_repo || in_tf_psa_crypto_repo; then :; else
echo "Must be run from Mbed TLS / TF-PSA-Crypto root" >&2
Expand Down
2 changes: 1 addition & 1 deletion scripts/mbedtls_framework/build_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def guess_tf_psa_crypto_root(root: Optional[str] = None) -> str:
def is_mbedtls_3_6() -> bool:
"""Whether the working tree is an Mbed TLS 3.6 one or not
Return false in we are in TF-PSA-Crypto or in Mbed TLS but with a version
Return false if we are in TF-PSA-Crypto or in Mbed TLS but with a version
different from 3.6.x.
Raise an exception if we are neither in Mbed TLS nor in TF-PSA-Crypto.
"""
Expand Down
67 changes: 67 additions & 0 deletions scripts/project_detection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# project-detection.sh
#
# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
#
# Purpose
#
# This script contains functions for shell scripts to
# help detect which project (Mbed TLS, TF-PSA-Crypto)
# or which Mbed TLS branch they are in.

# Project detection
read_project_name_file () {
SCRIPT_DIR=$(pwd)

PROJECT_NAME_FILE="scripts/project_name.txt"

if read -r PROJECT_NAME < "$PROJECT_NAME_FILE"; then :; else
echo "$PROJECT_NAME_FILE does not exist... Exiting..." >&2
exit 1
fi
}

in_mbedtls_repo () {
read_project_name_file
test "$PROJECT_NAME" = "Mbed TLS"
}

in_tf_psa_crypto_repo () {
read_project_name_file
test "$PROJECT_NAME" = "TF-PSA-Crypto"
}

#Branch detection
read_build_info () {
SCRIPT_DIR=$(pwd)

BUILD_INFO_FILE="include/mbedtls/build_info.h"

if [ ! -f "$BUILD_INFO_FILE" ]; then
echo "File $BUILD_INFO_FILE not found."
exit 1
fi

MBEDTLS_VERSION_MAJOR=$(grep "^#define MBEDTLS_VERSION_MAJOR" "$BUILD_INFO_FILE" | awk '{print $3}')
MBEDTLS_VERSION_MINOR=$(grep "^#define MBEDTLS_VERSION_MINOR" "$BUILD_INFO_FILE" | awk '{print $3}')

if [ -z "$MBEDTLS_VERSION_MAJOR" ]; then
echo "MBEDTLS_VERSION_MAJOR not found in $BUILD_INFO_FILE."
exit 1
fi

if [ -z "$MBEDTLS_VERSION_MINOR" ]; then
echo "MBEDTLS_VERSION_MINOR not found in $BUILD_INFO_FILE."
exit 1
fi
}

in_3_6_branch () {
read_build_info
test $MBEDTLS_VERSION_MAJOR = "3" && test $MBEDTLS_VERSION_MINOR = "6"
}

in_4_x_branch () {
read_build_info
test $MBEDTLS_VERSION_MAJOR = "4"
}

0 comments on commit df0144c

Please sign in to comment.