Chapter 3. 工具的配置

Table of Contents

3.1. 电子邮件地址
3.2. mc
3.3. git
3.4. quilt
3.5. devscripts
3.6. sbuild
3.7. git-buildpackage
3.8. HTTP 代理
3.9. 私有 Debian 仓库
3.10. Virtual machines
3.11. Local network with virtual machines

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

devscripts 软件包应当安装在维护者的工作环境中。

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.

[Caution] Caution

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

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

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

添加至 ~/.bashrc 文件. 

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

mc 命令提供了管理文件的简单途径。它可以打开二进制 deb 文件,并仅需对二进制 deb 文件按下回车键便能检查其内容。它调用了 dpkg-deb 命令作为其后端。我们可以按照下列方式对其配置,以支持简易 chdir 操作。

添加至 ~/.bashrc 文件. 

# mc related
if [ -f /usr/lib/mc/mc.sh ]; then
  . /usr/lib/mc/mc.sh
fi

如今 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
[Tip] Tip

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

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

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

添加至 ~/.bashrc 文件. 

alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
. /usr/share/bash-completion/completions/quilt
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:"
    QUILT_COLORS="${QUILT_COLORS}diff_ctx=35:diff_cctx=33"
    if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
fi

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

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

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

debuild 命令同样由 devscripts 软件包提供,它可以构建二进制软件包并使用 lintian 命令对其进行检查。lintian 命令的详细输出通常都很实用。

您可以将下列内容写入 ~/.devscripts 文件来进行配置。

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 选项以帮助构建源码中具有外来无关内容的软件包(参见 Section 5.17, “构建软件包时排除不必要的内容”)。

当前情况下,使用 4096 位的 RSA 密钥是较好的做法。另见 创建一个新 GPG 密钥

The sbuild package provides a clean room (chroot) build environment. It offers this efficiently with the help of schroot using the bind-mount feature of the modern Linux kernel.

Since it is the same build environment as the Debian’s buildd infrastructure, it is always up to date and comes with full of useful features.

It can be customized to offer following features:

  • The schroot package to boost the chroot creation speed.
  • lintian 软件包能找到所构建软件包中的缺陷。
  • The piuparts package to find bugs in the package.
  • The autopkgtest package to find bugs in the package.
  • ccache 软件包可以加速 gcc。(可选)
  • libeatmydata1 软件包可以加速 dpkg。(可选)
  • 并行运行 make 以提高构建速度。(可选)

Let’s get started by following https://wiki.debian.org/sbuild .

$ sudo apt install sbuild piuparts autopkgtest lintian
$ sudo usermod -a -G <your_user_name> sbuild

Reboot your system or execute command such as “kill -TERM -1[8]. Then login and check you are a member of sbuild group using id command.

$ id
uid=1000(<yourname>) gid=1000(<yourname>) groups=...,132(sbuild)

Let’s create the configuration file ~/.sbuildrc in line with recent Debian practice https://wiki.debian.org/SourceOnlyUpload as:

cat >~/.sbuildrc << 'EOF'
##############################################################################
# PACKAGE BUILD RELATED (source-only-upload as default)
##############################################################################
# -d
$distribution = 'unstable';
# -A
$build_arch_all = 1;
# -s
$build_source = 1;
# --source-only-changes
$source_only_changes = 1;
# -v
$verbose = 1;

##############################################################################
# POST-BUILD RELATED (turn off functionality by setting variables to 0)
##############################################################################
$run_lintian = 1;
$lintian_opts = ['-i', '-I'];
$run_piuparts = 1;
$piuparts_opts = ['--schroot', 'unstable-amd64-sbuild'];
$run_autopkgtest = 1;
$autopkgtest_root_args = '';
$autopkgtest_opts = [ '--', 'schroot', '%r-%a-sbuild' ];

##############################################################################
# PERL MAGIC
##############################################################################
1;
EOF

Following document assumes that sbuild is configured this way.

Edit this to your needs. Post-build tests can be turned on and off by assigning 1 or 0 to the corresponding variables,

[Warning] Warning

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

[Note] Note

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

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

# Configuration file for "gbp <command>"

[DEFAULT]
# the default build command:
builder = sbuild
# use pristine-tar:
pristine-tar = True
# Use color when on a terminal, alternatives: on/true, off/false or auto
color = auto
[Tip] Tip

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

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

  • 特化的 HTTP 缓存代理,使用 apt-cacher-ng 软件包。
  • Generic HTTP caching proxy (squid package) configured by squid-deb-proxy package

In order to use this HTTP proxy without manual configuration adjustment, it’s a good idea to install either auto-apt-proxy or squid-deb-proxy-client package to everywhere.

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

For testing GUI application, it is good idea to have virtual machines. Install virt-manager and qemu-kvm.

Use of chroot and virtual machines allow us not to update the whole host PC to the latest unstable.

In order to access virtual machines easily over the local network, setting up multicast DNS service discovery infrastructure by installing avahi-utils is a good idea.

For all running virtual machines and the host PC, we can use each host name appended with .local for SSH to access each other.



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

[8] Logout from your system via GUI menu may not work.