Patching a Debian Package

This is my experience on patching a debian package. Once you learn how to do it, its so simple and straightforward I wanted to demonstrate.

Problem

I develop an application named SerialPlot. It’s programmed with Qt SDK. It makes use of QSerialPort module of Qt for accessing the serial port devices. When I updated my system to Linux Mint 18 which is based on Ubuntu 16.04, SerialPlot got broken. When you remove a USB based serial port device while it is still open in SerialPlot, application goes into a loop and finally crashes. After some investigation I determined this was an issue with the Qt 5.5 . Problem was already fixed in the next version of the Qt.

Solution

I don’t want to update my complete Qt installation. More importantly I didn’t want to force people to update whole Qt library, just for my application. So I decided to port the fixes back to the 5.5 version of the QSerialPort library. This library is distributed in a debian package named libqt5serialport5.

Gathering Requirements

Change to an empty directory. Because below commands will liter the place a little.

mkdir qtserialport-fix && cd qtserialport-fix

Downloading the build dependencies:

apt build-dep libqt5serialport5

Downloading the source package of the libqt5serialport5. Remember, before this step you should have enabled the source package repositories.

apt source libqt5serialport5

Installing some tools that are required to build debian packages:

apt install build-essential fakeroot devscripts

Making the Fix

Now you should have 1 directory and 3 files in your working directory.

qtserialport-opensource-src-5.5.1/
qtserialport-opensource-src_5.5.1.orig.tar.xz
qtserialport-opensource-src_5.5.1-2build1.debian.tar.gz
qtserialport-opensource-src_5.5.1-2build1.dsc

The file *.orig.tar.xz is the original source code.  *.debian.tar.gz file is the packaged debian source code file. *.dsc file is required to upload package to a debian repository. The directory should contain our source package and debian/ directory required to patch and re-build the debian package already extracted.

To patch a debian package properly we will use a tool named quilt. This is a tool specifically created to manage patches to debian packages.

Change into the source directory:

cd qtserialport-opensource-src-5.5.1/

First should apply all the existing (if any) patches.

quilt push -a

Now we create a new patch:

quilt new fix-resourceerror-on-close.diff

Add the file we want to change to current patch:

quilt add src/serialport/qserialport_unix.cpp

Now it’s time to open the file in your favorite editor and make the necessary changes. After you save your file, tell quilt about the changes.

quilt refresh

To finish patching, un-apply all patches:

quilt pop -a

Building the Package

To build the package just call:

dpkg-buildpackage

If build succeeds you should have one or more *.deb files in the parent directory as result. Now you can install your fixed package.

sudo dpkg --install libqt5serialport5_5.5.1-2build1_amd64.deb

What Next?

If you want to distribute your fixed package to others, next steps would be to upload it to a PPA (or a regular debian repository, if you have one). For this you should change the version of the package. This is done by changing the debian/changelog file. But I won’t get into the any more details.

Finally

Please note that this is not a tutorial. If you are going to do this, you should read about debian packaging. Debian wiki is a good place to start. Unfortunately good information is scattered around and it can take some time until you understand what is exactly going on. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *