Skip to content

ROS2 project from development to deployment, Part 2: Add udev and other system files

How to add additional system files to the package, like udev rules, systemd service, etc.

rules

The debian/rules file is a makefile that is used to build the package. It contains the instructions for building, installing, and cleaning up the package. The debian/rules file is generated by bloom when you run the bloom-generate command. You can modify it to add additional steps to the build process.

The debian/rules file is a makefile that base on dh (debhelper) and it is used to build the package. It contains the instructions for building, installing, and cleaning up the package.

Command What it does
dh_auto_configure Runs ./configure, cmake, or similar
dh_auto_build Runs make or equivalent
dh_auto_test Runs test suites if available
dh_auto_install Installs built files into debian/<pkg> staging area
dh_installdocs Installs docs like README
dh_strip Removes debug symbols
dh_builddeb Builds the final .deb package

demo: override deb location

Add patch file to edit debian/rules file

  • Create debian_scripts folder in the project root
  • Create patch_rule.sh and patch_compat.sh files in the debian_scripts folder
file Description
patch_rule.sh add override method like override_dh_builddeb dh_auto_install
patch_compat.sh change compat level to 10 or higher
debian_scripts/patch_rule.sh
1
2
3
4
5
6
7
    #!/bin/sh

    cat <<'EOF' >> debian/rules

    override_dh_builddeb:
        dh_builddeb --destdir=/workspace/debs
    EOF

override manual

Add dh_builddeb rule to end of file

debian/rules
1
2
3
4
# add this to the end of the file

override_dh_builddeb:
    dh_builddeb --destdir=/workspace/debs

```

compat

Bloom uses compat=9 for maximum compatibility across various buildfarm environments and older ROS build tools. the level define the debhelper futures to use. in out case whe need to change it to 10 or higher to use the --destdir option.

debian_scripts/patch_compat.sh
1
2
3
cat <<'EOF' > debian/compat
10
EOF

VScode task

Using vscode to run bloom , custom script and the fakeroot to build debian package.

"version": "2.0.0",
"tasks": [
    {
        "label": "build <package_name>",
        "type": "shell",
        "command": "bloom-generate rosdebian --ros-distro humble && ./debian_scripts/patch_rule.sh && ./debian_scripts/patch_compat.sh && fakeroot debian/rules binary",
        "options": {
            "cwd": "${workspaceFolder}/src/<package_name>",
        }
    }
]

Demo: Add postinst script file

Add postinst to debian file

  • Create debian_scripts folder in the project root
  • Create patch_rule.sh and patch_compat.sh files in the debian_scripts folder
  • Create postinst file in the debian_scripts folder
debian_scripts/postinst
1
2
3
4
5
#!/bin/sh
set -e

# pip install textual==1.0.0
exit 0
debian_scripts/patch_rule.sh
#!/bin/sh

cat <<'EOF' >> debian/rules

override_dh_install:
    dh_install
    cp \$(CURDIR)/debian_scripts/postinst debian/postinst
    chmod 755 debian/postinst

override_dh_builddeb:
    dh_builddeb --destdir=/workspace/debs
EOF
  • Add override_dh_install
  • copy postinst file to debian/postinst folder
  • Add permission to the postinst file
  • Set override_dh_builddeb to copy the debian package to /workspace/debs folder
debian_scripts/patch_compat.sh
1
2
3
cat <<'EOF' > debian/compat
10
EOF

TODO: Add dpkg -I to check the package


Demo: Add udev rules

github action

We use github actions and act to run it locally.

Add udev rule to /etc/udev/rules.d/

  • create udev rules file (put it in project root under udev folder)
  • Add install script, this script update debian rules file after bloom generate
  • Add step to github actions command
udev rules
# any udev rules file
post_bloom_script.sh
1
2
3
4
5
6
7
8
9
#!/bin/bash

cat <<EOF >> src/<package_name>/debian/rules

override_dh_install:
    mkdir -p \$(DEBIAN)/etc/udev/rules.d
    cp -r udev/* \$(DEBIAN)/etc/udev/rules.d
    dh_install
EOF

check the $(DEBIAN) path

The $(DEBIAN) path is the path where the debian package is created. You can check it by running the following command:

TAB not space

Make sure to use tab and not space in the post_bloom_script.sh file. You can check it using cat -T command.

github action step
1
2
3
- name: Add udev rules
  run: |
    ./src/<package_name>/post_bloom_script.sh

TAB VSCode

Config vscode to use tab and not spaces for shell script

set vscode to use tab and not spaces
1
2
3
4
5
6
7
{
    "[shellscript]": {
        "editor.insertSpaces": false,
        "editor.tabSize": 4,
        "editor.detectIndentation": false
    },
}

TAB check

Using cat to check if file contains tab or space

cat -T <file>
1
2
3
4
5
6
#!/bin/bash

cat <<EOF
^Ia
^Ib
EOF