Skip to content

Commit

Permalink
Add heuristic to run python devel space relays
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
  • Loading branch information
sloretz committed Jan 24, 2020
1 parent 6773140 commit 35c874f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tools/rosbash/scripts/rosrun
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ esac
pkg_name="$1"
file_name="$2"

function inonedir() {
exe=$1
shift
list_of_dirs=("$@")
for location in "${list_of_dirs[@]}";
do
if [[ "$exe" = "$location"* ]] ; then
# exe path starts with $location
echo "yes"
return
fi
done
echo "no"
}

if [[ -n $CMAKE_PREFIX_PATH ]]; then
_rosrun_IFS="$IFS"
IFS=$'\n'
Expand Down Expand Up @@ -91,8 +106,29 @@ if [[ ! $file_name == */* ]]; then
done
fi
exit 3
elif [[ ${#exepathlist[@]} -eq 2 ]]; then
# If one executable is from share and another from libexec then use one from libexec.
# This assumes the one from libexec is a devel-space python relay script created by catkin.

# Share dirs includes devel, install, or src space locations
catkin_package_share_dirs=($(catkin_find --without-underlays --share "$pkg_name" 2> /dev/null))
debug "Looking in catkin share dirs: $IFS$(catkin_find --without-underlays --share "$pkg_name" 2>&1)"

first_libexec=$(inonedir "${exepathlist[0]}" "${catkin_package_libexec_dirs[@]}")
first_share=$(inonedir "${exepathlist[0]}" "${catkin_package_share_dirs[@]}")
second_libexec=$(inonedir "${exepathlist[1]}" "${catkin_package_libexec_dirs[@]}")
second_share=$(inonedir "${exepathlist[1]}" "${catkin_package_share_dirs[@]}")

if [[ $first_libexec == "yes" && $first_share == "no" && $second_share == "yes" ]]; then
debug "Assuming ${exepathlist[0]} is a devel-space relay for ${exepathlist[1]}"
exepathlist=(${exepathlist[0]})
elif [[ $second_libexec == "yes" && $second_share == "no" && $first_share == "yes" ]]; then
debug "Assuming ${exepathlist[1]} is a devel-space relay for ${exepathlist[0]}"
exepathlist=(${exepathlist[1]})
fi
fi

elif [[ ${#exepathlist[@]} -gt 1 ]]; then
if [[ ${#exepathlist[@]} -gt 1 ]]; then
echo "[rosrun] You have chosen a non-unique executable, please pick one of the following:"
select opt in "${exepathlist[@]}"; do
exepath="$opt"
Expand Down

0 comments on commit 35c874f

Please sign in to comment.