#990073 dpkg-gencontrol: please expand binary packages in Built-Using to source and version

Package:
dpkg-dev
Source:
dpkg-dev
Submitter:
Nicolas Boulenguez
Date:
2026-09-18 12:13:04 UTC
Severity:
normal
Tags:
#990073#5
Date:
2021-06-19 14:00:43 UTC
From:
To:
Hello.

This pattern seems common:
debian/rules:
  override_dh_gencontrol:
        dh_gencontrol -- "-VBuilt-Using:P1=`dpkg-query -Wf'$${source:Package} (= $${source:Version})' P2`"
debian/control:
  Package: P1
  Built-Using: ${Built-Using:P1}

It would be convenient and less error-prone to write:
  Package: P1
  Built-Using: P2
and trust dpkg-gencontrol to replace P2 with the output of
  dpkg-query -Wf '${source:Package} (= ${source:Version})' P2

debian/rules could still use variables, but would not be forced to
deal with dpkg-query anymore.
  override_dh_gencontrol:
    dh_gencontrol -- -VBuilt-Using:P1=$(if TEST,P2)

Especially, conditions depending on architectures or build profiles
could be expressed directly within debian/control:
  Built-Using: P2 [!arm64]

The rewriting should only affect valid package identitiers without
version restriction (after variable substitutions and architecture or
profile restrictions).  Since the Policy requires values matching
'SOURCE (= VERSION)', single identifiers are currently invalid.
Hence, the change would not affect existing packages or, more
generally, explicit values from the maintainer.

#990073#10
Date:
2021-06-20 10:00:39 UTC
From:
To:
Here is a proof of concept passing the following tests.
gcc                                       -> gcc-defaults (= .*)
bla (= 1), gcc, foo (= 2)                 -> bla (= 1), foo (= 2), gcc-defaults (= .*)
bla (= 1), gcc, g++, foo (= 2)            -> bla (= 1), foo (= 2), gcc-defaults (= .*)
bla (= 1), foo (= 2) [arm64], g++ [arm64] -> bla (= 1)
bla, gcc, g++, foo (= 2)                  -> error message with 'bla gcc g++'
--- a/man/dpkg-gencontrol.pod
+++ b/man/dpkg-gencontrol.pod
@@ -58,6 +58,10 @@ B<dpkg-gencontrol>
 also adds an entry for the binary package to
 B<debian/files>.

+Each unversioned dependency in the B<Built-Using> field is assumed to
+be installed on the system (usually, via B<Build-Depends>), and
+replaced with the matching source package and version.
+
 =head1 OPTIONS

 =over
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -293,6 +293,13 @@ foreach my $field (field_list_pkg_dep()) {
 	                      reduce_profiles => 1, union => 1);
             error(g_("parsing package '%s' %s field: %s"), $oppackage,
                   $field, $field_value) unless defined $dep;
+            if ($field eq 'Built-Using'
+                and (my @changed = grep { not defined $_->{'version'} } $dep->get_deps())) {
+                my $debs = join(' ', map { $_->{'package'} } @changed);
+                my @lines = `dpkg-query -Wf '\${source:Package} (= \${source:Version})\\n' $debs`;
+                error(g_('failed to expand Built-Using: %s'), $debs) if $?;
+                $_->parse_string(shift @lines) for (@changed);
+            }
 	    $dep->simplify_deps($facts);
             $dep->sort();
 	}

#990073#21
Date:
2023-05-19 18:59:22 UTC
From:
To:
Hello.

I have written a tool inspired by this bug report.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1035888
A full description is available at
https://salsa.debian.org/debian/dh-builtusing/-/blob/master/dh_builtusing.pod

This is a proof of concept, any suggestion or critic is welcome
(especially before anyone starts depending on it :-).

A separate debhelper tool avoids extending the dpkg interface. It
should be easier to maintain and document.
The price is some redundancy.  The tool parses debian/control twice,
via Dh_Lib and Dpkg perl modules.

#990073#22
Date:
2023-08-17 06:14:48 UTC
From:
To:
Hello.
Dh-builtusing is available in unstable.