第 3 章 工具的配置

目录

3.1. 电子邮件地址
3.2. mc
3.3. git
3.4. quilt
3.5. devscripts
3.6. pbuilder
3.7. git-buildpackage
3.8. HTTP 代理
3.9. 私有 Debian 仓库

build-essential 软件包必须在构建环境内预先安装。

The devscripts package should be installed in the maintainer environment.

Although this is not necessarily an absolute requirement, it is a good idea to install and set up all of the popular set of packages mentioned in this chapter in the maintainer environment. This enables us to share the common baseline working environment.

Please install the tools mentioned in the Overview of Debian Maintainer Tools in the “Debian Developer’s Reference”, as needed, too.

[小心] 小心

这里展示的工具配置方式仅作为示例提供,可能与系统上最新的软件包相比有所落后。Debian 的开发具有一个移动的目标。请确保阅读合适的文档并按照需要更新配置内容。

许多 Debian 维护工具识别并使用 shell 环境变量 $DEBEMAIL$DEBFULLNAME 作为作为您的电子邮件地址和名称。

我们可以通过将下面几行加入 ~/.bashrc[6] 的方式对这些软件进行配置。

添加至 ~/.bashrc 文件. 

DEBEMAIL="your.email.address@example.org"
DEBFULLNAME="Firstname Lastname"
export DEBEMAIL DEBFULLNAME

The mc command offers very easy ways to manage files. It can open the binary deb file to check its content by pressing the Enter key over the binary deb file. It uses the dpkg-deb command as its back-end. Let’s set it up to support easy chdir as follows.

添加至 ~/.bashrc 文件. 

# mc related
export HISTCONTROL=ignoreboth
. /usr/lib/mc/mc.sh

如今 git 命令已成为管理带历史的源码树的必要工具。

git 命令的用户级全局配置,如你的名字和电子邮件地址,保存在 ~/.gitconfig 文件中,且可以使用如下方式配置:

$ git config --global user.name "Name Surname"
$ git config --global user.email yourname@example.com

如果你仍然只习惯 CVS 或者 Subversion 的命令风格,你可以使用如下方式设置几个命令别名。

$ git config --global alias.ci "commit -a"
$ git config --global alias.co checkout

你可以使用如下命令检查全局配置。

$ git config --global --list
[提示] 提示

有必要使用某些图形界面 git 工具,例如 gitkgitg 命令来有效地处理 git 仓库的历史。

quilt 命令提供了记录修改的一个基本方式。对 Debian 打包来说,该工具需要进行自定义,从而在 debian/patches/ 目录内记录修改内容,而非使用默认的 patches/ 目录。

为了避免改变 quilt 命令自身的行为,我们在这里创建一个用于 Debian 打包工作的命令别名:dquilt。之后,我们将对应内容写入 ~/.bashrc 文件。下面给出的第二行为 dquilt 命令提供与 quilt 命令相同的命令行补全功能。

添加至 ~/.bashrc 文件. 

alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
complete -F _quilt_completion $_quilt_complete_opt dquilt

然后我们来创建具有如下内容的 ~/.quiltrc-dpkg 文件。

d=.
while [ ! -d $d/debian -a `readlink -e $d` != / ];
    do d=$d/..; done
if [ -d $d/debian ] && [ -z $QUILT_PATCHES ]; then
    # if in Debian packaging tree with unset $QUILT_PATCHES
    QUILT_PATCHES="debian/patches"
    QUILT_PATCH_OPTS="--reject-format=unified"
    QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
    QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
    QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:" + \
            "diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33"
    if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
fi

请参考 quilt(1) 和 处理大量补丁的方法暨对 Quilt 的介绍 以了解如何使用 quilt 命令。

要获取使用示例,请查看 第 4.8 节 “第三步(备选):修改上游源代码”

debsign 命令由 devscripts 软件包提供,它可以使用用户的 GPG 私钥对 Debian 软件包进行签名。

The debuild command, included in the devscripts package, builds the binary package and checks it with the lintian command. It is useful to have verbose outputs from the lintian command.

You can set these up in ~/.devscripts as follows.

DEBUILD_DPKG_BUILDPACKAGE_OPTS="-i -I -us -uc"
DEBUILD_LINTIAN_OPTS="-i -I --show-overrides"
DEBSIGN_KEYID="Your_GPG_keyID"

用于 dpkg-source 命令的 DEBUILD_DPKG_BUILDPACKAGE_OPTS 中可以额外使用 -i-I 选项以帮助构建源码中具有外来无关内容的软件包(参见 第 5.15 节 “Building package without extraneous contents”)。

