Ask Your Question

Where is the source code of installed packages?

asked 2016-10-30 06:17:55 -0600

danyloM gravatar image

I have installed ROS Kinetic and it sits is the /opt/ros/kinetic/ folder which has the following structure:

├── bin
├── etc
├── include
├── lib
├── setup.bash
├── setup.zsh
└── share

Now suppose I want to view the source code which makes rosrun turtlesim turtle_teleop_key possible. It is a node of the turtlesim package, so I navigate to this package using roscd turtlesim. This puts me into the directory /opt/ros/kinetic/share/turtlesim, which has the following files:

├── cmake
├── images
├── msg
├── package.xml
└── srv

The actual .cpp source files are nowhere to be found! How can I view the source files for a given package? turtlesim is just an example, there are of course other packages whose source I'm interested in looking at.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-10-30 10:38:57 -0600

abrzozowski gravatar image

updated 2016-10-30 14:27:44 -0600

You can retrive path to sources of specific package by typing roslocate uri <package_name>, for more information about roslocate see reference.

Getting the sources for turtlesim can be done by: git clone $(roslocate uri turtlesim 2> /dev/null | awk '/https/')

edit flag offensive delete link more


Thanks, this worked for me!

danyloM gravatar image danyloM  ( 2016-10-30 12:18:07 -0600 )edit

This works, but note that you don't necessarily get the sources that were used to build the (debian) pkg that you installed. git clone <url> checks out whatever the repository has configured as the default HEAD, while apt-get source $pkg downloads a tarball for a specific version.

gvdhoorn gravatar image gvdhoorn  ( 2016-10-30 13:08:32 -0600 )edit

I agree with @gvdhoorn 100 percent. If you download sources by above command, you'll get devel (it means develop) branch (branch set as main for this specyfic repository e.g. kinetic-devel), not released sources (based on debian package).

abrzozowski gravatar image abrzozowski  ( 2016-10-30 14:17:57 -0600 )edit

So, if you choose this approach, you should check the branch of downloaded repository to make sure you are on right (for kinetic call: git checkout kinetic-devel).

abrzozowski gravatar image abrzozowski  ( 2016-10-30 14:18:11 -0600 )edit

If you really want the specific version of the sources used to build a pkg, checking out the 'devel branch' corresponding to your ROS distribution is not enough. You'd have to checkout the commit that was used to draft a release from. The repo should have been tagged. Use those.

gvdhoorn gravatar image gvdhoorn  ( 2016-10-30 16:17:42 -0600 )edit

Yes, i understand. A release pkg is always behind or equal/on beginning/ to a 'devel branch'. If you want download the latest sources with 'fixes/features', using command based on a roslocate is appropriate. Otherwise, apt-get source $pkg_name is better solution.

abrzozowski gravatar image abrzozowski  ( 2016-10-30 17:34:16 -0600 )edit

answered 2016-10-30 08:40:32 -0600

gvdhoorn gravatar image

If you've installed ROS Kinetic using the binary debian distribution, then the sources are not installed. Only the binaries (ie: the nodes) and any other related artefacts (launch files, urdf/xacros, etc). What is installed is down to the developers btw: they have to include CMake install(..) directives in their CMakeLists.txt for whatever they want to be included in the binary distribution(s).

Retrieving the sources for a particular package is relatively easy, using apt-get source $pkg_name. You have update your apt configuration slightly though.

See "apt-get source" for for how to do this.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2016-10-30 06:17:31 -0600

Seen: 5,546 times

Last updated: Oct 30 '16