第 7 章 检查软件包中的错误

目录

7.1. Suspicious changes
7.2. Verifying a package's installation
7.3. Verifying a package's maintainer scripts
7.4. Using lintian
7.5. The debc command
7.6. The debdiff command
7.7. The interdiff command
7.8. The mc command

There are some techniques you should know for checking a package for errors before uploading it to the public archives.

It's also a good idea to carry out testing on a machine other than your own. You must watch closely for any warnings or errors for all the tests described here.

7.1. Suspicious changes

If you find a new autogenerated patch file such as debian-changes-* in the debian/patches directory after building your non-native Debian package in 3.0 (quilt) format, chances are you changed some files by accident or the build script modified the upstream source. If it is your mistake, fix it. If it is caused by the build script, fix the root cause with dh-autoreconf as in 第 4.4.3 节 “定制 rules 文件” or work around it with source/options as in 第 5.25 节 “source/options.

7.2. Verifying a package's installation

You must test your package for whether it installs without problem. The debi(1) command helps you to test installing all the generated binary packages.

$ sudo debi gentoo_0.9.12-1_i386.changes

To prevent installation problem on different systems, you must make sure that there are no filenames conflicting with other existing packages, using the Contents-i386 file downloaded from the Debian archive. The apt-file command may be handy for this task. If there are collisions, please take action to avoid this real problem, whether by renaming the file, moving a common file to a separate package that multiple packages can depend on, using the alternatives mechanism (see update-alternatives(1)) in coordination with the maintainers of other affected packages, or declaring a Conflicts relationship in the debian/control file.

7.3. Verifying a package's maintainer scripts

All maintainer scripts (that is, preinst, prerm, postinst, and postrm files) are hard to write correctly unless they are auto-generated by the debhelper programs. So do not use them if you are a novice maintainer (see 第 5.19 节 “{pre,post}{inst,rm}).

If the package makes use of these non-trivial maintainer scripts, be sure to test not only for install but also for remove, purge, and upgrade processes. Many maintainer script bugs show up when packages are removed or purged. Use the dpkg command as follows to test them.

$ sudo dpkg -r gentoo
$ sudo dpkg -P gentoo
$ sudo dpkg -i gentoo_version-revision_i386.deb

整个测试过程应按照以下序列操作:

  • 如果可能,安装前一个版本的软件包;

  • 从前一个版本升级软件包;

  • 降级软件包到前一个版本(可选);

  • 彻底删除该软件包;

  • 全新安装该软件包;

  • 卸载该软件包;

  • 再次安装该软件包。

  • 彻底删除该软件包;

如果这是你的第一个软件包,你应该使用其他版本号创建一个测试用的软件包来完成升级测试,这样可以避免将来的问题。

请牢记如果你的软件包已经在以往版本的 Debian 中发布,人们通常会从最近发布的 Debian 发布里的版本升级,所以也要测试从那个版本升级到当前的版本。

Although downgrading is not officially supported, supporting it is a friendly gesture.

7.4. Using lintian

使用 lintian(1) 检查你的 .changes 文件。lintian 命令会运行很多测试脚本来检查常见的打包错误。[77]

$ lintian -i -I --show-overrides gentoo_0.9.12-1_i386.changes

Of course, replace the filename with the name of the .changes file generated for your package. The output of the lintian command uses the following flags.

  • E: for error; a sure policy violation or packaging error.

  • W: for warning; a possible policy violation or packaging error.

  • I: for info; information on certain aspects of packaging.

  • N: 代表注释:帮助你调试的详细信息。

  • O: 代表已覆盖:一个被 lintian-overrides 文件覆盖的信息,但由于使用 --show-overrides 选项而显示。

When you see warnings, tune the package to avoid them or verify that the warnings are spurious. If spurious, set up lintian-overrides files as described in 第 5.14 节 “{package.,source/}lintian-overrides.

Note that you can build the package with dpkg-buildpackage and run lintian on it in one command, if you use debuild(1) or pdebuild(1).

7.5. The debc command

You can list files in the binary Debian package with the debc(1) command.

$ debc package.changes

7.6. The debdiff command

你可以使用 debdiff(1) 命令比较两个 Debian 源代码包的内容。

$ debdiff old-package.dsc new-package.dsc

你还可以使用 debdiff(1) 命令比较两个 Debian 二进制包的文件列表。

$ debdiff old-package.changes new-package.changes

These are useful to identify what has been changed in the source packages and to check for inadvertent changes made when updating binary packages, such as unintentionally misplacing or removing files.

7.7. The interdiff command

你可以使用 interdiff(1) 命令比较两个 diff.gz 文件。这对于更新使用旧的 1.0 源代码格式的软件包时,检查是否有意外的变更非常有用。

$ interdiff -z old-package.diff.gz new-package.diff.gz

The new 3.0 source format stores changes in multiple patch files as described in 第 5.26 节 “patches/*. You can trace changes of each debian/patches/* file using interdiff, too.

7.8. The mc command

很多文件检查操作可以通过使用类似 mc(1) 的文件管理器来完成,它可以帮助你直接查看 *.deb 文件的内容,除此之外还可以用于 *.udeb*.debian.tar.gz*.diff.gz*.orig.tar.gz 文件。

Be on the lookout for extra unneeded files or zero length files, both in the binary and source package. Often cruft doesn't get cleaned up properly; adjust your rules file to compensate for this.



[77] 如果你按照 第 6.3 节 “debuild 命令” 中的叙述定义了 /etc/devscripts.conf~/.devscripts 文件,就不需要再添加 lintian 选项 -i -I --show-overrides