[ROS in 5 mins] 040 – What is in the directories src, build and devel?

What is in the directories src, build and devel?

Written by Bayode Aderinola

17/09/2018

In this post, we will see what the ROS workspace directories src, build and devel contain. We’ll also see how these directories are used in ROS workspace management.

Let’s go!

Step 1: Create a Project (ROSject) on ROSDS

Head to http://rosds.online and create a project called “ros workspace” (or whatever you wish). Please ensure you select “Ubuntu 16.04 + ROS Kinetic + Gazebo 7” under “Configuration”. Once done with that, open up the project by clicking on “Open ROSject”.

Step 2: Check out what we have in the catkin_ws workspace and save its current state in git

Pick a Shell tool from the Tools menu and locate the catkin_ws directory.

user:~$ cd catkin_ws/
user:~/catkin_ws$ ll
total 24
drwxrwxr-x  5 user user 4096 Jun 11  2018 ./
drwxrwxrwx 10 user user 4096 Dec  2 12:16 ../
-rw-rw-r--  1 user user   98 Nov 17  2017 .catkin_workspace
drwxrwxr-x  7 user user 4096 Jun 11  2018 build/
drwxrwxr-x  3 user user 4096 Jun 11  2018 devel/
drwxrwxr-x  2 user user 4096 Nov 17  2017 src/

So we see that we have three subfolders in the workspace: src, build and devel. Now we are going to save the current state of that directory before we make further changes:

user:~/catkin_ws$ git init
Initialized empty Git repository in /home/user/catkin_ws/.git/
user:~/catkin_ws$ git add .
user:~/catkin_ws$ git commit -m "Initial workspace state"
[master (root-commit) d18311c] Initial workspace state
 112 files changed, 7467 insertions(+)
 create mode 100644 .catkin_workspace
 ...# truncated messages
user:~/catkin_ws$ git status
On branch master
nothing to commit, working tree clean

Step 3: Create a new package in the workspace and observe the changes

Take note that only the src folder has been changed here.

# We change the workspace's src folder and create a package.
user:~/catkin_ws$ cd src
user:~/catkin_ws/src$ catkin_create_pkg test_package rospy
Created file test_package/package.xml
Created file test_package/CMakeLists.txt
Created folder test_package/src
Successfully created files in /home/user/catkin_ws/src/test_package. Please adjust the values in package.xml.

# We change back to the workspace (catkin_ws) directory and see that we have new untracked files and directories. 
# We commit them to git.
user:~/catkin_ws/src$ cd ..
user:~/catkin_ws$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/test_package/

nothing added to commit but untracked files present (use "git add" to track)
user:~/catkin_ws$ git add src/test_package/
user:~/catkin_ws$ git commit -m "Create a test package"
[master 13e3e91] Create a test package
 2 files changed, 266 insertions(+)
 create mode 100644 src/test_package/CMakeLists.txt
 create mode 100644 src/test_package/package.xml

# We check the workspace folder again in git and see that it's "clean"
user:~/catkin_ws$ git status
On branch master
nothing to commit, working tree clean
user:~/catkin_ws$

Step 4: Compile the workspace and observe the changes

Now we will compile the workspace and see what happens.

# COMPILE THE WORKSPACE
user:~/catkin_ws$ catkin_make
Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install
####
#### Running command: "cmake /home/user/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install -G Unix Makefiles" in "/home/user/catkin_ws/build"
####

#...lots of truncated messages

# CHECK THE WORKSPACE IN GIT
user:~/catkin_ws$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   build/CMakeCache.txt
        modified:   build/CMakeFiles/Makefile.cmake
        modified:   build/CMakeFiles/Makefile2
        modified:   build/CMakeFiles/TargetDirectories.txt
        modified:   build/CTestTestfile.cmake
        modified:   build/Makefile
        modified:   build/catkin/catkin_generated/version/package.cmake
        modified:   build/catkin_generated/generate_cached_setup.py
        modified:   build/catkin_generated/installspace/_setup_util.py
        modified:   build/catkin_generated/installspace/setup.sh
        modified:   build/catkin_generated/order_packages.cmake
        modified:   build/catkin_generated/order_packages.py
        modified:   build/catkin_generated/setup_cached.sh
        modified:   build/catkin_generated/stamps/Project/_setup_util.py.stamp
        modified:   build/catkin_generated/stamps/Project/package.xml.stamp
        modified:   build/catkin_make.cache
        modified:   build/cmake_install.cmake
        modified:   devel/_setup_util.py
        modified:   devel/setup.sh

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        build/CTestConfiguration.ini
        build/CTestCustom.cmake
        build/atomic_configure/
        build/catkin_generated/installspace/local_setup.bash
        build/catkin_generated/installspace/local_setup.sh
        build/catkin_generated/installspace/local_setup.zsh
        build/test_package/
        devel/cmake.lock
        devel/lib/
        devel/local_setup.bash
        devel/local_setup.sh
        devel/local_setup.zsh
        devel/share/

no changes added to commit (use "git add" and/or "git commit -a")

Now we see that there a lot of modified and new files in both build and devel, (no) thanks to the command we just ran.

Let’s put it all together in the next step.

Step 5: Put it all together – translate the action into words

I strongly believe you already got some hints about the src, build and devel directories from the commands we ran in the steps above. Now let’s consolidate those hints:

  • src contains the source files for packages created. That’s why we created a package in this folder in Step 3.
  • we run cmake from build  to build the packages in src. You can call it cmake‘s working directory. You’ll also notice that the bulk of modified files are in this direction after we ran catkin_make.
  • ROS places built files of the package in devel for development/testing. Yep, and that’s why most of the files in this directory after catkin_make are new.
  • Extra: install – this folder will be created if you compile with the command catkin_make install. Try it out!

And…that was it!

Extra: Video

Prefer to listen to the “sights and sounds” version of this post? We have one for you below; happy watching!

Further Learning

If you are a ROS beginner and want to learn ROS basics fast, we recommend you take any of the following courses on Robot Ignite Academy:

Feedback

Did you like this post? Whatever the case, please leave a comment in the comments section below, so we can interact and learn from each other.

If you want to learn about other ROS topics, please let us know on the comments area and we will do a post or video about it.

Thank you!

Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

0 Comments

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This