Currently, an RSA key with 4096 bits is a good idea. See Creating a new GPG key.

The pbuilder package provides a clean room (chroot) build environment. [7]

我们可以搭配使用另外几个辅助软件包对其自定义。

  • cowbuilder 软件包能加速 chroot 创建过程。
  • lintian 软件包能找到所构建软件包中的缺陷。
  • bashmcvim 软件包在构建失败时用来查找问题。
  • ccache 软件包可以加速 gcc。(可选)
  • libeatmydata1 软件包可以加速 dpkg。(可选)
  • 并行运行 make 以提高构建速度。(可选)
[警告] 警告

可选的自定义项可能造成负面影响。如果有疑问,请禁用它们。

我们使用如下给出的内容来创建 ~/.pbuilderrc 文件(所有可选功能均已禁用)。

AUTO_DEBSIGN="${AUTO_DEBSIGN:-no}"
PDEBUILD_PBUILDER=cowbuilder
HOOKDIR="/var/cache/pbuilder/hooks"
MIRRORSITE="http://deb.debian.org/debian/"
#APTCACHE=/var/cache/pbuilder/aptcache
APTCACHE=/var/cache/apt/archives
#BUILDRESULT=/var/cache/pbuilder/result/
BUILDRESULT=../
EXTRAPACKAGES="ccache lintian libeatmydata1"

# enable to use libeatmydata1 for pbuilder
#export LD_PRELOAD=${LD_PRELOAD+$LD_PRELOAD:}libeatmydata.so

# enable ccache for pbuilder
#export PATH="/usr/lib/ccache${PATH+:$PATH}"
#export CCACHE_DIR="/var/cache/pbuilder/ccache"
#BINDMOUNTS="${CCACHE_DIR}"

# parallel make
#DEBBUILDOPTS=-j8
[注意] 注意

可以考虑创建从 /root/.pbuilderrc/home/<user>/.pbuilderrc 的符号链接以获得一致的体验。

[注意] 注意

由于 缺陷 #606542,你可能需要手动将 EXTRAPACKAGES 列出的软件包安装进入 chroot。请见 第 7.10 节 “chroot”

[注意] 注意

Install libeatmydata1 (>=82-2) both inside and outside of the chroot or disable to use libeatmydata1. This may cause a race condition with some build systems.

[注意] 注意

并行的 make 可能在某些已有软件包上运行失败,它同样会使得构建日志难以阅读。

我们可以按如下方式创建钩子脚本:

/var/cache/pbuilder/hooks/A10ccache

#!/bin/sh
set -e
# increase the ccache caching size
ccache -M 4G
# output the current statistics
ccache -s

/var/cache/pbuilder/hooks/B90lintian

#!/bin/sh
set -e
apt-get -y --allow-downgrades install lintian
echo "+++ lintian output +++"
su -c "lintian -i -I --show-overrides /tmp/buildd/*.changes; :" -l pbuilder
echo "+++ end of lintian output +++"

/var/cache/pbuilder/hooks/C10shell

#!/bin/sh
set -e
apt-get -y --allow-downgrades install vim bash mc
# invoke shell if build fails
cd /tmp/buildd/*/debian/..
/bin/bash < /dev/tty > /dev/tty 2> /dev/tty
[注意] 注意

所有这些脚本都需要设置为全局可执行:“-rwxr-xr-x 1 root root”。

[注意] 注意

ccache 的缓存目录 /var/cache/pbuilder/cache 需要为了 pbuilder 命令的使用而设置为全局可写:“-rwxrwxrwx 1 root root”。你需要明白这样会带来相关的安全隐患。

你也可能需要在 ~/.gbp.conf 中设置全局配置信息

# Configuration file for "gbp <command>"

[DEFAULT]
# the default build command:
builder = git-pbuilder -i -I -us -uc
# use pristine-tar:
pristine-tar = True
# Use color when on a terminal, alternatives: on/true, off/false or auto
color = auto
[提示] 提示

这里的 gbp 命令是 git-buildpackage 命令的一个别名。

你应当在本地设置 HTTP 缓存代理以节约访问 Debian 软件仓库的带宽。可以考虑以下几种选项:

  • 简单的 HTTP 缓存代理,使用 squid 软件包。
  • 特化的 HTTP 缓存代理,使用 apt-cacher-ng 软件包。

你可以使用 reprepro 软件包搭建私有 Debian 仓库。



[6] 这里假设你正在使用 Bash 并以此作为登录默认 shell。如果你设置了其它登录 shell,例如 Z shell,请使用它们对应的配置文件替换 ~/.bashrc 文件。

[7] The sbuild package provides an alternative chroot platform.