Debian Packaging from First Principles – Part 2 – Dependencies
Following on from my first blog post in this series, today I’m looking at dependencies within .deb
files. As with part 1, all of the source code files for these packages are available from my project’s repository.
Impossible Dependencies
First of all, we’ll build an un-installable package with impossible to resolve dependencies. The libreoffice
Debian package is composed of a number individual packages such as libreoffice-writer
, libreoffice-calc
, and libreoffice-impress
. Imagine if Microsoft fully embraced their open-source ambitions; we could one day see microsoftoffice-word
, microsoftoffice-excel
and microsoftoffice-powerpoint
. Until then, the following package will remain impossible to install.
Package: dpfp-impossibledependencies
Version: 0.1.0-1
Architecture: all
Description: An effectively empty deb file with impossible to resolve dependencies, manually assembled to understand Debian packaging.
Maintainer: Mike Coats <i.am@mikecoats.com>
Depends: microsoftoffice-word, microsoftoffice-excel, microsoftoffice-powerpoint, microsoftoffice-outlook
Since we’re not going to be able to install any files, anyway, the impossible package can be empty by including a blank tar file. This can be accomplished by passing the --files-from /dev/null
argument to the tar command within the Makefile.
Attempting to install that file will return an error for each package that dpkg
is unable to find.
$ sudo dpkg -i ./dpfp-impossibledependencies_0.1.0-1_all.deb
Selecting previously unselected package dpfp-impossibledependencies.
(Reading database ... 160683 files and directories currently installed.)
Preparing to unpack .../dpfp-impossibledependencies_0.1.0-1_all.deb ...
Unpacking dpfp-impossibledependencies (0.1.0-1) ...
dpkg: dependency problems prevent configuration of dpfp-impossibledependencies:
dpfp-impossibledependencies depends on microsoftoffice-word; however:
Package microsoftoffice-word is not installed.
dpfp-impossibledependencies depends on microsoftoffice-excel; however:
Package microsoftoffice-excel is not installed.
dpfp-impossibledependencies depends on microsoftoffice-powerpoint; however:
Package microsoftoffice-powerpoint is not installed.
dpfp-impossibledependencies depends on microsoftoffice-outlook; however:
Package microsoftoffice-outlook is not installed.
dpkg: error processing package dpfp-impossibledependencies (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
dpfp-impossibledependencies
Plain Dependency
A more rational example is one that depends on the single, already installed, package we created last time. To do so, our depends
line becomes much simpler this time, just the name of the simple, no-dependency, package.
Package: dpfp-plaindependency
Version: 0.1.0-1
Architecture: all
Description: A bare-minimum deb file with a simple dependency, manually assembled to understand Debian packaging.
Maintainer: Mike Coats <i.am@mikecoats.com>
Depends: dpfp-simple
To prove that this package really does depend on dpfp-simple
we’ll add a symbolic link in our new package that refers to the file installed in the first package.
$ ls -l data/opt/debian-packaging-first-principles/plain-dependency
total 8
-rw-r--r-- 1 mike mike 77 Jul 12 12:50 dpfp-plain-dependency-success.txt
lrwxrwxrwx 1 mike mike 69 Jul 12 12:49 dpfp-simple-success.txt -> /opt/debian-packaging-first-principles/simple/dpfp-simple-success.txt
Unlike the impossible example, installing this package goes smoothly and inspecting the installed files will show the text file and symbolic link side by side.
$ sudo dpkg -i ./dpfp-plaindependency_0.1.0-1_all.deb
Selecting previously unselected package dpfp-plaindependency.
(Reading database ... 160683 files and directories currently installed.)
Preparing to unpack .../dpfp-plaindependency_0.1.0-1_all.deb ...
Unpacking dpfp-plaindependency (0.1.0-1) ...
Setting up dpfp-plaindependency (0.1.0-1) ...
Listing the files and their contents will show that we’re pulling in the file from the first, pre-installed, package too.
$ ls -l /opt/debian-packaging-first-principles/plain-dependency/
total 8
-rw-r--r-- 1 root root 77 Jul 12 12:50 dpfp-plain-dependency-success.txt
lrwxrwxrwx 1 root root 69 Jul 12 12:49 dpfp-simple-success.txt -> /opt/debian-packaging-first-principles/simple/dpfp-simple-success.txt
$ cat /opt/debian-packaging-first-principles/plain-dependency/dpfp-*.txt
Debian Packaging from First Principles
Plain Dependency
Success!
Debian Packaging from First Principles
Simple
Success!
Mutual Dependencies
Until now all of our dependencies have formed a simple tree, but now we’re going to build a pair of packages that depend on each other. One will not be able to be installed without the other.
We will first create an “a” package that depends on our “b” package.
Package: dpfp-mutualdependency-a
[...]
Depends: dpfp-mutualdependency-b
We will then create the counterpart “b” package that will depend on our first “a” package.
Package: dpfp-mutualdependency-b
[...]
Depends: dpfp-mutualdependency-a
Attempting to install only one of the mutually dependent packages will fail, referencing the other half of the pair.
$ sudo dpkg -i dpfp-mutualdependency-a_0.1.0-1_all.deb
[...]
dpkg: dependency problems prevent configuration of dpfp-mutualdependency-a:
dpfp-mutualdependency-a depends on dpfp-mutualdependency-b; however:
Package dpfp-mutualdependency-b is not installed.
[...]
Errors were encountered while processing:
dpfp-mutualdependency-a
Similarly, attempting to install only the second of the pair will return the same error.
$ sudo dpkg -i dpfp-mutualdependency-b_0.1.0-1_all.deb
[...]dpkg: dependency problems prevent configuration of dpfp-mutualdependency-b:
dpfp-mutualdependency-b depends on dpfp-mutualdependency-a; however:
Package dpfp-mutualdependency-a is not configured yet.
[...]
Errors were encountered while processing:
dpfp-mutualdependency-b
Installing both packages of the mutual pair at the same time will complete successfully because dpkg can resolve the dependencies.
$ sudo dpkg -i dpfp-mutualdependency-a_0.1.0-1_all.deb dpfp-mutualdependency-b_0.1.0-1_all.deb
Selecting previously unselected package dpfp-mutualdependency-a.
(Reading database ... 160686 files and directories currently installed.)
Preparing to unpack dpfp-mutualdependency-a_0.1.0-1_all.deb ...
Unpacking dpfp-mutualdependency-a (0.1.0-1) over (0.1.0-1) ...
Selecting previously unselected package dpfp-mutualdependency-b.
Preparing to unpack dpfp-mutualdependency-b_0.1.0-1_all.deb ...
Unpacking dpfp-mutualdependency-b (0.1.0-1) over (0.1.0-1) ...
Setting up dpfp-mutualdependency-b (0.1.0-1) ...
Setting up dpfp-mutualdependency-a (0.1.0-1) ...
In the first post in this series I got to grip with how deb packages are put together and now in this second post I understand how they’re connected to each other. Next time, I’m going to look at repackaging an existing piece of software for an architecture it wasn’t originally published for, and then try to host it on my own “apt” repository.
2024-09-24