Skip to content

Extend API to use std::filesystem - #104

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

ahcorde merged 5 commits into
rollingfrom
ahcorde/rolling/path_api

Conversation

@ahcorde

@ahcorde ahcorde commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

Related with this issue #92

@Ryanf55 FYI

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
@Ryanf55

Ryanf55 commented Nov 13, 2025

Copy link
Copy Markdown

Nice to see this, will review soon!

Comment thread ament_index_cpp/src/has_resource.cpp Outdated
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 <[email protected]>
@ahcorde
ahcorde requested a review from Ryanf55 November 25, 2025 15:03
@ahcorde

ahcorde commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

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

ahcorde commented Dec 8, 2025

Copy link
Copy Markdown
Contributor Author

@ros-pull-request-builder retest this please

@ahcorde

ahcorde commented Dec 8, 2025

Copy link
Copy Markdown
Contributor Author

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

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
@ahcorde

ahcorde commented Dec 18, 2025

Copy link
Copy Markdown
Contributor Author

* \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>

@jmachowinski jmachowinski Dec 18, 2025 •

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 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 <[email protected]>
@ahcorde

ahcorde commented Dec 19, 2025 •

Copy link
Copy Markdown
Contributor Author

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
@peci1

peci1 commented Jan 26, 2026

Copy link
Copy Markdown

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

peci1 commented Jan 26, 2026

Copy link
Copy Markdown

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

@jmachowinski

jmachowinski commented Jan 26, 2026 •

Copy link
Copy Markdown

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

@peci1

peci1 commented Jan 26, 2026

Copy link
Copy Markdown

Okay, I'll have a look ;)

@Ryanf55

Ryanf55 commented Jan 26, 2026

Copy link
Copy Markdown

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 <[email protected]>
peci1 pushed a commit to peci1/ament_index that referenced this pull request Jan 27, 2026
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
@peci1

peci1 commented Jan 27, 2026

Copy link
Copy Markdown

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 <[email protected]>
Signed-off-by: Martin Pecka <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
mergify Bot pushed a commit that referenced this pull request Feb 2, 2026
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Martin Pecka <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(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 <[email protected]>
Signed-off-by: Martin Pecka <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(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 <[email protected]>
Signed-off-by: Martin Pecka <[email protected]>
Co-authored-by: Martin Pecka <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
*/
AMENT_INDEX_CPP_PUBLIC
void
get_package_prefix(const std::string & package_name, std::filesystem::path & path);

@Timple Timple Feb 19, 2026 •

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.

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 <[email protected]>
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 <[email protected]>
Co-authored-by: Nathan Brooks <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
arntanguy added a commit to arntanguy/mc_rtc_ros_compat that referenced this pull request Nov 23, 2026
arntanguy added a commit to arntanguy/mc_rtc_ros_compat that referenced this pull request Nov 23, 2026
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