Debcraft – 最简单的方式来修改和构建 Debian 软件包
Debcraft – Easiest way to modify and build Debian packages

原始链接: https://optimizedbyotto.com/post/debcraft-easy-debian-packaging/

## Debcraft:简化 Debian 软件包构建 Debian 软件包构建以其复杂性而闻名,这常常让新贡献者望而却步,并导致经验丰富的打包者感到疲惫。Debcraft 旨在通过自动化繁琐的任务并推广最佳实践,从而改善代码和构建制品的变化跟踪,帮助新老打包者。 与其他软件包格式不同,Debian 使用 `debian/` 目录中的声明式文件,这提供了强大的可靠性和静态分析能力。然而,这种方法也带来了陡峭的学习曲线,因为存在许多工具、过时的文档以及缺乏标准化的实践。 Debcraft 通过有意识地采用明确的观点,并利用 Git、`git-buildpackage` 和 Linux 容器(Docker/Podman)来简化这一过程。这使得软件包构建无需 Debian 系统即可完成,从而提高了可访问性。它提供了用于构建、测试、更新和发布软件包的命令,具有清晰的输出和易于比较构建制品的特性。 此外,`debcraft improve` 命令可以自动执行策略更新等维护任务,而 `debcraft update` 命令则可以简化上游版本升级。Debcraft 可以通过 `apt install debcraft` 或 Git 获取,它使用 shell 脚本编写以鼓励贡献,并为有志于成为 Debian 开发者的用户提供指导。

## Debcraft 与 Debian 软件包:总结 最近 Hacker News 上出现了一场关于 Debcraft 的讨论,Debcraft 是一款旨在简化 Debian 软件包修改和构建的工具。讨论的核心问题并非 Debcraft 本身,而是长期以来 Debian 软件包工具和文档难以理解的问题。 许多评论者都认为 Debian 的文档充斥着过时的信息,使得找到适用于当前版本的相关指南变得困难。一些人提出了版本化文档分支等解决方案,但承认删除旧内容存在顾虑。另一些人则指出了 Debian 维护者指南等现有资源,但即使这些资源也可能淹没在信息噪音中难以发现。 一个反复出现的主题是,基本的软件包任务——例如将文件简单地复制到 `.deb` 文件中——由于工具的复杂性而变得出乎意料地困难。 许多用户提倡在简单情况下直接使用 `dpkg-deb`,并将 Debian 的复杂性与 Alpine 和 Arch Linux 等发行版简化的打包流程进行对比。 讨论还涉及软件生态系统中工具创建的循环性,即新的工具出现是为了解决现有问题,但最终会被其他工具取代。 归根结底,许多人认为 Debian 本身应该优先简化其核心打包工具。
相关文章

原文

Debian packaging is notoriously hard. Far too many new contributors give up while trying, and many long-time contributors leave due to burnout from having to do too many thankless maintenance tasks. Some just skip testing their changes properly because it feels like too much toil.

Debcraft is my attempt to solve this by automating all the boring stuff, and making it easier to learn the correct practices and helping new and old packagers better track changes in both source code and build artifacts.

The challenge of declarative packaging code

Unlike how rpm or apk packages are done, the deb package sources by design avoid having one massive procedural packaging recipe. Instead, the packaging is defined in multiple declarative files in the debian/ subdirectory. For example, instead of a script running install -m 755 bin/btop /usr/bin/btop there is a file debian/btop.install containing the line usr/bin/btop.

This makes the overall system more robust and reliable, and allows, for example, extensive static analysis to find problems without having to build the package. The notable exception is the debian/rules file, which contains procedural code that can modify any aspect of the package build. Almost all other files are declarative.

Benefits include, among others, that the effect of a Debian-wide policy change can be relatively easily predicted by scanning what attributes and configurations all packages have declared.

The drawback is that to understand the syntax and meaning of each file, one must understand which build tools read which files and traverse potentially multiple layers of abstraction. In my view, this is the root cause for most of the perceived complexity.

