Skip to content

Use get_package_share_path just as python - #112

Merged
ahcorde merged 6 commits into
ament:rollingfrom
nobleo:get_package_share_path
Feb 25, 2026
Merged

ahcorde merged 6 commits into
ament:rollingfrom
nobleo:get_package_share_path

Conversation

@Timple

@Timple Timple commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

cpp and python were going out of sync.

Besides

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

Looks much better than

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

Due to the short-livedness of the get_package_share_directory(..., std::filesystem::path) syntax, I didn't deprecated it.

I can finish this PR including the tests etc if that's appreciated. For now I wanted feedback first. 🙂

@Timple
Timple force-pushed the get_package_share_path branch from 9781967 to a3b1568 Compare February 20, 2026 08:23
@jmachowinski

Copy link
Copy Markdown

I like the change. It's way cleaner than the previous version.

*/
AMENT_INDEX_CPP_PUBLIC
void
get_package_share_directory(const std::string & package_name, std::filesystem::path & path);

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.

we need to update downstream packages

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How? Or to what?
Or do we (shortly) keep this function around for depreciation?

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 the API in question was added after kilted and therefore we can directly remove/replace it before the next release.
Removing this API will break all the tests etc that were already moved to the new API and need to be fixed.
E.g. if you check out the full rolling stack and remove the old API fix all compile failures resulting from this and do PRs for it.

@Timple Timple Feb 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And then merge simultaneously?

Then we would need someone with merge access to all these repos I guess?

Edit: or we can let everyone merge at their own pace I guess

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.

I have permission to merge PRs across all the ROS 2 core.

We should deprecate the method instead of removing it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I deprecated the previous implementation. So this can be merged and the other repositories will get a deprecation warning.

@ahcorde

ahcorde commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

@ahcorde ahcorde left a comment

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.

Windows is not compiling

  utest.cpp

utest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::filesystem::path __cdecl ament_index_cpp::get_package_share_path(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?get_package_share_path@ament_index_cpp@@YA?AVpath@filesystem@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z) referenced in function "private: virtual void __cdecl AmentIndexCpp_get_package_share_path_Test::TestBody(void)" (?TestBody@AmentIndexCpp_get_package_share_path_Test@@EEAAXXZ) [C:\ci\ws\build\ament_index_cpp\ament_index_cpp_utest.vcxproj]

C:\ci\ws\build\ament_index_cpp\Release\ament_index_cpp_utest.exe : fatal error LNK1120: 1 unresolved externals [C:\ci\ws\build\ament_index_cpp\ament_index_cpp_utest.vcxproj]

Timple and others added 2 commits February 24, 2026 13:51
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
Signed-off-by: Tim Clephas <[email protected]>
Signed-off-by: Tim Clephas <[email protected]>
@Timple

Timple commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

Windows is not compiling

  utest.cpp

utest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::filesystem::path __cdecl ament_index_cpp::get_package_share_path(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?get_package_share_path@ament_index_cpp@@YA?AVpath@filesystem@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@4@@Z) referenced in function "private: virtual void __cdecl AmentIndexCpp_get_package_share_path_Test::TestBody(void)" (?TestBody@AmentIndexCpp_get_package_share_path_Test@@EEAAXXZ) [C:\ci\ws\build\ament_index_cpp\ament_index_cpp_utest.vcxproj]

C:\ci\ws\build\ament_index_cpp\Release\ament_index_cpp_utest.exe : fatal error LNK1120: 1 unresolved externals [C:\ci\ws\build\ament_index_cpp\ament_index_cpp_utest.vcxproj]

Found a wrong include, I hope windows works now?

@ahcorde

ahcorde commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

@ahcorde
ahcorde merged commit acfcac6 into ament:rolling Feb 25, 2026
2 checks passed
@nbbrooks

nbbrooks commented Mar 15, 2026 •

Copy link
Copy Markdown

Is there a source of truth somewhere for deprecations and deletions and their associated PRs? A docs.ros.org page? A ROS discourse post? When moveit2 rolling starts failing CI jobs around deprecations, it takes me a frustrating amount of time for me to find the particular GH organization and repo associated with that breakage to understand and fix it, whether that is something in rclcpp, ament, tf, etc.

