@@ -115,6 +115,24 @@ common::await_startup() {
115115 return 1
116116}
117117
118+ common::_abs_path_if_exists () {
119+ local base=" $1 "
120+ local path=" $2 "
121+ if [[ -z " $path " ]]; then
122+ return 1
123+ fi
124+ if [[ " $path " != /* ]]; then
125+ path=" $base /$path "
126+ fi
127+ if [[ -f " $path " ]]; then
128+ local dir
129+ dir=$( cd " $( dirname " $path " ) " && pwd -P)
130+ printf ' %s\n' " $dir /$( basename " $path " ) "
131+ return 0
132+ fi
133+ return 1
134+ }
135+
118136# Discover compiled extension path, preferring debug builds.
119137# Honors LIB_PATH if already set in the environment.
120138common::resolve_extension () {
@@ -137,36 +155,27 @@ common::resolve_extension() {
137155
138156 # Honour overridden build output directory first.
139157 if [[ -n " ${CARGO_TARGET_DIR:- } " ]]; then
140- debug_candidate=" ${CARGO_TARGET_DIR%/ } /debug/librabbit_rs.${ext} "
141- release_candidate=" ${CARGO_TARGET_DIR%/ } /release/librabbit_rs.${ext} "
142- if [[ -f " $debug_candidate " ]]; then
143- echo " $debug_candidate "
144- return 0
145- fi
146- if [[ -f " $release_candidate " ]]; then
147- echo " $release_candidate "
148- return 0
158+ local cargo_dir=" ${CARGO_TARGET_DIR%/ } "
159+ if [[ " $cargo_dir " != /* ]]; then
160+ cargo_dir=" $root /$cargo_dir "
149161 fi
162+ debug_candidate=" $cargo_dir /debug/librabbit_rs.${ext} "
163+ release_candidate=" $cargo_dir /release/librabbit_rs.${ext} "
164+ if common::_abs_path_if_exists " $root " " $debug_candidate " ; then return 0; fi
165+ if common::_abs_path_if_exists " $root " " $release_candidate " ; then return 0; fi
150166 fi
151167
152168 debug_candidate=" $root /target/debug/librabbit_rs.${ext} "
153169 release_candidate=" $root /target/release/librabbit_rs.${ext} "
154170
155- if [[ -f " $debug_candidate " ]]; then
156- echo " $debug_candidate "
157- return 0
158- fi
159- if [[ -f " $release_candidate " ]]; then
160- echo " $release_candidate "
161- return 0
162- fi
171+ if common::_abs_path_if_exists " $root " " $debug_candidate " ; then return 0; fi
172+ if common::_abs_path_if_exists " $root " " $release_candidate " ; then return 0; fi
163173
164174 # Look for CI build artefacts (target/ci/<job>/release).
165175 local ci_root=" $root /target/ci"
166176 if [[ -d " $ci_root " ]]; then
167177 while IFS= read -r -d ' ' candidate; do
168- if [[ -f " $candidate " ]]; then
169- echo " $candidate "
178+ if common::_abs_path_if_exists " $root " " $candidate " ; then
170179 return 0
171180 fi
172181 done < <( find " $ci_root " -maxdepth 3 -type f -name " librabbit_rs.${ext} " -print0)
0 commit comments