From a57ccb07e9caaab9c02615eae4f620ba057dd1f0 Mon Sep 17 00:00:00 2001 From: monkescripts Date: Sun, 16 Aug 2026 11:47:34 +0800 Subject: [PATCH] Emit a .dsv env hook so the plugin path resolves under colcon The hook was a .sh-only file that hardcoded the configure-time install prefix. It worked, but baked an absolute path into the installed hook, so the install tree could not be relocated. Switch to the ament-native form and declare AMENT_CMAKE_ENVIRONMENT_HOOKS_DESC_gz_led_plugin so ament_environment_hooks also emits gz_led_plugin.dsv. colcon's setup chain prefers the .dsv when one exists and only falls back to sourcing the .sh otherwise -- and that fallback exports COLCON_CURRENT_PREFIX, never AMENT_CURRENT_PREFIX, which is why a .sh-only hook using ament_prepend_unique_value would silently prepend whichever prefix was sourced last (e.g. /opt/ros/humble/lib). The descriptor's path is relative, so colcon resolves it against the package prefix and the install tree stays relocatable. --- CMakeLists.txt | 5 +++-- env_hooks/gz_led_plugin.sh.in | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31903aa..3059876 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,7 @@ project(gz_led_plugin) # Vendored from https://github.com/jasmeet0915/gz_sim_led_plugin with a local # patch (see src/LedPlugin.cpp) so identical model instances don't collide on -# scoped visual/light names. Built for Gazebo Harmonic (gz-sim8), matching the -# versions the existing dave_gz_world_plugins package uses in this workspace. +# scoped visual/light names. Built for Gazebo Harmonic (gz-sim8) find_package(ament_cmake REQUIRED) find_package(gz-cmake3 REQUIRED) @@ -42,6 +41,8 @@ install( ) # Put libgz_led_plugin.so on GZ_SIM_SYSTEM_PLUGIN_PATH when the workspace is sourced. +set(AMENT_CMAKE_ENVIRONMENT_HOOKS_DESC_gz_led_plugin + "prepend-non-duplicate;GZ_SIM_SYSTEM_PLUGIN_PATH;lib") ament_environment_hooks("${CMAKE_CURRENT_SOURCE_DIR}/env_hooks/gz_led_plugin.sh.in") ament_package() diff --git a/env_hooks/gz_led_plugin.sh.in b/env_hooks/gz_led_plugin.sh.in index 5109142..fc4d7d5 100644 --- a/env_hooks/gz_led_plugin.sh.in +++ b/env_hooks/gz_led_plugin.sh.in @@ -1 +1 @@ -export GZ_SIM_SYSTEM_PLUGIN_PATH="@CMAKE_INSTALL_PREFIX@/lib:${GZ_SIM_SYSTEM_PLUGIN_PATH}" +ament_prepend_unique_value GZ_SIM_SYSTEM_PLUGIN_PATH "$AMENT_CURRENT_PREFIX/lib"