77[ -n " $__INIT_ENV_LOADED " ] && return
88__INIT_ENV_LOADED=1
99
10- # (Optional) Remove/comment log line below to keep CI logs clean:
11- # echo "[INFO] init_env loaded."
12-
13- # --- Robust root detection ---
10+ # --- Robust root detection for host-tools ---
1411if [ -z " $ROOT_DIR " ]; then
15- # Fast path: current working directory is root
16- if [ -d " ./utils" ] && [ -d " ./suites" ]; then
17- ROOT_DIR=" $( pwd) "
18- # Check if we're in host-tools and Runner exists as sibling
19- elif [ -d " ../Runner/utils" ] && [ -d " ../Runner/suites" ]; then
20- ROOT_DIR=" $( cd ../Runner && pwd) "
12+ # When sourced, we need to find the directory containing this init_env file
13+ # Try multiple methods to get the script location
14+ if [ -n " ${BASH_SOURCE:- } " ]; then
15+ # Bash
16+ _script_dir=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
17+ elif [ -n " ${ZSH_VERSION:- } " ]; then
18+ # Zsh
19+ _script_dir=" $( cd " $( dirname " ${(% ):-% x} " ) " && pwd) "
20+ else
21+ # POSIX fallback: assume init_env is in a known location relative to caller
22+ # The caller (run.sh) sets INIT_ENV variable before sourcing
23+ if [ -n " ${INIT_ENV:- } " ]; then
24+ _script_dir=" $( cd " $( dirname " $INIT_ENV " ) " && pwd) "
25+ else
26+ _script_dir=" $( cd " $( dirname " $0 " ) " && pwd) "
27+ fi
28+ fi
29+
30+ # For host-tools, ROOT_DIR is the host-tools directory itself
31+ if [ -d " $_script_dir /utils" ] && [ -f " $_script_dir /utils/functestlib.sh" ]; then
32+ ROOT_DIR=" $_script_dir "
2133 else
22- # Fallback: walk up from this script's location
23- _script_dir=" $( cd " $( dirname " $0 " ) " && pwd) "
24- _search=" $_script_dir "
25- while [ " $_search " != " /" ]; do
26- if [ -d " $_search /utils" ] && [ -d " $_search /suites" ]; then
27- ROOT_DIR=" $_search "
28- break
29- fi
30- # Also check for Runner subdirectory
31- if [ -d " $_search /Runner/utils" ] && [ -d " $_search /Runner/suites" ]; then
32- ROOT_DIR=" $_search /Runner"
33- break
34- fi
35- _search=$( dirname " $_search " )
36- done
34+ echo " [ERROR] Could not detect host-tools root (missing utils/ or functestlib.sh)" >&2
35+ echo " [DEBUG] Tried _script_dir=$_script_dir " >&2
36+ exit 1
3737 fi
3838fi
3939
4040# --- Validate and export key environment paths ---
4141if [ -z " ${ROOT_DIR:- } " ] || [ ! -d " $ROOT_DIR /utils" ] || [ ! -f " $ROOT_DIR /utils/functestlib.sh" ]; then
42- echo " [ERROR] Could not detect testkit root (missing utils/ or functestlib.sh)" >&2
42+ echo " [ERROR] Could not detect host-tools root (missing utils/ or functestlib.sh)" >&2
4343 exit 1
4444fi
4545
4646export ROOT_DIR
4747export TOOLS=" $ROOT_DIR /utils"
48- export __RUNNER_SUITES_DIR=" $ROOT_DIR /suites "
48+ export __RUNNER_SUITES_DIR=" $ROOT_DIR "
4949export __RUNNER_UTILS_BIN_DIR=" $ROOT_DIR /common"
5050
5151# --- Ensure TOOLS is usable in all shells ---
@@ -58,7 +58,6 @@ case ":$PATH:" in
5858esac
5959
6060# --- Source functestlib.sh to make functions available ---
61- # Note: functestlib.sh must be sourced for run-test.sh to work properly
6261if [ -f " $TOOLS /functestlib.sh" ]; then
6362 # shellcheck disable=SC1090,SC1091
6463 . " $TOOLS /functestlib.sh"
0 commit comments