From 7c2646ee5d8bde384e1ec4a927b15c3a844f6071 Mon Sep 17 00:00:00 2001 From: Nathan Brooks Date: Thu, 9 Jul 2026 13:24:58 -0600 Subject: [PATCH] resolute: complete ament_index_cpp::get_package_share migration on Rolling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ament_index_cpp evolved its API in two steps, and the RCLCPP_VERSION_GTE(30, 0, 0) guards added in #3703 hit the wrong branch on Rolling-on-Noble (where the header still exists but the 1-arg form is now deprecated) and outright fail to compile on Rolling-on-Resolute (where the header no longer exists at all). Guard on ament_index_cpp's own version macro — three tiers: 1.14+ (Rolling on Resolute) replaced the old header, exposing get_package_share_path(pkg) which returns std::filesystem::path directly. 1.5+ (Jazzy 1.8.4, Kilted 1.11.4, Lyrical 1.13.3, Rolling-on-Noble 1.13.1) Old header still present; use the 2-arg out-param overload get_package_share_directory(pkg, path) which is non-deprecated (matters for the -Werror=deprecated-declarations job on Rolling-on-Noble where the 1-arg form is deprecated). older (Humble 1.4.1) Only the 1-arg get_package_share_directory(pkg) returning std::string is available; wrap in std::filesystem::path(). Guarding on ament_index_cpp's own version (rather than rclcpp's) is important because the two packages release independently — the API change lives in ament_index_cpp, and using RCLCPP_VERSION as a proxy misfires when Rolling's rclcpp advances without a corresponding ament_index_cpp bump (as happened in #3703 → this fix). Drops the now-unused `#include ` in each file (added by #3703 for the guard we replaced). Verified with a full source-build of moveit2 + downstream against `ubuntu:resolute` + ROS Rolling (`ros2-testing` apt). Co-Authored-By: Claude Opus 4.7 --- .../utils/src/robot_model_test_utils.cpp | 52 +++++++++++++------ .../planning/rdf_loader/src/rdf_loader.cpp | 26 ++++++++-- .../moveit_setup_framework/utilities.hpp | 26 ++++++++-- 3 files changed, 80 insertions(+), 24 deletions(-) diff --git a/moveit_core/utils/src/robot_model_test_utils.cpp b/moveit_core/utils/src/robot_model_test_utils.cpp index b858a3d23a..2549355931 100644 --- a/moveit_core/utils/src/robot_model_test_utils.cpp +++ b/moveit_core/utils/src/robot_model_test_utils.cpp @@ -34,9 +34,26 @@ /* Author: Bryce Willey */ -#include - +// ament_index_cpp's get_package_share_directory API changed twice. +// Guard on ament_index_cpp's own version — not rclcpp — because the +// changes live in ament_index_cpp and its release cadence is independent +// of rclcpp's. +// 1.14+ (Rolling on Resolute): +// get_package_share_directory.hpp REMOVED, replaced with +// get_package_share_path.hpp exposing get_package_share_path(pkg) +// returning std::filesystem::path directly. +// 1.5+ (Jazzy 1.8.4, Kilted 1.11.4, Lyrical 1.13.3, Rolling-on-Noble 1.13.1): +// 2-arg out-param overload get_package_share_directory(pkg, path) +// available; the 1-arg form is deprecated starting in 1.13. +// Older (Humble 1.4.1): +// only the non-deprecated 1-arg get_package_share_directory(pkg) +// returning std::string is available. +#include +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) +#include +#else #include +#endif #include #include #include @@ -66,14 +83,14 @@ moveit::core::RobotModelPtr loadTestingRobotModel(const std::string& package_nam const std::string& urdf_relative_path, const std::string& srdf_relative_path) { -// For Rolling, L-turtle, and newer -#if RCLCPP_VERSION_GTE(30, 0, 0) - std::filesystem::path urdf_path; - ament_index_cpp::get_package_share_directory(package_name, urdf_path); - urdf_path /= urdf_relative_path; - std::filesystem::path srdf_path; - ament_index_cpp::get_package_share_directory(package_name, srdf_path); - srdf_path /= srdf_relative_path; +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) + const auto urdf_path = ament_index_cpp::get_package_share_path(package_name) / urdf_relative_path; + const auto srdf_path = ament_index_cpp::get_package_share_path(package_name) / srdf_relative_path; +#elif AMENT_INDEX_CPP_VERSION_GTE(1, 5, 0) + std::filesystem::path pkg_share; + ament_index_cpp::get_package_share_directory(package_name, pkg_share); + const auto urdf_path = pkg_share / urdf_relative_path; + const auto srdf_path = pkg_share / srdf_relative_path; #else const auto urdf_path = std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name)) / urdf_relative_path; @@ -107,8 +124,9 @@ moveit::core::RobotModelPtr loadTestingRobotModel(const std::string& robot_name) urdf::ModelInterfaceSharedPtr loadModelInterface(const std::string& robot_name) { const std::string package_name = "moveit_resources_" + robot_name + "_description"; -// For Rolling, L-turtle, and newer -#if RCLCPP_VERSION_GTE(30, 0, 0) +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) + std::filesystem::path res_path = ament_index_cpp::get_package_share_path(package_name); +#elif AMENT_INDEX_CPP_VERSION_GTE(1, 5, 0) std::filesystem::path res_path; ament_index_cpp::get_package_share_directory(package_name, res_path); #else @@ -141,8 +159,9 @@ srdf::ModelSharedPtr loadSRDFModel(const std::string& robot_name) if (robot_name == "pr2") { const std::string package_name = "moveit_resources_" + robot_name + "_description"; -// For Rolling, L-turtle, and newer -#if RCLCPP_VERSION_GTE(30, 0, 0) +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) + std::filesystem::path res_path = ament_index_cpp::get_package_share_path(package_name); +#elif AMENT_INDEX_CPP_VERSION_GTE(1, 5, 0) std::filesystem::path res_path; ament_index_cpp::get_package_share_directory(package_name, res_path); #else @@ -153,8 +172,9 @@ srdf::ModelSharedPtr loadSRDFModel(const std::string& robot_name) else { const std::string package_name = "moveit_resources_" + robot_name + "_moveit_config"; -// For Rolling, L-turtle, and newer -#if RCLCPP_VERSION_GTE(30, 0, 0) +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) + std::filesystem::path res_path = ament_index_cpp::get_package_share_path(package_name); +#elif AMENT_INDEX_CPP_VERSION_GTE(1, 5, 0) std::filesystem::path res_path; ament_index_cpp::get_package_share_directory(package_name, res_path); #else diff --git a/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp b/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp index db0957e96f..45d6daf28d 100644 --- a/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp +++ b/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp @@ -34,13 +34,30 @@ /* Author: Ioan Sucan, Mathias Lüdtke, Dave Coleman */ -#include - // MoveIt #include #include #include +// ament_index_cpp's get_package_share_directory API changed twice. +// Guard on ament_index_cpp's own version — not rclcpp — because the +// changes live in ament_index_cpp and its release cadence is independent +// of rclcpp's. +// 1.14+ (Rolling on Resolute): +// get_package_share_directory.hpp REMOVED, replaced with +// get_package_share_path.hpp exposing get_package_share_path(pkg) +// returning std::filesystem::path directly. +// 1.5+ (Jazzy 1.8.4, Kilted 1.11.4, Lyrical 1.13.3, Rolling-on-Noble 1.13.1): +// 2-arg out-param overload get_package_share_directory(pkg, path) +// available; the 1-arg form is deprecated starting in 1.13. +// Older (Humble 1.4.1): +// only the non-deprecated 1-arg get_package_share_directory(pkg) +// returning std::string is available. +#include +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) +#include +#else #include +#endif #include #include @@ -222,8 +239,9 @@ bool RDFLoader::loadPkgFileToString(std::string& buffer, const std::string& pack std::filesystem::path path; try { -// For Rolling, L-turtle, and newer -#if RCLCPP_VERSION_GTE(30, 0, 0) +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) + path = ament_index_cpp::get_package_share_path(package_name); +#elif AMENT_INDEX_CPP_VERSION_GTE(1, 5, 0) ament_index_cpp::get_package_share_directory(package_name, path); #else path = ament_index_cpp::get_package_share_directory(package_name); diff --git a/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp b/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp index 6cc6967965..f0bedfd969 100644 --- a/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp +++ b/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp @@ -36,10 +36,27 @@ #pragma once -#include - #include +// ament_index_cpp's get_package_share_directory API changed twice. +// Guard on ament_index_cpp's own version — not rclcpp — because the +// changes live in ament_index_cpp and its release cadence is independent +// of rclcpp's. +// 1.14+ (Rolling on Resolute): +// get_package_share_directory.hpp REMOVED, replaced with +// get_package_share_path.hpp exposing get_package_share_path(pkg) +// returning std::filesystem::path directly. +// 1.5+ (Jazzy 1.8.4, Kilted 1.11.4, Lyrical 1.13.3, Rolling-on-Noble 1.13.1): +// 2-arg out-param overload get_package_share_directory(pkg, path) +// available; the 1-arg form is deprecated starting in 1.13. +// Older (Humble 1.4.1): +// only the non-deprecated 1-arg get_package_share_directory(pkg) +// returning std::string is available. +#include +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) +#include +#else #include +#endif #include #include #include @@ -54,8 +71,9 @@ inline std::filesystem::path getSharePath(const std::string& package_name) { try { -// For Rolling, L-turtle, and newer -#if RCLCPP_VERSION_GTE(30, 0, 0) +#if AMENT_INDEX_CPP_VERSION_GTE(1, 14, 0) + return ament_index_cpp::get_package_share_path(package_name); +#elif AMENT_INDEX_CPP_VERSION_GTE(1, 5, 0) std::filesystem::path path; ament_index_cpp::get_package_share_directory(package_name, path); return path;