I imagine if this existed/was more widely known, more package maintainers would mention the deprecation/deletion PR in their issue, which would make it easier for other package maintainers to do their migration.

nbbrooks added a commit to nbbrooks/moveit2 that referenced this pull request Mar 15, 2026
…and ament_index_cpp::get_package_share_directory(*, *) to ament_index_cpp::get_package_share_path(package_name) addressing ament/ament_index#112

Revert QT support changes which will be addressed in a separate PR

Temporarily add '-Wno-error=deprecated-declarations' to suppress other upstream deprecatios from short circuiting CI
@Timple

Timple commented Mar 15, 2026

Copy link
Copy Markdown
Contributor Author

Can this be backported to active distro's? Minus the deprecation message of course.

To prevent these kind of constructions for packages that use a single branch for all active distros: https://github.com/moveit/moveit2/pull/3705/changes#diff-c5eab2d24cfc0cc52d9d0fadc0596533f00ca45e3f8ea45a31bcd8c72b34fafaR40

@christophebedard

Copy link
Copy Markdown
Member

@Mergifyio backport kilted jazzy humble

@mergify

mergify Bot commented Apr 26, 2026 •

Copy link
Copy Markdown

backport kilted jazzy humble

✅ Backports have been created

Details

Cherry-pick of acfcac6 has failed:

On branch mergify/bp/kilted/pr-112
Your branch is up to date with 'origin/kilted'.

You are currently cherry-picking commit acfcac6.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   ament_index_cpp/CMakeLists.txt
	new file:   ament_index_cpp/include/ament_index_cpp/get_package_share_path.hpp
	new file:   ament_index_cpp/src/get_package_share_path.cpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   ament_index_cpp/include/ament_index_cpp/get_package_share_directory.hpp
	both modified:   ament_index_cpp/src/get_package_share_directory.cpp
	both modified:   ament_index_cpp/test/utest.cpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of acfcac6 has failed:

On branch mergify/bp/jazzy/pr-112
Your branch is up to date with 'origin/jazzy'.

You are currently cherry-picking commit acfcac6.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   ament_index_cpp/CMakeLists.txt
	new file:   ament_index_cpp/include/ament_index_cpp/get_package_share_path.hpp
	new file:   ament_index_cpp/src/get_package_share_path.cpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   ament_index_cpp/include/ament_index_cpp/get_package_share_directory.hpp
	both modified:   ament_index_cpp/src/get_package_share_directory.cpp
	both modified:   ament_index_cpp/test/utest.cpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of acfcac6 has failed:

On branch mergify/bp/humble/pr-112
Your branch is up to date with 'origin/humble'.

You are currently cherry-picking commit acfcac6.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   ament_index_cpp/CMakeLists.txt
	new file:   ament_index_cpp/include/ament_index_cpp/get_package_share_path.hpp
	new file:   ament_index_cpp/src/get_package_share_path.cpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   ament_index_cpp/include/ament_index_cpp/get_package_share_directory.hpp
	both modified:   ament_index_cpp/src/get_package_share_directory.cpp
	both modified:   ament_index_cpp/test/utest.cpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@christophebedard

christophebedard commented Apr 26, 2026 •

Copy link
Copy Markdown
Member

Can this be backported to active distro's? Minus the deprecation message of course.

To prevent these kind of constructions for packages that use a single branch for all active distros: https://github.com/moveit/moveit2/pull/3705/changes#diff-c5eab2d24cfc0cc52d9d0fadc0596533f00ca45e3f8ea45a31bcd8c72b34fafaR40

@Timple I triggered the automatic backport PRs. Would you be willing to open PRs against those branches in order to fix conflicts and adapt them to the older distros? I've posted some quick comments on all PRs.

Timple added a commit to nobleo/ament_index that referenced this pull request May 13, 2026
Signed-off-by: Tim Clephas <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit acfcac6)

# Conflicts:
#	ament_index_cpp/include/ament_index_cpp/get_package_share_directory.hpp
#	ament_index_cpp/src/get_package_share_directory.cpp
#	ament_index_cpp/test/utest.cpp
Timple added a commit to nobleo/ament_index that referenced this pull request May 13, 2026
Signed-off-by: Tim Clephas <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit acfcac6)