Common complaints about .deb packaging

Related to the above, people learning Debian packaging frequently voice the following complaints:

  • Debian has too many tools to learn, often with overlapping or duplicate functionality.
  • Too much outdated and inconsistent documentation that makes learning the numerous tools needlessly hard.
  • Lack of documentation of the generally agreed best practices, mainly due to Debian’s reluctance as a project to pick one tool and deprecate the alternatives.
  • Multiple layers of abstraction and lack of clarity on what any single change in the debian/ subdirectory leads to in the final package.
  • Requirement of Debian packages to be developed on a Debian system.

How Debcraft solves (some of) this

Debcraft is intentionally opinionated for the sake of simplicity, and makes heavy use of git, git-buildpackage, and most importantly Linux containers, supporting both Docker and Podman.

By using containers, Debcraft frees the user from the requirement of having to run Debian. This makes .deb packaging more accessible to developers running some other Linux distro or even Mac or Windows (with WSL). Of course we want developers to run Debian (or a derivative like Ubuntu) but we want them even more to build, test and ship their software as .deb. Even for Debian/Ubuntu users having everything done inside clean hermetic containers of the latest target distribution version will yield more robust, secure and reproducible builds and tests. All containers are built automatically on-the-fly using best practices for layer caching, making everything easy and fast.

Debcraft has simple commands to make it easy to build, rebuild, test and update packages. The most fundamental command is debcraft build, which will not only build the package but also fetch the sources if not already present, and with flags such as --distribution or --source-only build for any requested Debian or Ubuntu release, or generate source packages only for Debian or PPA upload purposes.

For ease of use, the output is colored and includes helpful explanations on what is being done, and suggests relevant Debian documentation for more information.

Most importantly, the build artifacts, along with various logs, are stored in separate directories, making it easy to compare before and after to see what changed as a result of the code or dependency updates (utilizing diffoscope among others).

While the above helps to debug successful builds, there is also the debcraft shell command to make debugging failed builds significantly easier by dropping into a shell where one can run various dh commands one-by-one.

Once the build works, testing autopkgtests is as easy as running debcraft test. As with all other commands, Debcraft is smart enough to read information like the target distribution from the debian/changelog entry.

When the package is ready to be released, there is the debcraft release command that will create the Debian source package in the correct format and facilitate uploading it either to your Personal Package Archive (PPA) or if you are a Debian Developer to the official Debian archive.

Automatically improve and update packages

Additionally, the command debcraft improve will try to fix all issues that are possible to address automatically. It utilizes, among others, lintian-brush, codespell and debputy. This makes repetitive Debian maintenance tasks easier, such as updating the package to follow the latest Debian policies.

To update the package to the latest upstream version there is also debcraft update. It will read the package configuration files such as debian/gbp.conf and debian/watch and attempts to import the latest upstream version, refresh patches, build and run autopkgtests. If everything passes, the new version is committed. This helps automate the process of updating to new upstream versions.

Try out Debcraft now!

On a recent version of Debian and Ubuntu, Debcraft can be installed simply by running apt install debcraft. To use Debcraft on some other distribution or to get the latest features available in the development version install it using:

git clone https://salsa.debian.org/debian/debcraft.git
cd debcraft
make install-local

To see exact usage instructions run debcraft --help.

Contributions welcome

Current Debcraft version 0.5 still has some rough edges and missing features, but I have personally been using it for over a year to maintain all my packages in Debian. If you come across some issue, feel free to file a report at https://salsa.debian.org/debian/debcraft/-/issues or submit an improvement at https://salsa.debian.org/debian/debcraft/-/merge_requests. The code is intentionally written entirely in shell script to keep the barrier to code contribution as low as possible.

By the way, if you aspire to become a Debian Developer, and want to follow my examples in using state-of-the-art tooling and collaborate using salsa.debian.org, feel free to reach out for mentorship. I am glad to see more people contribute to Debian!

联系我们 contact @ memedata.com