2020-08-02 18:58:08 -04:00
|
|
|
# Include guard to prevent running hooks more than once
|
|
|
|
if [ -n "${_catkin_setup_hook_loaded:-}" ]; then return; fi
|
|
|
|
_catkin_setup_hook_loaded=1
|
|
|
|
|
2019-04-07 15:55:30 -04:00
|
|
|
# Load catkin environment hooks. This mimics the behavior of _setup_util.py.
|
2019-04-06 22:17:28 -04:00
|
|
|
|
2019-04-07 15:55:30 -04:00
|
|
|
declare -gA _catkinPackagesSeen
|
|
|
|
declare -gA _catkinGenericEnvHooks
|
|
|
|
declare -gA _catkinSpecificEnvHooks
|
|
|
|
|
|
|
|
_findCatkinEnvHooks() {
|
2019-04-06 22:17:28 -04:00
|
|
|
local pkg="$1"
|
2019-04-07 15:55:30 -04:00
|
|
|
local pkgEnvHookDir="$pkg/etc/catkin/profile.d"
|
|
|
|
# Deduplicate the packages
|
2022-10-08 22:37:47 -04:00
|
|
|
if [ -z "${_catkinPackagesSeen["$pkg"]:-}" ] && [ -d "$pkgEnvHookDir" ]; then
|
2019-04-07 15:55:30 -04:00
|
|
|
while IFS= read -rd '' hook; do
|
2019-04-07 20:53:35 -04:00
|
|
|
case "$hook" in
|
2020-08-02 18:58:08 -04:00
|
|
|
*.sh) _catkinGenericEnvHooks["$(basename "$hook")"]="$hook" ;;
|
|
|
|
*) _catkinSpecificEnvHooks["$(basename "$hook")"]="$hook" ;;
|
2019-04-07 20:53:35 -04:00
|
|
|
esac
|
|
|
|
done < <(find "$pkgEnvHookDir" \( -name "*.sh" -o -name "*.$CATKIN_SHELL" \) -print0)
|
2019-03-21 00:23:14 -04:00
|
|
|
fi
|
2019-04-07 15:55:30 -04:00
|
|
|
_catkinPackagesSeen["$pkg"]=1
|
|
|
|
}
|
2022-09-21 19:35:47 -04:00
|
|
|
addEnvHooks "$targetOffset" _findCatkinEnvHooks
|
2019-04-07 15:55:30 -04:00
|
|
|
|
|
|
|
_runCatkinEnvHook() {
|
|
|
|
[ -n "$1" ] || return 0
|
|
|
|
# Causes hooks to look in the wrong place
|
|
|
|
unset CATKIN_ENV_HOOK_WORKSPACE
|
2019-12-01 22:48:23 -05:00
|
|
|
# Some hooks assume set +u
|
|
|
|
set +u
|
2019-04-07 15:55:30 -04:00
|
|
|
# Some hooks fail in stripped down bash during builds
|
|
|
|
source "$1" || true
|
2019-12-01 22:48:23 -05:00
|
|
|
set -u
|
2019-04-07 15:55:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_runCatkinEnvHooksArray() {
|
|
|
|
# Run hooks in sorted order of their file names
|
|
|
|
# This would fail if a filename contained EOT
|
2021-10-12 09:28:32 -04:00
|
|
|
|
|
|
|
# Work around https://github.com/NixOS/nix/issues/5262
|
2021-09-27 17:06:06 -04:00
|
|
|
local eot=$(printf '\004')
|
2019-04-07 15:55:30 -04:00
|
|
|
while IFS= read -rd '' hook; do
|
|
|
|
_runCatkinEnvHook "$hook"
|
|
|
|
done < <(printf "%s\0" "$@" | \
|
|
|
|
# Replace final / with EOT, separating the file name
|
2021-09-27 17:06:06 -04:00
|
|
|
sed -z 's|\(.*\)/|\1'${eot}'|' | \
|
2019-04-07 15:55:30 -04:00
|
|
|
# Sort on second EOT separated field (file name)
|
2021-09-27 17:06:06 -04:00
|
|
|
LC_ALL=C sort -zt${eot} -k2 | \
|
2019-04-07 15:55:30 -04:00
|
|
|
# Substitute / back in for EOT
|
2021-09-27 17:06:06 -04:00
|
|
|
sed -z 's|'${eot}'|/|')
|
2019-04-07 15:55:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_runCatkinEnvHooks() {
|
|
|
|
_runCatkinEnvHooksArray "${_catkinGenericEnvHooks[@]}"
|
|
|
|
_runCatkinEnvHooksArray "${_catkinSpecificEnvHooks[@]}"
|
2019-03-21 00:23:14 -04:00
|
|
|
}
|
2019-04-07 15:55:30 -04:00
|
|
|
postHooks+=(_runCatkinEnvHooks)
|
2019-03-21 00:23:14 -04:00
|
|
|
|
2019-04-06 01:46:54 -04:00
|
|
|
_catkinPostPatchHook() {
|
2019-04-07 15:55:30 -04:00
|
|
|
while IFS= read -rd '' cfg; do
|
2019-04-06 22:17:28 -04:00
|
|
|
patchShebangs "$cfg"
|
2019-04-07 15:55:30 -04:00
|
|
|
done < <(find . -name '*.cfg' -executable -print0)
|
2019-04-06 01:46:54 -04:00
|
|
|
}
|
|
|
|
postPatchHooks+=(_catkinPostPatchHook)
|
|
|
|
|
2019-03-21 00:23:14 -04:00
|
|
|
_catkinPreConfigureHook() {
|
2019-04-06 01:46:54 -04:00
|
|
|
cmakeFlags+=" -DCATKIN_ENABLE_TESTING=${doCheck:-OFF}"
|
2020-07-30 21:13:39 -04:00
|
|
|
# Don't try to detect Debian/Ubuntu when sandbox is disabled
|
|
|
|
cmakeFlags+=" -DSETUPTOOLS_DEB_LAYOUT=OFF"
|
2022-10-08 22:37:47 -04:00
|
|
|
# Don't install setup scripts or .catkin workspace marker. Unfortunately,
|
|
|
|
# we still need the marker for the environment hooks, so it is created
|
|
|
|
# manually.
|
|
|
|
cmakeFlags+=" -DCATKIN_BUILD_BINARY_PACKAGE=ON"
|
2019-03-21 00:23:14 -04:00
|
|
|
}
|
|
|
|
preConfigureHooks+=(_catkinPreConfigureHook)
|
|
|
|
|
2022-10-08 22:37:47 -04:00
|
|
|
_catkinMarkerHook() {
|
|
|
|
# The ROS_PACKAGE_PATH hook needs the .catkin marker
|
|
|
|
touch "$out/.catkin"
|
2019-04-06 01:46:54 -04:00
|
|
|
}
|
2022-10-08 22:37:47 -04:00
|
|
|
postInstallHooks+=(_catkinMarkerHook)
|
2019-04-06 01:46:54 -04:00
|
|
|
|
2020-08-02 18:58:08 -04:00
|
|
|
_catkinWrapperHook() {
|
|
|
|
wrapPythonPrograms
|
|
|
|
}
|
|
|
|
postFixupHooks+=(_catkinWrapperHook)
|
|
|
|
|
2019-04-06 22:17:28 -04:00
|
|
|
export CATKIN_SHELL=bash
|