ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Determine path of (sourced) catkin workspace?

asked 2019-01-08 07:30:50 -0500

bluenote gravatar image

updated 2019-01-08 09:06:29 -0500

After sourcing a Catkin workspace, what is the best way to determine the root path of the sourced workspace? I'm aware of catkin locate, however this doesn't have the desired behavior because it does not rely on the sourced workspace, but rather is working directory dependent, i.e.,

  • it would not work from outside of the workspace path structure,
  • and it does not work if you source workspace A but cd into workspace B etc.

How can I reliably determine the path of the workspace that has been sourced?

Ideally I'm looking a solution that doesn't require further processing like parsing $CMAKE_PREFIX_PATH, because I need access to the path in several places (scripts) and I'd like to avoid repeating the post processing logic in every place.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2019-01-08 08:04:53 -0500

dljubic gravatar image

Hello bluenote,

the way I am usually doing it is by typing: echo $CMAKE_PREFIX_PATH in my terminal. It gives you all the sourced workspaces.

As a little side note, I would advise you to add the following line in your .bashrc file in order to know which workspaces are sourced every time you open a new terminal.

echo "CMAKE_PREFIX_PATH = $CMAKE_PREFIX_PATH"

If you have any further questions, feel free to ask. :)

edit flag offensive delete link more

Comments

I was actually looking a solution that doesn't require further processing, because I need access to the path in several places (scripts) and I would like to avoid repeatedly implementing the disassembling the list of paths and navigating to the root.

bluenote gravatar image bluenote  ( 2019-01-08 09:04:36 -0500 )edit

You could parse it once in a bash script or in the .bashrc and export an environment variable (e.g. SOURCED_WS) when you find the path you are looking for. That way, you would have to process it only once. Could this idea be of any use? :)

dljubic gravatar image dljubic  ( 2019-01-08 09:26:11 -0500 )edit

I cannot rely on modifying .bashrc (must work for many users / different ws, and on CI systems). My goal was to have something that is defined exactly when setup.sh gets sourced. Surprising that catkin lacks this basic feature... Maybe an env-hook could do it, but the documentation is poor.

bluenote gravatar image bluenote  ( 2019-01-08 09:45:36 -0500 )edit
1

CMAKE_PREFIX_PATH is the variable to use. It's a standard linux env var with paths in it, separated by colons (:). First path is of the last sourced workspace. You'll have to write a short bash script (or even a Python script) that parses it. I don't see any other way.

gvdhoorn gravatar image gvdhoorn  ( 2019-01-08 09:59:21 -0500 )edit

@gvdhoorn It's not possible to reliably extract the path from CMAKE_PREFIX_PATH: (1) as you say, it is a standard linux variable, so making the assumption that the first path is the workspace can be wrong; (2) the path points to the devel space and afaik it can be arbitrarily nested, right?

bluenote gravatar image bluenote  ( 2019-01-09 03:12:51 -0500 )edit
0

answered 2020-10-28 06:49:09 -0500

chutsu gravatar image

As of October 2020, probably a better solution instead of parsing the $CMAKE_PREFIX_PATH and obtain the last* sourced path is to use catkin tools's catkin locate command. The output of the command outputs the currently sourced catkin workspace, further there are additional options to locate the build, src, devel directories and more. Look here for more info.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-01-08 07:30:50 -0500

Seen: 4,048 times

Last updated: Oct 28 '20