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

Revision history [back]

click to hide/show revision 1
initial version

This will list all packages found between <exec_depend>, <build_depend> and <run_depend> tags from package.xml (or any other file)

List dependencies

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

Change: ~/catkin_ws/src to your package src path


How it works

  • grep -RhI -e "^ *<exec_depend>" -e "^ *<build_depend>" -e "^ *<run_depend>" WS_SRC_FOLDER
    • -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 file 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)

If you don't use Noetic <exec_depend> tags needs to be change just check any package.xml file and see what tags you want to extract

Other rosdep solution

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

Or

rosdep install --from-paths ~/catkin_ws/src --ignore-src -r --reinstall --simulate | sed -e "s/ *sudo -H apt-get install //"

But this returns less packages

This will list all packages found between <exec_depend>, <build_depend> and <run_depend> tags from package.xml (or any other file)

List dependenciesall rosdep dependencies (one-liner)

rosdep resolve `grep -RhI -e "^ *<exec_depend>" -e "^ *<build_depend>"  -e "^ *<run_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

Change: ~/catkin_ws/src to your package src path

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>" WS_SRC_FOLDER~/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 file 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)

    If you

  • Ommited code (sed and tr does output tidying)
  • 2>/dev/null redirects stderr to null aka don't use Noetic <exec_depend> tags needs to be change just check any package.xml file and see what tags you want to extract

    Other rosdep solution

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

    Or

    rosdep install --from-paths ~/catkin_ws/src --ignore-src -r --reinstall --simulate | sed -e "s/ *sudo -H print stdrr because it's not seen by sed

  • (echo -n "sudo apt-get install //"

    But this returns less " && cat); echo "" predends "sudo apt-get install " to the list of apt packages

This will list all packages found between <exec_depend>, <build_depend> and <run_depend> tags from package.xml (or any other file)

List all rosdep dependencies (one-liner)

rosdep resolve `grep -RhI -e "^ *<exec_depend>" -e "^ *<build_depend>"  -e "^ *<run_depend>" *<[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

This will list all packages found between <exec_depend>, <build_depend> and , <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