# Conflicts:
#	ament_index_cpp/include/ament_index_cpp/get_package_share_directory.hpp
#	ament_index_cpp/src/get_package_share_directory.cpp
#	ament_index_cpp/test/utest.cpp
@Timple

Timple commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Done. Humble isn't possible because c++14

ahcorde added a commit that referenced this pull request May 14, 2026
Signed-off-by: Tim Clephas <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
(cherry picked from commit acfcac6)
Signed-off-by: Tim Clephas <[email protected]>
Co-authored-by: Tim Clephas <[email protected]>
ahcorde pushed a commit that referenced this pull request May 15, 2026
(cherry picked from commit acfcac6)

Signed-off-by: Tim Clephas <[email protected]>
Co-authored-by: Tim Clephas <[email protected]>
nbbrooks added a commit to nbbrooks/moveit2 that referenced this pull request Jul 9, 2026
…lling

The RCLCPP_VERSION_GTE(30, 0, 0) branches added in moveit#3703 for these
three files reference a two-argument overload of
`ament_index_cpp::get_package_share_directory(package_name, out_path)`
that has never existed. Rolling's ament_index_cpp API is
`get_package_share_path(package_name)` returning `std::filesystem::path`
directly (ament/ament_index#112), and the corresponding header is
`get_package_share_path.hpp` — the old `get_package_share_directory.hpp`
has been removed.

Switch:
- Rolling header: `#include <ament_index_cpp/get_package_share_path.hpp>`
- Rolling calls: `get_package_share_path(pkg)` returning path directly

Pre-Rolling (`#else` branch) keeps the current
`get_package_share_directory(pkg)` returning `std::string`.

Verified with a full source-build of moveit2 + downstream against
`ubuntu:resolute` + ROS Rolling (`ros2-testing` apt).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
nbbrooks added a commit to nbbrooks/moveit2 that referenced this pull request Jul 9, 2026
…lling

The RCLCPP_VERSION_GTE(30, 0, 0) branches added in moveit#3703 for these
three files reference a two-argument overload of
`ament_index_cpp::get_package_share_directory(package_name, out_path)`
that has never existed. Rolling's ament_index_cpp API is
`get_package_share_path(package_name)` returning `std::filesystem::path`
directly (ament/ament_index#112), and the corresponding header is
`get_package_share_path.hpp` — the old `get_package_share_directory.hpp`
has been removed on the Ubuntu Resolute-based images.

Switch:
- Feature-test via `__has_include(<ament_index_cpp/get_package_share_path.hpp>)`
  rather than RCLCPP_VERSION_GTE — the API rename is in ament_index_cpp,
  not rclcpp, and the two versions can drift (rolling-ci's frozen Noble
  container has RCLCPP >= 30 but no new header yet).
- Rolling: `get_package_share_path(pkg)` returning path directly.
- Pre-Rolling: keep `get_package_share_directory(pkg)` returning std::string.

Verified with a full source-build of moveit2 + downstream against
`ubuntu:resolute` + ROS Rolling (`ros2-testing` apt).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
nbbrooks added a commit to nbbrooks/moveit2 that referenced this pull request Jul 9, 2026
…lling

The RCLCPP_VERSION_GTE(30, 0, 0) branches added in moveit#3703 for these
three files reference a two-argument overload of
`ament_index_cpp::get_package_share_directory(package_name, out_path)`
that has never existed. Rolling's ament_index_cpp API is
`get_package_share_path(package_name)` returning `std::filesystem::path`
directly (ament/ament_index#112), and the corresponding header is
`get_package_share_path.hpp` — the old `get_package_share_directory.hpp`
has been removed on the Ubuntu Resolute-based images.

Guard: RCLCPP_VERSION_GTE(33, 0, 0).

The ament_index_cpp rename shipped with rclcpp 33 (Rolling on Ubuntu
Resolute). Rolling on Noble was still at rclcpp 30.x with the old
header. So the moveit#3703 threshold of 30 was set too early — it was true
on both Noble-era rolling (old API) and Resolute-era rolling (new API),
which is why the code compiled on Noble-based rolling-ci but chose the
wrong branch.

Verified with a full source-build of moveit2 + downstream against
`ubuntu:resolute` + ROS Rolling (`ros2-testing` apt).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
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.

5 participants