From 5944104a52889f5f4477a658af73b1889bf7c9ab Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Fri, 11 Apr 2025 14:39:37 +0200 Subject: [PATCH] scripts: make demo_common.sh usable on its own When looking for $root_dir, do not try to guess if the root path is Mbed TLS or TF-PSA-Crypto one, but simply look for "scripts/project_name.txt" file without reading it. In this way the initial part of the script does not need "project_detection.sh". Once the root path is found, we can easily: - source "project_detection.sh"; - check if query_compile_time_config is available or not. This commit also updates "dlopen_demo.sh" so that it simply sources "demo_common.sh" and not "project_detection.sh" (not directly at least). Signed-off-by: Valerio Setti Signed-off-by: Ronald Cron --- scripts/demo_common.sh | 62 +++++++++++++++++++++-------------- tests/programs/dlopen_demo.sh | 10 ++---- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/scripts/demo_common.sh b/scripts/demo_common.sh index 4ad4c7187..8f5c942d0 100644 --- a/scripts/demo_common.sh +++ b/scripts/demo_common.sh @@ -16,14 +16,13 @@ set -e -u -DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG=${DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG:-1} - -need_query_compile_time_config () { - if [ $DEMO_COMMON_NEED_QUERY_COMPILE_TIME_CONFIG -eq 1 ]; then - return 0; - else +# Check if the provided path ($1) can be a valid root for Mbed TLS or TF-PSA-Crypto. +# This is based on the fact that "scripts/project_name.txt" exists. +is_valid_root () { + if ! [ -f "$1/scripts/project_name.txt" ]; then return 1; fi + return 0; } ## At the end of the while loop below $root_dir will point to the root directory @@ -35,21 +34,15 @@ root_dir="${0%/*}" ## ## The code works no matter where the demo script is relative to the current ## directory, even if it is called with a relative path. -n=5 +n=4 while true; do # If we went up too many folders, then give up and return a failure. if [ $n -eq 0 ]; then echo >&2 "This doesn't seem to be an Mbed TLS source tree." exit 125 fi - # If we reached the Mbed TLS root folder then we're done. - if is_mbedtls_root "$root_dir"; then - break; - fi - # If we reached the TF-PSA-Crypto root folder and the script that sourced - # this file does not need query_compile_time_config (which is only available - # in Mbed TLS repo) then we're done. - if is_tf_psa_crypto_root "$root_dir" && ! need_query_compile_time_config; then + + if is_valid_root "$root_dir"; then break; fi @@ -63,6 +56,9 @@ while true; do esac done +# Now that we have a root path we can source the "project_detection.sh" script. +. "$root_dir/framework/scripts/project_detection.sh" + ## msg LINE... ## msg