From f7325865bb55231108e32698285b09710911aba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 1 Oct 2024 11:54:34 +0200 Subject: [PATCH] all.sh: first define functions, then call them. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't interleave defining functions with running some code. The only exception is calling shopt, which needs to come first as it affects how the following function definitions are parsed. Signed-off-by: Manuel Pégourié-Gonnard --- tests/scripts/all.sh | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index db8d6373ac..35fc1be1d0 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -108,13 +108,16 @@ #### Initialization and command line parsing ################################################################ -# Abort on errors (even on the left-hand side of a pipe). -# Treat uninitialised variables as errors. -set -e -o pipefail -u - -# Enable ksh/bash extended file matching patterns +# Enable ksh/bash extended file matching patterns. +# Must come before function definitions or some of them wouldn't parse. shopt -s extglob +pre_set_shell_options () { + # Abort on errors (even on the left-hand side of a pipe). + # Treat uninitialised variables as errors. + set -e -o pipefail -u +} + # For project detection in_mbedtls_repo () { test "$PROJECT_NAME" = "Mbed TLS" @@ -1099,11 +1102,14 @@ helper_get_psa_key_type_list() { echo "$loc_list" } -# Include the components from components.sh -test_script_dir="${0%/*}" -for file in "$test_script_dir"/components*.sh; do - source $file -done +# Must be called before pre_initialize_variables which sets ALL_COMPONENTS. +pre_load_components () { + # Include the components from components.sh + test_script_dir="${0%/*}" + for file in "$test_script_dir"/components*.sh; do + source $file + done +} ################################################################ @@ -1200,8 +1206,15 @@ run_component () { unset current_component } +################################################################ +#### Main (only function definitions above) +################################################################ + + # Preliminary setup +pre_set_shell_options pre_check_environment +pre_load_components pre_initialize_variables pre_parse_command_line "$@"