changelog shortlog tags changeset files revisions annotate raw

chapters/creating_debian_packages_from_cpan.tex

changeset 2: 85f6b78ebb5d
parent:36c3c1f99680
author: Patrik Willard <wildcard_at_padowi_dot_se>
date: Tue May 18 15:44:04 2010 +0200 (24 months ago)
permissions: -rw-r--r--
description: added license
1% Copyright 2009 FSCONS, Superflex and the individual authors.
2% This entire book and all its source files is licenced under Creative Commons Attribution-ShareAlike 2.5
3\begin{savequote}
4 \qauthor{\LARGE{Jeremiah Foster}}
5\end{savequote}
6\chapter{Creating Debian packages from CPAN}
7\label{c:debs_cpan}
8
9CPAN is a well-known and useful archive of Perl modules, a pearl in the Perl
10world. While it serves many Perl developers and users, it cannot by its very
11nature cater for further distribution because it does not know what form that
12distribution has to take. In other words, how is cpan supposed to know if it
13needs to morph into a specif\hbox{}ic format to allow a module to be installed on a
14specif\hbox{}ic platform? It cannot and should not, it should provide instead a stable
15API and a distributed database allowing for easy packaging ``downstream'', which
16is what it does. One can install from source if one prefers, or with the cpan
17and cpanp tools, but sometimes you need or want a more complete and f\hbox{}lexible
18system for installing software.
19
20As we move downstream, we get closer to the user and the user's system. Hic sunt
21dracones, you need to be pretty careful about how and what you install lest you
22create instability and bugs. Cpan tries to handle installation elegantly by
23installing dependencies with whatever module you are installing. This is a
24``Good Thing\texttrademark'', it helps the end-user immeasurably and helps to
25avoid ``dependency hell''; a painful state which describes the situation of
26having some of your needed software installed, but not all of it.
27
28Since a cpan module is agnostic to its f\hbox{}inal destination and tries to be as
29cross-platform as possible, it will not know about the specif\hbox{}ic peculiarities of
30the operating system upon which it is to reside. In fact, one might argue a good
31deal of cpants is directed at this problem, determining the quirks of the OS.
32Workarounds include the inclusion of multiple operating-system-specif\hbox{}ic tools
33and functions, yuck.
34
35A better solution might be ``package management'' which allows for a cpan module
36to be wrapped in a way that allows for simpler installation. This is of course
37operating system specif\hbox{}ic and rightly so, the OS needs to determine how to
38install, where to install, and what. So cpan can just do its thing while the OS
39communicates directly with cpan, gets the required module(s), any Perl
40dependencies, and does the installation work. The OS then checks to see if there
41are operating system required dependencies above and beyond the Perl
42dependencies, satisf\hbox{}ies those dependencies, resulting in a single call to the
43package manager to install software without having to search the internet for
44some arbitrary .so f\hbox{}ile.
45
46This article aims to explain this packaging process for Debian and Debian
47derived operating systems such as Ubuntu, allowing for Perl modules to be
48installed as debs and even submitted to Debian itself. The Debian system has
49many users, receives security notif\hbox{}ications, is known for its stability, and
50gets regular updates. These are things your Perl modules will automatically get
51as well when you submit them to Debian.
52
53There is a dedicated group of Debian hackers, both ``Debian Developers'' and
54non-developers, who maintain Perl modules in Debian. I am one of those who works
55on the Debian-Perl team\cite{debs_cpan-debian_perl_team} and would like to
56describe the development of debs from cpan, including some of its gory details,
57so that others can be familiar with ``best practices'' of packaging software for
58Debian.
59
60Let us begin with a tool called dh-make-perl, shall we? Dh-make-perl (the dh
61stands for Debian helper) is a wrapper around the cpan tool, plus a whole lot
62more. We call it the same way as we would call cpan, with a module name. It then
63goes to cpan for the source of our deb because the goal of a deb is to have the
64source code separate and pristine. Debian makes no changes to the upstream
65source for packaging. Occasionally someone in Debian might patch the source to
66f\hbox{}ix a bug, but in Debian-Perl we try to use patch to patch things and always try
67to pass our patch upstream at least into RT, Perl's bug tracker.
68
69Choosing something to package is actually quite important. I will choose
70Test::F\hbox{}ile because I f\hbox{}ind it useful and have some familiarity with it - two
71things one needs to generate the interest and motivation when there are bug
72reports or new features. Packaging is actually considerable work over time, a
73stale package is both a potential security risk and quickly forgotten.
74
75Now we use our f\hbox{}irst tool, the powerful dh-make-perl. I will show the call to
76dh-make-perl and then go through it a bit since I am going to pass a lot of
77arguments just to show some features.
78
79\lstset{
80 basicstyle=\footnotesize\ttfamily,
81 commentstyle=\textit,
82 %numbers=left,
83 %numberstyle=\tiny,
84 %stepnumber=1,
85 %numbersep=5pt,
86 breaklines=true,
87 tabsize=4,
88 keywordstyle=\color{red},
89 frame=single,
90 showspaces=false,
91 showtabs=false,
92 xleftmargin=15pt,
93 framexleftmargin=9pt,
94 framexrightmargin=9pt,
95 %backgroundcolor=\color{lightgray},
96 showstringspaces=false
97}
98\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dh-make-perl,caption=dh-make-perl command]{}
99dh-make-perl --cpan Test::File --desc "Test file attributes with perl." --arch all --version 1.25 -e jeremiah@jeremiahfoster.com --dh 7 --requiredeps --build
100\end{lstlisting}
101
102We call dh-make-perl with a bunch of parameters. This of course is not
103necessary, you can make your call much smaller, but I want to show some of these
104parameters because they make life a little easier and you may want to use them.
105Of course the canonical source of dh-make-perl parameters and functions is in
106the man page for dh-make-perl, this is good to check on occasion since it has
107been getting updated recently\cite{debs_cpan-git_dh_make_perl}.
108
109The f\hbox{}irst parameter, or really argument to dh-make-perl, is the {-}{-}cpan f\hbox{}lag
110which tells dh-make-perl to go and get the module from cpan as opposed to
111f\hbox{}inding it locally. From the man page: ``If neither {-}{-}cpan nor a directory
112is given as argument, dh-make-perl tries to create a Perl package from the data
113in .'' i.e. the current directory. So if you have a module you want to install
114locally or for some reason do not want to push up to Debian, you can create
115local debs for your own local machines or mirror, no need to push them
116downstream as it were.
117
118Next we give the name of our module in the same way we would if we were using
119cpan, i.e. Foo::Bar. The {-}{-}desc switch tells dh-make-perl what to use for
120Debian's short description and the {-}{-}arch f\hbox{}lag is for the architecture. Here
121we are using all because perl works on all the architectures that Debian
122of\hbox{}f\hbox{}icially (and unof\hbox{}f\hbox{}icially) supports.
123
124Shockingly enough the {-}{-}version f\hbox{}lag provides a way to inform dh-make-perl
125about the version of the package we are packaging, so this is the current
126version of Test::F\hbox{}ile; -e is the email address f\hbox{}lag, it wants an email address
127after it; {-}{-}dh is a call to debhelper itself and after {-}{-}dh you have to
128specify the version of debhelper you want to use. This is a little tricky
129because dif\hbox{}ferent versions of debhelper create dif\hbox{}ferent artefacts, specif\hbox{}ically
130dif\hbox{}ferent debian/rules f\hbox{}iles. So you want most likely to use version 7 for
131debhelper. To paraphrase the dh-make-perl man page, {-}{-}dh will set desired
132the debhelper version. If ``ver'' is 7, the generated debian/rules f\hbox{}ile is
133minimalist, using the auto-mode of debhelper. This minimalist version is what
134you want, unless you are going to package an XS module or need to do some crazy
135stuf\hbox{}f at build time.
136
137Fortunately we do not have to mess about with our debian/rules f\hbox{}ile, so I am
138going to continue discussing the rest of the arguments to dh-make-perl, but I
139want to say that there is a great deal to discuss regarding debian/rules and you
140would do well to consider reading about it in the Debian developers'
141documentation in places like the New Maintainer's
142Guide\cite{debs_cpan-new_maint_guide-rules}. If you are reading this in front of
143a Debian command line, you can simply do an ``aptitude install maint-guide'' to
144get the documentation.
145
146The {-}{-}requiredeps f\hbox{}lag tells dh-make-perl to require Perl dependencies, that
147is to say, if we do not f\hbox{}ind all the modules needed to build, we should fail to
148build our deb. This is really good because it makes your deb package more
149portable and all the Perl module dependencies will get installed when you
150install your package on another machine, very convenient. For this call to work
151you need to have apt-f\hbox{}ile installed on the machine on which you are building the
152package. Apt-f\hbox{}ile is an excellent tool, written in Perl (of course!). It allows
153you to search for f\hbox{}iles in Debian packages, even packages that are not installed
154on your system. This means that apt-f\hbox{}ile is really the canonical tool to f\hbox{}ind
155things in Debian or Ubuntu packages. A quick example: say we wanted to install
156libtest-more-perl and we called aptitude to install it thusly, ``aptitude
157install libtest-more-perl''. Aptitude says:
158
159\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:apt-install,caption=aptitude install libtest-more-perl output]{}
160E: Unable to locate package libtest-more-perl
161\end{lstlisting}
162
163But we are certain that this fundamental perl module is in Debian! Haven't we
164seen Test::More output in fact? Indeed we have, but this module does not exist
165on its own. Debian has included it with the package perl-modules because it is
166such a fundamental tool, and so much else in Debian requires it. So looking for
167it with ``dpkg -L libtest-more-perl'' will produce these rather unhelpful
168results:
169
170\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-search,caption=dpkg -L libtest-more-perl output]{}
171Package ``libtest-more-perl'' is not installed.
172\end{lstlisting}
173
174But in fact, when we search with ``apt-f\hbox{}ile search Test/More.pm'' (which is the
175format we need to specify since we are looking at the f\hbox{}ile system) we will f\hbox{}ind
176that apt-f\hbox{}ile f\hbox{}inds it for us:
177
178\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:apt-file,caption=apt-file search Test/More.pm output]{}
179perl-modules: /usr/share/perl/5.10.0/Test/More.pm
180\end{lstlisting}
181
182This output tells us that the f\hbox{}ile Test/More.pm is under /usr/share/perl/5.10.0
183and it is in the Debian package perl-modules. This is a handy and reliable way
184to f\hbox{}ind if the Perl module you are looking for is already packaged in Debian.
185All of these commands were issued on a Debian testing system.
186
187F\hbox{}inally we pass {-}{-}build which ``builds only a binary package (by calling
188`fakeroot debian/rules binary') and does not sign the package. It is meant for a
189quick local install of a package, not for creating a package ready for
190submission to the Debian archive.'' So says the man page for dh-make-perl. I
191like to build the package with dh-make-perl because then certain build problems
192come to the fore sooner. It is not a requirement to build the package with
193dh-make-perl however.
194
195Once we have run dh-make-perl, we watch all sorts of interesting output f\hbox{}ly by,
196like output from cpan, the test suite of our module, etc. The debhelper build
197process takes over after cpan has worked its magic and we get a f\hbox{}inished two
198f\hbox{}iles and a directory when we are done. They are:
199
200\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dh-make-perl-output,caption=dh-make-perl output]{}
201File: libtest-file-perl_1.25_all.deb
202File: libtest-file-perl_1.25.orig.tar.gz
203Dir: Test-File-1.25
204\end{lstlisting}
205
206
207
208\section{The anatomy of a package}
209\label{s:debs_cpan:anatomy}
210
211You would be tempted to say ``Well I have built my deb, I'm done!'' Doing a dpkg
212{-}{-}contents libtest-f\hbox{}ile-perl\_1.25\_all.deb ought to show this output on our new
213deb:
214
215\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-contents,caption=dpkg {-}{-}contents libtest-file-perl output]{}
216drwxr-xr-x root/root 0 2009-02-09 15:39 ./
217drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/
218drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/
219drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/man/
220drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/man/man3/
221-rw-r--r-- root/root 4142 2009-02-09 15:39 ./usr/share/man/man3/Test::File.3.gz
222drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/perl5/
223drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/perl5/Test/
224-rw-r--r-- root/root 27027 2008-06-10 19:59 ./usr/share/perl5/Test/File.pm
225drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/doc/
226drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/
227-rw-r--r-- root/root 69 2007-02-09 02:30 ./usr/share/doc/libtest-file-perl/README
228-rw-r--r-- root/root 1476 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/copyright
229drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/examples/
230-rw-r--r-- root/root 69 2007-02-09 02:30 ./usr/share/doc/libtest-file-perl/examples/README
231-rw-r--r-- root/root 164 2009-02-09 15:39 ./usr/share/doc/libtest-file-perl/changelog.gz
232drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/
233drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/
234drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/auto/
235drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/auto/Test/
236drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl5/auto/Test/File/
237-rw-r--r-- root/root 195 2009-02-09 15:39 ./usr/lib/perl5/auto/Test/File/.packlist
238drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl/
239drwxr-xr-x root/root 0 2009-02-09 15:39 ./usr/lib/perl/5.10/
240-rw-r--r-- root/root 214 2009-02-09 15:39 ./usr/lib/perl/5.10/perllocal.pod
241\end{lstlisting}
242
243But in fact we are not done, we need to build the deb with dpkg-buildpackage and
244we need to modify some of the f\hbox{}iles in the Debian directory. F\hbox{}irst we will start
245by modifying the f\hbox{}iles in the Debian directory to make sure we have a proper
246package. The f\hbox{}irst thing we need to do is to change the name of our directory.
247Debian has a requirement that says the package name has to be lowercase which
248means that our directory has to be lower case. So we move Test-F\hbox{}ile to
249libtest-f\hbox{}ile-perl-1.25. This format is the standard format for Debian Perl
250packages. While one might say it is not the most beautiful format, it has its
251strengths. Those strengths are that the format informs the user it is a library
252package, part of a larger system which might require dependencies. It has the
253suf\hbox{}f\hbox{}ix -perl which indicates that it is a Perl library. There are a few modules
254in Debian which are not labelled this way, and there is no absolute law saying
255you have to call your module this way, but if you do not you are in fact doing
256the user a grave disservice, because anyone who is used to Debian or Debian
257derivatives will search for a module as libfoo-bar-perl and they will not f\hbox{}ind
258your module if it is not so labelled.
259
260So once we have moved Test-F\hbox{}ile-1.25 to libtest-f\hbox{}ile-perl-1.25 we will change
261into that directory and take a look around. We f\hbox{}ind that it is just like the
262untarred module from CPAN only with the addition of a Debian directory. We will
263take a closer look at the Debian directory now which is at the heart of
264packaging. According to the New Maintainer's
265guide\cite{debs_cpan-new_maint_guide} ``The most important of them are
266`control', `changelog', `copyright' and `rules', which are required for all
267packages.'' Let us start by taking a look at the control f\hbox{}ile:
268
269\lstset{
270 basicstyle=\footnotesize\ttfamily,
271 commentstyle=\textit,
272 numbers=left,
273 numberstyle=\tiny,
274 stepnumber=1,
275 numbersep=5pt,
276 breaklines=true,
277 tabsize=4,
278 keywordstyle=\color{red},
279 frame=single,
280 showspaces=false,
281 showtabs=false,
282 xleftmargin=15pt,
283 framexleftmargin=9pt,
284 framexrightmargin=9pt,
285 %backgroundcolor=\color{lightgray},
286 showstringspaces=false
287}
288
289\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:control-file,caption=control]{}
290Source: libtest-file-perl
291Section: perl
292Priority: optional
293Build-Depends: debhelper (>= 7)
294Build-Depends-Indep: perl (>= 5.6.0-12), libtest-manifest-perl (>= 1.14)
295Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
296Uploaders: Jeremiah C. Foster <jeremiah@jeremiahfoster.com>
297Standards-Version: 3.8.0
298Homepage: http://search.cpan.org/dist/Test-File/
299Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libtest-file-perl/
300Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libtest-file-perl/
301
302Package: libtest-file-perl
303Architecture: all
304Depends: ${perl:Depends}, ${misc:Depends}, libtest-manifest-perl (>= 1.14)
305Description: Test file attributes with Perl.
306 Test::Files provides a collection of test utilities for file attributes.
307 .
308 Some file attributes depend on the owner of the process testing the file in
309 the same way the file test operators do. For instance, root (or super-user or
310 Administrator) may always be able to read files no matter the permissions.
311 .
312 Some attributes don't make sense outside of Unix, either, so some tests
313 automatically skip if they think they won't work on the platform. If you have
314 a way to make these functions work on Windows, for instance, please send me a
315 patch. :)
316 .
317 This description was "automagically" extracted from the module by dh-make-perl.
318\end{lstlisting}
319
320I will move quickly through the f\hbox{}irst lines of the control f\hbox{}ile but I would like
321to point out lines 4 and 5 where Build-Depends and Build-Depends-Indep are
322def\hbox{}ined. This is where the magic at the core of aptitude lies, and why the apt
323system is so powerful. Here we def\hbox{}ine the relationships between packages in the
324operating system and within Perl which will be satisf\hbox{}ied at build time. These
325dependencies were calculated by dh-make-perl but there are other mechanisms to
326do this as well and sometimes we will even need to do this by hand. Looking in
327the source directory for the package and even the META.yml and Makef\hbox{}ile.PL can
328reveal dependencies that might otherwise be missed. Usually dh-make-perl gets it
329right however and this is not necessary.
330
331In our Build-Depends line we are saying we depend on debhelper and we will not
332be able to build our package unless this dependency is satisf\hbox{}ied, it is an
333absolute dependency. The apt system will check automatically for dependencies on
334your dependencies, so you only specify the dependencies you need for your
335package, you do not have to rummage around to f\hbox{}ind out what they depend on.
336Build-Depends is only for dependencies required to build a binary package on
337your architecture, it is not a complete selection of build-time relationships.
338In our package, we also need Build-Depends-Indep which def\hbox{}ines other packages
339that our package will need to run, not just to build.
340
341This is fairly esoteric stuf\hbox{}f, and Perl largely abstracts the ``building'' of
342binaries away from the Perl programmer in the interest of simplicity and ease of
343use. You can dig into this stuf\hbox{}f if you want, there is much more to learn about
344building Perl both on the Perl side and on the Debian side, but since it is a
345rather large subject area I am going to gloss over the really hairy details and
346refer you to the Debian policy\cite{debs_cpan-debian_policy} and your own Google
347prowess to get more info than that I have presented here.
348
349Most of the other stuf\hbox{}f in the debian/control f\hbox{}ile is pretty self-explanatory;
350resources for the source code, who was responsible for the package uploading,
351etc. I would like to direct you to the last line where we see some packaging
352boilerplate which ought to be removed, i.e. line 28.
353
354If we now turn our attention to debian/copyright we can see the power of Free
355Software and copyright. The Debian Free Software Guidelines require that a
356copyright be assigned so that a licence can be enforced. Perl is under the
357Artistic licence, a licence that has won important legal victories in the United
358States, and also under the GPL. This dual licensing is ef\hbox{}fective but only when
359there is a copyright specif\hbox{}ied and many Perl hackers forget to do this. I would
360like to encourage you to document your copyright, even if you received the
361copyright by default when you authored new code, this makes it easier to package
362your software. Here is what our copyright f\hbox{}ile looks like:
363
364\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:copyright-file,caption=copyright]{}
365Format-Specification:
366 http://wiki.debian.org/Proposals/CopyrightFormat?action=recall&rev=196
367Upstream-Maintainer: brian d foy <bdfoy@cpan.org>
368Upstream-Source: http://search.cpan.org/dist/Test-File/
369Upstream-Name: Test-File
370Disclaimer: This copyright info was automatically extracted
371 from the Perl module. It may not be accurate, so you better
372 check the module sources in order to ensure the module for its
373 inclusion in Debian or for general legal information. Please,
374 if licensing information is incorrectly generated, file a bug
375 on dh-make-perl.
376
377Files: *
378Copyright: brian d foy <bdfoy@cpan.org>
379License-Alias: Perl
380License: Artistic | GPL-1+
381
382Filend: debian/*
383Copyright: 2009, Jeremiah C. Foster <jeremiah@jeremiahfoster.com>
384Licence: Artistic | GPL-1+
385
386Licence: Artistic
387 This program is free software; you can redistribute it and/or modify
388 it under the terms of the Artistic Licence, which comes with Perl.
389 On Debian GNU/Linux systems, the complete text of the Artistic Licence
390 can be found in `/usr/share/common-licences/Artistic'
391
392Licence: GPL-1+
393 This program is free software; you can redistribute it and/or modify
394 it under the terms of the GNU General Public Licence as published by
395 the Free Software Foundation; either version 1, or (at your option)
396 any later version.
397 On Debian GNU/Linux systems, the complete text of the GNU General
398 Public Licence can be found in `/usr/share/common-licences/GPL'
399\end{lstlisting}
400
401This f\hbox{}ile is pretty straight-forward. We will remove the boilerplate from lines
4026 through 11 and then f\hbox{}ill in the exact date of the copyright for the software,
403in this case we'll have to go to cpan and f\hbox{}ind out that it is 2008, but after
404that we are done with the copyright f\hbox{}ile.
405
406The compat and watch f\hbox{}iles play minor roles in our package building drama. The
407watch f\hbox{}ile is a tool to check to see if there have been any new releases, it
408gets used by a tool called uscan which allows one to update a new cpan module
409into an existing Debian package quickly. The compat f\hbox{}ile is merely a
410``compatibility'' number for some of the other Debian tools, I will leave that
411to you to explore.
412
413
414
415
416\section{Building the package with dpkg-buildpackage}
417\label{s:debs_cpan:building}
418
419Now it is time to look at the main build tool for building Perl debs,
420dpkg-buildpackage. There are plenty of build tools in Debian and there seems to
421be a new one every month. For example there is now one called git-buildpackage
422and for all I know it may be great. I like dpkg-buildpackage so that is what I
423am going to tell you about.
424
425As with every build tool there are ten thousand options, but I am just going to
426describe the juicy parts. I call dpkg-buildpackage like this:
427
428\lstset{
429 basicstyle=\footnotesize\ttfamily,
430 commentstyle=\textit,
431 numbers=none,
432 %numberstyle=\tiny,
433 %stepnumber=1,
434 %numbersep=5pt,
435 breaklines=true,
436 tabsize=4,
437 keywordstyle=\color{red},
438 frame=single,
439 showspaces=false,
440 showtabs=false,
441 xleftmargin=15pt,
442 framexleftmargin=9pt,
443 framexrightmargin=9pt,
444 %backgroundcolor=\color{lightgray},
445 showstringspaces=false
446}
447\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-buildpackage,caption=dpkg-buildpackage command]{}
448dpkg-buildpackage -rfakeroot -D -kjeremiah@jeremiahfoster.com
449\end{lstlisting}
450
451What we have right after the call is the f\hbox{}lag -r with the word fakeroot right
452after it, that is the command used to gain root. The -D is for checking
453conf\hbox{}licts and dependencies which I highly recommend although you can do it
454without checking dependencies but that would most likely not be portable.
455F\hbox{}inally, -k and my email address is the key I use to sign the package.
456
457This tool is a Perl tool, of course, and if you look at the source you will see
458the name Ian Jackson in the copyright section. Ian Jackson is the guy who
459started Debian, he is in fact the Ian of Debian with his wife Debra being the
460deb part. You can also see that this f\hbox{}ile is not very well documented, no pod
461for example, which is a shame. There are other modules also being pulled into
462this one, modules like dpkg and dpkg::Version which is useful for checking
463version numbers of packages. Why won't you f\hbox{}ind these packages on cpan? Good
464question. It is one of my long term goals to expose all these tools to cpan and
465get the public to examine them and help with development and documentation. The
466developers in Debian seem to think these tools are only relatively interesting
467to a Debian developer, which may be true, but I suspect it is valuable to have
468tools that work on such a fundamental level with Debian packages since Debian is
469so widespread. Then people can either use them themselves or even devise tools
470on top of them that might be useful, like the cpan2dist tool in cpanplus. I can
471also see these tools as potentially being useful for a distribution agnostic
472linux packaging program. In any case, I think Debian should follow the best
473practices of the Perl community either way and make the tools available and I
474intend to do that work if someone does not beat me to it.
475
476In the meantime, what happened when we built our package? Since we passed -D to
477check dependencies, dpkg-buildpackage called dpkg-checkbuilddeps and found that
478we cannot build our package because we are missing a dependency; Test::Manifest.
479You can run dpkg-checkbuilddeps separately and this is the output:
480
481\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:dpkg-checkbuilddeps,caption=dpkg-checkbuilddeps output]{}
482dpkg-checkbuilddeps: Unmet build dependencies: libtest-manifest-perl (>= 1.14)
483\end{lstlisting}
484
485The above line tells us that the Perl module Test::Manifest needs to be included
486for and that it already exists in Debian as the package libtest-manifest-perl.
487Marvel at the power of the apt system! It saved us a journey to dependency hell.
488We simply install libtest-manifest-perl and try to build again\ldots
489
490This time, success! Dpkg-buildpackage will ask me for my key passphrase, which I
491give it, and it signs the package for me. Now if we look in our dir we have:
492
493\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:post-dpkg-checkbuilddeps,caption=Directory after successful dpkg-checkbuilddeps run]{}
494libtest-file-perl-1.25
495libtest-file-perl_1.25-1_all.deb
496libtest-file-perl_1.25-1.dsc
497libtest-file-perl_1.25-1_i386.changes
498libtest-file-perl_1.25-1.tar.gz
499\end{lstlisting}
500
501Hooray! We have our deb, signed and sealed. You can install it now with dpkg -i
502libtest-f\hbox{}ile-perl\_1.25-1\_all.deb but before we pass it out far and wide, let
503us take one f\hbox{}inal step and build it in a ``clean room'' or a minimal Debian
504install. This we can use as a baseline and assume that if it builds and installs
505here it can build and install anywhere. To do this we are going to use pbuilder
506which is a ``personal package builder''. It creates a chroot, downloads a
507minimal Debian install, adds your package and any dependencies and builds a deb
508for you. If that works, you can be reasonably sure it will work out in the
509greater wide world of the Debian installed base.
510
511Here is the call:
512
513
514\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-1,caption=pbuilder command]{}
515sudo pbuilder build libtest-file-perl_1.25-1.dsc
516\end{lstlisting}
517
518I will go through an arbitrary selection of pbuilder's output:
519
520\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-1,caption=pbuilder output]{}
521I: using fakeroot in build.
522Current time: Wed Feb 11 16:22:37 CET 2009
523pbuilder-time-stamp: 1234365757
524Building the build Environment
525 -> extracting base tarball [/var/cache/pbuilder/base.tgz]
526\end{lstlisting}
527
528The base tarball gets unpackaged to create the build environment (f\hbox{}igure
529\ref{cl:debs_cpan:pbuilder-1}).
530
531\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-2,caption=pbuilder process continued]{}
532Get:1 http://ftp.debian.org sid Release.gpg [189B]
533Get:2 http://ftp.debian.org sid Release [80.6kB]
534Get:3 http://ftp.debian.org sid/main Packages/DiffIndex [2038B]
535Get:4 http://ftp.debian.org sid/main 2009-02-10-2012.30.pdiff [5047B]
536\end{lstlisting}
537
538Here (f\hbox{}igure \ref{cl:debs_cpan:pbuilder-2}) pbuilder updates the base Debian
539install with the latest dif\hbox{}fs of packages so your clean room is up-to-date. You
540can update it manually as well and change the distribution you want to use, I
541prefer to use testing but you might want to use stable.
542
543\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-3,caption=pbuilder process continued]{}
544Copying source file
545 -> copying [libtest-file-perl_1.25-1.dsc]
546 -> copying [./libtest-file-perl_1.25-1.tar.gz]
547Extracting source
548\end{lstlisting}
549
550pbuilder pulls in our source for the package (f\hbox{}igure
551\ref{cl:debs_cpan:pbuilder-3}).
552
553\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-4,caption=dpkg-buildpackage takes over]{}
554dpkg-buildpackage: source package libtest-file-perl
555dpkg-buildpackage: source version 1.25-1
556dpkg-buildpackage: source changed by Jeremiah C. Foster <jeremiah@jeremiahfoster.com>
557dpkg-buildpackage: host architecture i386
558\end{lstlisting}
559
560dpkg-buildpackage takes over and does its stuf\hbox{}f.
561
562\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:pbuilder-5,caption=Test failure!]{}
563Test::Manifest::test_harness found [t/load.t t/pod.t t/pod_coverage.t t/normalize.t t/test_files.t t/owner.t t/rt/30346.t]
564t/load............ok
565t/pod.............skipped
566 all skipped: Test::Pod 1.00 required for testing POD
567\end{lstlisting}
568
569Aha! I missed a useful tool. Since Test::Pod gets called while running tests, I
570should add it to Build-Depends-Indep in the debian/control f\hbox{}ile to get these
571tests to run. Of course it builds without it, but it is better to run all our
572tests as the original developer envisioned. Once I add that module and the
573module Test::Pod::Coverage which is also used in tests to the debian/control
574f\hbox{}ile, all the tests pass and the package gets built. This is a pretty good
575indication that this package will build on someone else's machine.
576
577To conf\hbox{}irm that we are in accordance with policy we ought to run the package
578through lintian, the Debian policy checker. I run it with the -i and -I f\hbox{}lags
579which provides much more verbose output, it has a {-}{-}pedantic switch as well.
580We might run it against our deb like this:
581
582\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:lintian-command,caption=lintian command]{}
583lintian -i -I libtest-file-perl_1.25-1_all.deb
584\end{lstlisting}
585
586And get output like this:
587
588\begin{lstlisting}[frame=trbl,label=cl:debs_cpan:lintian-output,caption=lintian output]{}
589E: libtest-file-perl: perl-module-in-core-directory usr/lib/perl/5.10/
590N:
591N: Packaged modules must not be installed into the core Perl directories as
592N: those directories change with each upstream Perl revision. The vendor
593N: directories are provided for this purpose.
594N:
595N: Refer to Debian Perl Policy section 3.1 (Site Directories) for details.
596N:
597N: Severity: important, Certainty: certain
598\end{lstlisting}\cite{debs_cpan-debian_perl_policy}
599
600These warnings are good to have, were you to submit your package for inclusion
601in Debian the expectation is that your package is ``lintian clean'' which means
602without warnings from lintian. Now we can submit this to Debian or put it in our
603own personal deb repo with conf\hbox{}idence.
604
605The package goes through some automatic building on a variety of architectures,
606sits in a queue for about ten days, then gets put into the Debian ``testing''
607distro. Anyone who has Debian testing sources in the /etc/apt/sources.list will
608now be able to install it just by calling aptitude. Now your package or software
609is available to millions of users. Congratulations.