]> git.donarmstrong.com Git - debhelper.git/commitdiff
dh: Add sequence dependencies and satisfy dependencies prior to running sequence
authorRoger Leigh <rleigh@debian.org>
Tue, 23 Nov 2010 18:00:06 +0000 (18:00 +0000)
committerJoey Hess <joey@kitenet.net>
Sun, 5 Dec 2010 21:35:30 +0000 (17:35 -0400)
Add %sequence_deps and invoke recursively prior to examining logs and
running commands in sequence.  The supplied dependencies are equivalent
to the following make rules:

build: build-arch build-indep
install: install-arch install-indep
install-arch: build-arch
install-indep: build-indep
binary: binary-arch binary-indep
binary-arch: install-arch
binary-indep: install-indep

In the existing dh command sequences, the binary sequences all included
the corresponding install sequence commands, and in turn the install
sequences all included the corresponding build commands.  While this
works, it has a major deficiency.  If the "binary" sequence is run, it
will not run the "build" target in debian/rules.  This leads to a
situation where building with dpkg-buildpackge, which would typically
invoke "debian/rules build" followed by "debian/rules binary-arch"
and/or "debian/rules debian-indep" may do something different than
just invoking "debian/rules binary" or "dh binary" because the build
target in debian/rules is effectively bypassed.  This applies equally
to the -arch and -indep sequence variants.

This change eliminates the duplicated sequence commands, and instead
invokes the appropriate target(s) in debian/rules, as specified in the
%sequence_deps hash.  In the common case, the dh sequence by the same
name will be called, so the behaviour is identical.  However, this
provides a means to utilise all of the policy-specified targets, plus
the install targets and extend them with additional dependencies and
commands, while still allowing full use of dh and giving identical
behaviour whether dh or debian/rules targets are used.

Signed-off-by: Roger Leigh <rleigh@debian.org>
dh

diff --git a/dh b/dh
index 301ce5d2a7850de14c27c3c1ab02b895f30b728a..5537db4cebe50098a2c09118e5f7901f6add08fd 100755 (executable)
--- a/dh
+++ b/dh
@@ -270,6 +270,16 @@ that is in the specified sequence. It then continues with the next command
 in the sequence. The B<--until>, B<--before>, B<--after>, and B<--remaining>
 options can override this behavior.
 
+A sequence can also have dependencies.  For example, the "binary"
+sequence depends upon the "binary-arch" and "binary-indep" sequences,
+and the "binary-arch" sequence depends upon the "install-arch"
+sequence which in turn depends upon the "build-arch" sequence.  These
+will, by default, be run via "debian/rules <sequence>" and so may be
+overridden or extended there, or else will run dh again to execute the
+depending sequence.  For example, "dh binary-arch" will run
+"debian/rules install-arch" which will run "dh install-arch" unless a
+custom install-arch target replaces the default target.
+
 B<dh> uses the B<DH_INTERNAL_OPTIONS> environment variable to pass information
 through to debhelper commands that are run inside override targets. The
 contents (and indeed, existence) of this environment variable, as the name
@@ -318,14 +328,15 @@ if (is_make_jobserver_unavailable()) {
 
 # Definitions of sequences.
 my %sequences;
-$sequences{build} = [qw{
+my @bd = qw{
        dh_testdir
        dh_auto_configure
        dh_auto_build
        dh_auto_test
-}],
-$sequences{'build-indep'} = [@{$sequences{build}}];
-$sequences{'build-arch'} = [@{$sequences{build}}];
+};
+$sequences{build} = [@bd];
+$sequences{'build-indep'} = [@bd];
+$sequences{'build-arch'} = [@bd];
 $sequences{clean} = [qw{
        dh_testdir
        dh_auto_clean
@@ -371,9 +382,9 @@ my @i = qw{
        dh_compress
        dh_fixperms
 };
-$sequences{'install'} = [@{$sequences{build}}, @i];
-$sequences{'install-indep'} = [@{$sequences{'build-indep'}}, @i];
-$sequences{'install-arch'} = [@{$sequences{'build-arch'}}, @i];
+$sequences{'install'} = [@i];
+$sequences{'install-indep'} = [@i];
+$sequences{'install-arch'} = [@i];
 my @ba=qw{
        dh_strip
        dh_makeshlibs
@@ -385,9 +396,19 @@ my @b=qw{
        dh_md5sums
        dh_builddeb
 };
-$sequences{binary} = [@{$sequences{install}}, @ba, @b];
-$sequences{'binary-indep'} = [@{$sequences{'install-indep'}}, @b];
-$sequences{'binary-arch'} = [@{$sequences{'install-arch'}}, @ba, @b];
+$sequences{binary} = [@ba, @b];
+$sequences{'binary-indep'} = [@b];
+$sequences{'binary-arch'} = [@ba, @b];
+
+# Sequence dependencies
+my %sequence_deps;
+$sequence_deps{build} = ['build-arch', 'build-indep'];
+$sequence_deps{install} = ['install-arch', 'install-indep'];
+$sequence_deps{'install-arch'} = ['build-arch'];
+$sequence_deps{'install-indep'} = ['build-indep'];
+$sequence_deps{binary} = ['binary-arch', 'binary-indep'];
+$sequence_deps{'binary-arch'} = ['install-arch'];
+$sequence_deps{'binary-indep'} = ['install-indep'];
 
 # Additional command options
 my %command_opts;
@@ -516,6 +537,29 @@ elsif (! exists $sequences{$sequence}) {
 }
 my @sequence=@{$sequences{$sequence}};
 
+# Recursively invoke sequence dependencies before any further processing.
+# The dh options are not passed in the environment, to ensure that the
+# behaviour is the same if invoked directly.
+my $deps = undef;
+$deps = $sequence_deps{$sequence}
+       if (exists($sequence_deps{$sequence}));
+if (defined($deps)) {
+       foreach my $dep (@$deps) {
+               my $command = 'debian/rules';
+               my @dep_options = ($dep);
+               print "   ".escape_shell($command, @dep_options)."\n";
+               if (! $dh{NO_ACT}) {
+                       my $ret=system($command, @dep_options);
+                       if ($ret >> 8 != 0) {
+                               exit $ret >> 8;
+                       }
+                       elsif ($ret) {
+                               exit 1;
+                       }
+               }
+       }
+}
+
 # The list of all packages that can be acted on.
 my @packages=@{$dh{DOPACKAGES}};