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 authored and dirk-thomas committed Feb 11, 2020
1 parent ee5469f commit f491a91
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 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,27 @@ 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_share=$(inonedir "${exepathlist[0]}" "${catkin_package_share_dirs[@]}")
second_share=$(inonedir "${exepathlist[1]}" "${catkin_package_share_dirs[@]}")

if [[ $first_share == "no" && $second_share == "yes" ]]; then
debug "Assuming ${exepathlist[0]} is a devel-space relay for ${exepathlist[1]}"
exepathlist=(${exepathlist[0]})
elif [[ $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 f491a91

Please sign in to comment.