For most packages, the “dh” short-hand rules (possibly with a few overrides) work great. It can often auto-detect the buildsystem and handle all the trivial parts.
With one notably exception: What if you need to compile the upstream code twice (or more) with different flags? This is the case for all source packages building both regular debs and udebs.
In that case, you would previously need to override about 5-6 helpers for this to work at all. The five dh_auto_* helpers and usually also dh_install (to call it with different –sourcedir for different packages). This gets even more complex if you want to support Build-Profiles such as “noudeb” and “nodoc”.
The best way to support “nodoc” in debhelper is to move documentation out of dh_install’s config files and use dh_installman, dh_installdocs, and dh_installexamples instead (NB: wait for compat 11 before doing this). This in turn will mean more overrides with –sourcedir and -p/-N.
And then there is “noudeb”, which currently requires manual handling in debian/rules. Basically, you need to use make or shell if-statements to conditionally skip the udeb part of the builds.
All of this is needlessly complex.
Improving the situation
In an attempt to make things better, I have made a new prototype feature in debhelper called “buildlabels” in experimental. The current prototype is designed to deal with part (but not all) of the above problems:
- It will remove the need for littering your rules file for supporting “noudeb” (and in some cases also other “noX” profiles).
- It will remove the need for overriding the dh_install* tools just to juggle with –sourcedir and -p/-N.
However, it currently not solve the need for overriding the dh_auto_* tools and I am not sure when/if it will.
The feature relies on being able to relate packages to a given series of calls to dh_auto_*. In the following example, I will use udebs for the secondary build. However, this feature is not tied to udebs in any way and can be used any source package that needs to do two or more upstream builds for different packages.
Assume our example source builds the following binary packages:
- foo
- libfoo1
- libfoo-dev
- foo-udeb
- libfoo1-udeb
And in the rules file, we would have something like:
[...] override_dh_auto_configure: dh_auto_configure -B build-deb -- --with-feature1 --with-feature2 dh_auto_configure -B build-udeb -- --without-feature1 --without-feature2 [...]
What is somewhat obvious to a human is that the first configure line is related to the regular debs and the second configure line is for the udebs. However, debhelper does not know how to infer this and this is where buildlabels come in. With buildlabels, you can let debhelper know which packages and builds that belong together.
How to use buildlabels
To use buildlabels, you have to do three things:
- Pick a reasonable label name for the secondary build. In the example, I will use “udeb”.
- Add “–buildlabel=$LABEL” to all dh_auto_* calls related to your secondary build.
- Tag all packages related to “my-label” with “X-DH-Buildlabel: $LABEL” in debian/control. (For udeb packages, you may want to add “Build-Profiles: <!noudeb>” while you are at it).
For the example package, we would change the debian/rules snippet to:
[...] override_dh_auto_configure: dh_auto_configure -B build-deb -- --with-feature1 --with-feature2 dh_auto_configure --buildlabel=udeb -B build-udeb -- --without-feature1 --without-feature2 [...]
(Remember to update *all* calls to dh_auto_* helpers; the above only lists dh_auto_configure to keep the example short.) And then add “X-DH-Buildlabel: udeb” in the stanzas for foo-udeb + libfoo1-udeb.
With those two minor changes:
- debhelper will skip the calls to dh_auto_* with –buildlabel=udeb if the udeb packages are skipped.
- dh_auto_install will automatically pick a separate destination directory by default for the udeb build (assuming you do not explicitly override it with –destdir).
- dh_install will now automatically pick up files from the destination directory.that dh_auto_install used for the given package (even if you overwrote it with –destdir). Note that you have to remove any use of “–sourcedir” first as this disables the auto-detection. This also works for other dh_install* tools supporting –sourcedir in compat 11 or later.
Real example
Thanks to Michael Biebl, I was able to make an branch in the systemd git repository to play with this feature. Therefore I have an real example to use as a show case. The gist of it is in the following three commits:
- Apply labels to packages and dh_auto_* tools: https://anonscm.debian.org/git/pkg-systemd/systemd.git/commit/?h=wip-dh-prototype-smarter-multi-builds&id=880a80bc392a298bed033c047ccbef65e50acc58
- Clean up most make conditionals: https://anonscm.debian.org/git/pkg-systemd/systemd.git/commit/?h=wip-dh-prototype-smarter-multi-builds&id=96c0ab8b35ce04eab031a4a9ee4c4ef686f76977
- Merge multiple dh_install calls into one: https://anonscm.debian.org/git/pkg-systemd/systemd.git/commit/?h=wip-dh-prototype-smarter-multi-builds&id=67994cb5e5b451ebcebb0dccfdd97e606ac4a172
(–fail-missing was never applied to the udeb before; I kept it that way by passing –sourcedir to dh_missing because I was to lazy to review the missing files).
Full branch can be seen at: https://anonscm.debian.org/git/pkg-systemd/systemd.git/log/?h=wip-dh-prototype-smarter-multi-builds
Request for comments / call for testing
This prototype is now in experimental (debhelper/10.7+exp.buildlabels) and you are very welcome to take it for a spin. Please let me know if you find the idea useful and feel free to file bugs or feature requests. If deemed useful, I will merge into master and include in a future release.
If you have any questions or comments about the feature or need help with trying it out, you are also very welcome to mail the debhelper-devel mailing list.
Known issues / the fine print:
- It is experimental feature and may change without notice.
- The current prototype may break existing packages as it is not guarded by a compat bump to ease your testing. I am still very curious to hear about any issues you may experience.
- The default build directory is re-used even with different buildlabels, so you still need to use explicit build dirs for buildsystems that prefer building in a separate directory (e.g. meson).
- udebs are not automatically tagged with an “udeb” buildlabel. This is partly by design as some source packages only build udebs (and no regular debs). If they were automatically tagged, the existing packages would break.
- Label names are used in path names, so you may want to refrain from using “too exciting” label names.
- It is experimental feature and may change without notice. (Yes, I thought it deserved repeating)
Filed under: Debhelper, Debian
