ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How can generate a list of dependencies from the src folder of a workspace?

asked 2017-01-11 10:53:54 -0600

IvanV gravatar image

updated 2017-01-12 08:21:51 -0600

Hello all,

We have a large workspace with plenty packages coming from third party developers. At its moment, dependencies of those packages where solved using rosdep.

However, for documentation purposes we need the complete list of dependencies of all packages.

Is there a way of automatically generate that dependencies list? Something like an option on rosdep to not install anything, but just list all dependencies and output them to console or file.

So far I haven't find such a tool.

Thank you and best regards.


Just tested rosdep with --simulate --reinstall options in a new workspace where some source has been placed.

First we run with --simulate:

rosdep install --simulate --from-paths ~/workspaces/project/src --ignore-src
#[apt] Installation commands:
  sudo -H apt-get install ros-indigo-hokuyo-node

It successfully list a ROS package dependency.

If we run also with --reinstall:

rosdep install --simulate --reinstall --from-paths ~/workspaces/project/src --ignore-src
#[apt] Installation commands:
  sudo -H apt-get install ros-indigo-hokuyo-node
  sudo -H apt-get install libeigen3-dev

And it additionally shows an already installed non-ROS dependency.

We now install missing dependencies using rosdep:

rosdep install --from-paths ~/workspaces/project/src --ignore-src

And after that, we run it again with --simulate --reinstall options:

rosdep install --simulate --reinstall --from-paths ~/workspaces/project/src --ignore-src
#[apt] Installation commands:
  sudo -H apt-get install libeigen3-dev

It successfully lists the non-ROS dependency, but doesn't list the ROS dependency.

Running it without --reinstall just gives emply output, as all dependencies are already installed:

rosdep install --simulate --from-paths ~/workspaces/project/src --ignore-src

So its seems that rosdep --reinstall only lists/reinstalls non-ROS packages. Is that the expected --reinstall behaviour?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-01-11 11:15:20 -0600

tfoote gravatar image

You can use the --simulate and --reinstall with --ignore-src to get the list I think you want like this: rosdep install -si --reinstall --from-path ~/path/to/src/

edit flag offensive delete link more



Wow. I completely missed that option. However, that command is only showing me the unmatched dependencies and not the ones already installed. Using rosdep install -s --reinstall and rosdep check gives me the same list of packages (and I know for sure that plenty of packages where installed).

IvanV gravatar image IvanV  ( 2017-01-12 01:57:20 -0600 )edit

I am also struggling to figure this out, all I'm trying to do is generate a list of apt package dependencies from a set of multiple ros packages.

IanCol gravatar image IanCol  ( 2019-04-12 13:57:07 -0600 )edit

If you have packages already installed on your system you can also use rospack depends <PACKAGE> however it won't do the rosdep resolution automatically to alias it to the debian package names. So that combined with rospack list and a little scripting can get you what you want. Or you can use the rospkg and rosdep python API to write a python script that does exactly what you want. This is what we do on the buildfarm.

tfoote gravatar image tfoote  ( 2019-04-12 16:04:32 -0600 )edit

Thanks for responding! I did end up hacking up a mess of a bash script, I'll try the python API next time. If it comes out clean, I'll try to share it here. Thanks!

IanCol gravatar image IanCol  ( 2019-04-13 11:27:20 -0600 )edit

answered 2022-10-12 17:11:55 -0600

Combinacijus gravatar image

updated 2022-10-23 14:55:26 -0600

This will list all packages found between <exec_depend>, <build_depend>, <run_depend>, <depend> and similar tags (<[a-z,A-Z,_]*depend>) from package.xml (or any other file)

List all rosdep dependencies (one-liner)

rosdep resolve `grep -RhI -e "^ *<[a-z,A-Z,_]*depend>" ~/catkin_ws/src/ | sed -e "s/.*>\(.*\)<.*/\1/" | sort -r | uniq | tr "\n" " "` 2>/dev/null | sed -e "s/^#.*//" | tr "\n" " " | sed -e "s/  */ /g" -e "s/  *//" |  (echo -n "sudo apt-get install " && cat); echo ""

Just change: ~/catkin_ws/src to your workspace src path.

Example return: sudo apt-get install ros-noetic-visualization-msgs ros-noetic-velodyne-pointcloud ..........

Copy paste output to terminal and it will install all dependencies. Note that maybe not all dependencies listed here are installed because you might use packages from source which are not downloaded via apt. I don't think that this would brake anything just redundant download which will be overridden by workspace packages

List dependencies as rosdep keys

grep -RhI -e "^ *<exec_depend>" -e "^ *<build_depend>"  -e "^ *<run_depend>" ~/catkin_ws/src | sed -e "s/.*>\(.*\)<.*/\1/" | sort | uniq

Rosdep way (missing packages | unusable)

rosdep install --from-paths ~/catkin_ws/src --ignore-src -r --reinstall --simulate

How it works

grep -RhI -e "^ *<exec_depend>" -e "^ *<build_depend>" -e "^ *<run_depend>" ~/catkin_ws/src | sed -e "s/.*>\(.*\)<.*/\1/" | sort | uniq returns rosdep keys as @gvdhoorn mentioned. To get apt packages there is rosdep resolve my_rosdep_key my_rosdep_key2 command

  • grep -RhI
    • -R recursive,
    • -h suppress the file name prefix on output
    • -I ignore binary files
    • -e "^ *<exec_depend>" -e "^ *<build_depend>" -e "^ *<run_depend>" - strings to match if any of those found. ^ * Matches any spaces from line start
    • ~/catkin_ws/src - at which path start recursive search
  • sed -e "s/.*>\(.*\)<.*/\1/" - Removes tags and leaves only package name.
    • sed does find and replace sed -e "s/FIND_THIS/REPLACE_WITH_THIS/"
    • .*> - match start tag <...>
    • \(.*\) match and group package name
    • <.* - match end tag <...>
    • \1 - replace with first group aka package name
  • | sort | uniq - sorts lines and removes duplicates (must sort first)
  • Ommited code (sed and tr does output tidying)
  • 2>/dev/null redirects stderr to null aka don't print stdrr because it's not seen by sed
  • (echo -n "sudo apt-get install " && cat); echo "" predends "sudo apt-get install " to the list of apt packages
edit flag offensive delete link more



Please note that this seems to output rosdepkeys as opposed to actual package names. Especially for system dependencies those will be different.

gvdhoorn gravatar image gvdhoorn  ( 2022-10-13 00:50:36 -0600 )edit

@gvdhoorn Oh right. Made new one-liner to address that that return apt packages. Could you check it and see does it have any obvious problem for e.g. would it override package paths that were installed from source? I think not but still

Combinacijus gravatar image Combinacijus  ( 2022-10-13 11:08:01 -0600 )edit

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: 2017-01-11 10:53:54 -0600

Seen: 4,425 times

Last updated: Oct 23