第 9 章 More on packaging

目录

9.1. 软件包自定义
9.2. Customized debian/rules
9.3. Variables for debian/rules
9.4. 新上游版本
9.5. Manage patch queue with dquilt
9.6. 构建命令
9.7. Note on sbuild
9.8. Special build cases
9.9. 上传 orig.tar.gz
9.10. 跳过的上传
9.11. 错误报告

Let’s explore more fundamentals of Debian packaging.

All customization data for the Debian source package resides in the debian/ directory as presented in 第 5.7 节 “第三步:编辑模板文件””:

When these are not sufficient to make a good Debian package, -p1 patches of debian/patches/* files are deployed to modify the upstream source. These are applied in the sequence defined in the debian/patches/series file before building the package as presented in 第 5.9 节 “Step 3 (alternatives): Modification to the upstream source”.

You should address the root cause of the Debian packaging problem in the least invasive way possible. This approach will make the generated package more robust for future upgrades.

[注意]注意

If the patch addressing the root cause is useful to the upstream project, send it to the upstream maintainer.

Flexible customization of the 第 6.5 节 “debian/rules 文件” is achieved by adding appropriate override_dh_* targets and their rules.

When a special operation is required for a certain dh_foo command invoked by the dh command, its automatic execution can be overridden by adding the makefile target override_dh_foo in the debian/rules file.

构建的过程可以使用某些上游提供的接口进行定制化,如使用传递给标准的源代码构建系统的参数。这些构建系统包括但不限于:

  • configure,
  • Makefile,
  • python -m build, 或者
  • Build.PL

In this case, you should add the override_dh_auto_build target with dh_auto_build -- arguments. This ensures that arguments are passed to the build system after the default parameters that dh_auto_build usually passes.

[提示]提示

Avoid executing bare build system commands directly if they are supported by the dh_auto_build command.

参见:

某些对自定义 debian/rules 有用的变量定义可以在 /usr/share/dpkg/ 目录下的文件中找到。比较重要的包括:

pkg-info.mk
Set DEB_SOURCE, DEB_VERSION, DEB_VERSION_EPOCH_UPSTREAM, DEB_VERSION_UPSTREAM_REVISION, DEB_VERSION_UPSTREAM, and DEB_DISTRIBUTION variables obtained from dpkg-parsechangelog(1). (useful for backport support etc..)
vendor.mk
Set DEB_VENDOR and DEB_PARENT_VENDOR variables; and dpkg_vendor_derives_from macro obtained from dpkg-vendor(1). (useful for vendor support (Debian, Ubuntu, …​).)
architecture.mk
Set DEB_HOST_* and DEB_BUILD_* variables obtained from dpkg-architecture(1).
buildflags.mk
Set CFLAGS, CPPFLAGS, CXXFLAGS, OBJCFLAGS, OBJCXXFLAGS, GCJFLAGS, FFLAGS, FCFLAGS, and LDFLAGS build flags obtained from dpkg-buildflags(1).

For example, you can add an extra option to CONFIGURE_FLAGS for linux-any target architectures by adding the following to debian/rules:

DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
 ...
ifeq ($(DEB_HOST_ARCH_OS),linux)
CONFIGURE_FLAGS += --enable-wayland
endif

参见 第 10.10 节 “多体系结构””、dpkg-architecture(1) 和 dpkg-buildflags(1)。

When a new upstream release tarball foo-newvwesion.tar.gz is released, the Debian source package can be updated by invoking commands in the old source tree as:

$ uscan
 ... foo-newversion.tar.gz downloaded
$ uupdate -v newversion ../foo-newversion.tar.gz
  • The debian/watch file in the old source tree must be a valid one.
  • This make symlink ../foo_newvwesion.orig.tar.gz pointing to ../foo-newvwesion.tar.gz.
  • Files are extracted from ../foo-newvwesion.tar.gz to ../foo-newversion/
  • Files are copied from ../foo-oldversion/debian/ to ../foo-newvesion/debian/ .

After the above, you should refresh debian/patches/* files (see 第 9.5 节 “Manage patch queue with dquilt”) and update debian/changelog with the dch(1) command.

When debian uupdate is specified at the end of line in the debian/watch file, uscan automatically executes uupdate(1) after downloading the tarball.

You can add, drop, and refresh debian/patches/* files with dquilt to manage patch queue.

  • Add a new patch debian/patches/bugname.patch recording the upstream source modification on the file buggy_file as:

    $ dquilt push -a
    $ dquilt new bugname.patch
    $ dquilt add buggy_file
    $ vim buggy_file
      ...
    $ dquilt refresh
    $ dquilt header -e
    $ dquilt pop -a
  • Drop (== disable) an existing patch

    • Comment out pertinent line in debian/patches/series
    • Erase the patch itself (optional)
  • Refresh debian/patches/* files to make dpkg-source -b work as expected after updating a Debian package to the new upstream release.

     $ uscan; uupdate  # updating to the new upstream release
     $ while dquilt push; do dquilt refresh ; done
     $ dquilt pop -a
    • If conflicts are encountered with dquilt push in the above, resolve them and run dquilt refresh manually for each of them.

Here is a recap of popular low level package build commands. There are many ways to do the same thing.

  • dpkg-buildpackage = 软件包打包工具的核心
  • debuild = dpkg-buildpackage + lintian (在清理后的环境变量下构建)
  • schroot = core of the Debian chroot environment tool
  • sbuild = dpkg-buildpackage on custom schroot (build in the chroot)

The sbuild(1) command is a wrapper script of dpkg-buildpackage which builds Debian binary packages in a chroot environment managed by the schroot(1) command. For example, building for Debian unstable suite can be done as:

 $ sudo sbuild -d unstable

In schroot(1) terminology, this builds a Debian package in a clean ephemeral chroot chroot:unstable-amd64-sbuild started as a copy of the clean minimal persistent chroot source:unstable-amd64-sbuild.

This build environment was set up as described in 第 4.6 节 “sbuild 设置” with sbuild-debian-developer-setup -s unstable which essentially did the following:

 $ sudo mkdir -p /srv/chroot/dist-amd64-sbuild
 $ sudo sbuild-createchroot unstable /srv/chroot/unstable-amd64-sbuild http://deb.debian.org/debian
 $ sudo usermod -a -G sbuild <your_user_name>
 $ sudo newgrp -

The schroot(1) configuration for unstable-amd64-sbuild was generated at /etc/schroot/chroot.d/unstable-amd64-sbuild.$suffix :

[unstable-amd64-sbuild]
description=Debian sid/amd64 autobuilder
groups=root,sbuild
root-groups=root,sbuild
profile=sbuild
type=directory
directory=/srv/chroot/unstable-amd64-sbuild
union-type=overlay

其中:

  • The profile defined in the /etc/schroot/sbuild/ directory is used to setup the chroot environment.
  • /srv/chroot/unstable-amd64-sbuild directory holds the chroot filesystem.
  • /etc/sbuild/unstable-amd64-sbuild is symlinked to /srv/chroot/unstable-amd64-sbuild .

You can update this source chroot source:unstable-amd64-sbuild by:

 $ sudo sbuild-update -udcar unstable

You can log into this source chroot source:unstable-amd64-sbuild by:

 $ sudo sbuild-shell unstable
[提示]提示

If your source chroot filesystem is missing packages such as libeatmydata1, ccache, and lintian for your needs, you may want to install these by logging into it.

The orig.tar.gz file may need to be uploaded for a Debian revision other than 0 or 1 under some exceptional cases (e.g., for a security upload).

When an essential package becomes a non-essential one (e.g., adduser), you need to remove it manually from the existing chroot environment for its use by piuparts.

当您第一次向归档上传软件包时,您还需要包含原始的 orig.tar.gz 源码。

如果 Debian 修订码是 1 或者 0,这都是默认的。否则,您必须使用带有 -sa 选项的 dpkg-buildpackage 命令。

  • dpkg-buildpackage -sa
  • debuild -sa
  • sbuild
  • 对于 gbp buildpackage,请编辑 ~/.gbp.conf 文件。
[提示]提示

另一方面,-sd 选项将会强制排除原始的 orig.tar.gz 源码。

[提示]提示

添加至 ~/.bashrc 文件。

如果当跳过上传时,你在 debian/changelog 中创建了多个条目,你必须创建一个包含自上次上传以来所有变更的 debian/changelog 文件。这可以通过指定 dpkg-buildpackage 选项 -v 以及上次上传的版本号,比如 1.2 来完成。

  • dpkg-buildpackage -v1.2
  • debuild -v1.2
  • sbuild --debbuildopts -v1.2
  • 对于 gbp buildpackage,请编辑 ~/.gbp.conf 文件。

The reportbug(1) command used for the bug report of binarypackage can be customized by the files in usr/share/bug/binarypackage/.

dh_bugfiles 命令将安装以下位于 debian/ 目录中的的模板文件。

  • debian/binarypackage.bug-controlusr/share/bug/binarypackage/control

    • 该文件包含诸如重定向错误报告至其它软件包的一些指导性内容。
  • debian/binarypackage.bug-presubjusr/share/bug/binarypackage/presubj

    • 该文件的内容将由 reportbug 命令向用户展示。
  • debian/binarypackage.bug-scriptusr/share/bug/binarypackage or usr/share/bug/binarypackage/script

    • reportbug 命令运行此脚本以生成错误报告的模板文件。

See dh_bugfiles(1) and reportbug’s Features for Developers (README.developers)”

[提示]提示

如果您总是需要提醒提交报告的用户某些注意事项或询问他们某些问题,使用这些文件可以将这个过程自动化。