Skip to content

Extend API to use std::filesystem#104

Merged
ahcorde merged 5 commits intorollingfrom
ahcorde/rolling/path_api
Dec 23, 2025
Merged

Extend API to use std::filesystem#104
ahcorde merged 5 commits intorollingfrom
ahcorde/rolling/path_api

Conversation

@ahcorde
Copy link
Copy Markdown
Contributor

@ahcorde ahcorde commented Nov 13, 2025

Related with this issue #92

@Ryanf55 FYI

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@Ryanf55
Copy link
Copy Markdown

Ryanf55 commented Nov 13, 2025

Nice to see this, will review soon!

Comment on lines 57 to 58
auto resource_path = path + "/share/ament_index/resource_index/" +
resource_type + "/" + resource_name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto resource_path = path + "/share/ament_index/resource_index/" +
resource_type + "/" + resource_name;
auto resource_path = path / "share" / "ament_index" / "resource_index" /
resource_type / resource_name;

Would it be time to also do changes like this?

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde ahcorde requested a review from Ryanf55 November 25, 2025 15:03
@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented Nov 25, 2025

There is still one function which required deprecation which is get_packages_with_prefixes. @Ryanf55 Do you have any idea about how we can rename this one ?

@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented Dec 8, 2025

@ros-pull-request-builder retest this please

@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented Dec 8, 2025

do you mind to take a look ? @mjcarroll @asymingt

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented Dec 18, 2025

Pulls: ros/pluginlib#289, #104, ros/resource_retriever#118, ros/ros_tutorials#190, ros-perception/image_common#388, ros2/rclcpp#3011, ros2/rmw_implementation#272, ros2/rmw_zenoh#879, ros2/rosbag2#2268, ros2/rviz#1647
Gist: https://gist.githubusercontent.com/ahcorde/39681e4e2c4ae7c2079f7fbd2e07884f/raw/105720d4ff8bdf2a21aee9708bf35531a754a3b3/ros2.repos
BUILD args: --packages-above-and-dependencies ament_index_cpp
TEST args: --packages-above ament_index_cpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17828

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

* \throws std::runtime_error if resource_type or resource_name are empty.
*/
AMENT_INDEX_CPP_PUBLIC
std::pair<std::optional<std::filesystem::path>, std::string>
Copy link
Copy Markdown

@jmachowinski jmachowinski Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not the biggest fan of std::pair as return type.
A small struct like

Suggested change
std::pair<std::optional<std::filesystem::path>, std::string>
struct PathWithResource
{
std::optional<std::filesystem::path> resourcePath;
// ?
std::string contents;
}

is nicer and makes the code using the return type way more understandable.

Also from the documentation I can't figure out what contents is / should contain.

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Copy Markdown
Contributor Author

ahcorde commented Dec 19, 2025

Pulls: ros/pluginlib#289, #104, ros/resource_retriever#118, ros/ros_tutorials#190, ros-perception/image_common#388, ros2/rclcpp#3011, ros2/rmw_implementation#272, ros2/rmw_zenoh#879, ros2/rosbag2#2268, ros2/rviz#1647
Gist: https://gist.githubusercontent.com/ahcorde/e52f66b6b23f6f749ced640a964517d1/raw/105720d4ff8bdf2a21aee9708bf35531a754a3b3/ros2.repos
BUILD args: --packages-above-and-dependencies ament_index_cpp
TEST args: --packages-above ament_index_cpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/17831

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
@peci1
Copy link
Copy Markdown

peci1 commented Jan 26, 2026

Would you consider backporting this (without the deprecations) to Jazzy and Kilted? It seems to me most of the changes are just adding new free functions, so it should be API and ABI compatible.

@jmachowinski
Copy link
Copy Markdown

@peci1 I don't see a reason against it, feel free to open a PR

@peci1
Copy link
Copy Markdown

peci1 commented Jan 26, 2026

I thought mergifio could do it, but I can't task it =)

@jmachowinski
Copy link
Copy Markdown

jmachowinski commented Jan 26, 2026

Mergify won't filter out the deprecation, therefore it needs to be a manual backport

@peci1
Copy link
Copy Markdown

peci1 commented Jan 26, 2026

Okay, I'll have a look ;)

@Ryanf55
Copy link
Copy Markdown

Ryanf55 commented Jan 26, 2026

Mergify won't filter out the deprecation, therefore it needs to be a manual backport

You can use mergify to start and then edit the code before merge.

peci1 pushed a commit to peci1/ament_index that referenced this pull request Jan 27, 2026
Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
peci1 pushed a commit to peci1/ament_index that referenced this pull request Jan 27, 2026
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@peci1
Copy link
Copy Markdown

peci1 commented Jan 27, 2026

Okay, I went with Jazzy manually: #109 . I'll do Kilted once Jazzy is merged.

ahcorde added a commit that referenced this pull request Feb 2, 2026
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
mergify bot pushed a commit that referenced this pull request Feb 2, 2026
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
(cherry picked from commit 1bba98c)
mergify bot pushed a commit that referenced this pull request Feb 2, 2026
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
(cherry picked from commit 1bba98c)
ahcorde added a commit that referenced this pull request Feb 3, 2026
(cherry picked from commit 1bba98c)

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Signed-off-by: Martin Pecka <peckama2@fel.cvut.cz>
Co-authored-by: Martin Pecka <peci1@seznam.cz>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
*/
AMENT_INDEX_CPP_PUBLIC
void
get_package_prefix(const std::string & package_name, std::filesystem::path & path);
Copy link
Copy Markdown
Contributor

@Timple Timple Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the result an argument and not an output of the function?

Now my code is more verbose because I need to construct an empty path first to pass it to this function.

This:

  auto dbc = ament_index_cpp::get_package_share_directory("can_dbc_pkg") + "/test/motohawk.dbc";

Becomes this:

  std::filesystem::path package_path;
  ament_index_cpp::get_package_share_directory("can_dbc_pkg", package_path);
  auto dbc = package_path / "test" / "motohawk.dbc";

To keep ABI perhaps we could have also just created a different function name? How about get_package_share_path:

  auto dbc = ament_index_cpp::get_package_share_path("can_dbc_pkg") / "test" / "motohawk.dbc";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was because you can't have two functions with the same args and different result type. So there was need to distinguish the new API somehow else.

But I agree the solution with renaming the function is much friendlier.

Tiryoh added a commit to Tiryoh/rosbag2 that referenced this pull request Feb 20, 2026
Migrate to non-deprecated ament_index_cpp APIs introduced in
ament/ament_index#104 to fix -Werror=deprecated-declarations errors.

Signed-off-by: Daisuke Sato <tiryoh@gmail.com>
nbbrooks added a commit to stephanie-eng/moveit2 that referenced this pull request Mar 16, 2026
Temporarily disable deprecation warning-as-error for QT and ament_target_dependencies deprecation warnings
nbbrooks added a commit to stephanie-eng/moveit2 that referenced this pull request Mar 22, 2026
nbbrooks added a commit to moveit/moveit2 that referenced this pull request Mar 23, 2026
…:path (#3703)

* Update deprecated usage of get_package_share

* Add include guards for ament/ament_index#104

---------

Co-authored-by: Stephanie Eng <seng@ottomotors.com>
Co-authored-by: Nathan Brooks <nathanbrooks@picknik.ai>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants