Skip to content

Commit 6d70288

Browse files
zhmiaoCopilot
andcommitted
fix: validate explicit ORT_DIR override
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d63650c commit 6d70288

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

sparrow-engine/scripts/ort-env.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,31 @@ pick_newest_ort_dir() {
8585
sort -V -r | head -1 | awk '{print $2}'
8686
}
8787

88+
ort_dir_has_runtime_lib() {
89+
local dir="$1"
90+
local versioned
91+
if [[ -f "$dir/libonnxruntime.so" ]]; then
92+
return 0
93+
fi
94+
versioned=$(find "$dir" -maxdepth 1 -name 'libonnxruntime.so.*.*.*' -type f -print -quit 2>/dev/null)
95+
[[ -n "$versioned" ]]
96+
}
97+
8898
find_ort_dir() {
8999
# Check explicit override first.
90100
if [[ -n "${ORT_DIR:-}" ]]; then
101+
if [[ ! -d "$ORT_DIR" ]]; then
102+
echo >&2 "error: ORT_DIR is not a directory: $ORT_DIR"
103+
echo >&2 "Check ORT_DIR points to an onnxruntime/capi directory."
104+
echo >&2 "Unset ORT_DIR to fall back to auto-discovery."
105+
return 1
106+
fi
107+
if ! ort_dir_has_runtime_lib "$ORT_DIR"; then
108+
echo >&2 "error: ORT_DIR does not contain libonnxruntime.so: $ORT_DIR"
109+
echo >&2 "Check ORT_DIR points to an onnxruntime/capi directory."
110+
echo >&2 "Unset ORT_DIR to fall back to auto-discovery."
111+
return 1
112+
fi
91113
echo "$ORT_DIR"
92114
return
93115
fi

0 commit comments

Comments
 (0)