Hi Joey,

On Sun, Jun 12, 2011 at 11:47:54AM -0400, Joey Hess wrote:
> Roger Leigh wrote:
> > Good point.  In the attached patch I've retained the scheme for
> > the build and install targets, where it serves a purpose, and
> > dropped it for binary.
> 
> $sequences{binary} = ['rules:install', @ba, @b];
> $sequences{'binary-indep'} = ['rules:install-indep', @b];
> $sequences{'binary-arch'} = ['rules:install-arch', @ba, @b];
> 
> But now binary-indep/arch targets won't be run by debian/rules binary.

Argh, yes. Changing this to

$sequences{binary} = ['rules:install', 'rules:binary-arch', 
'rules:binary-indep'];

(attached) means that the binary target won't do anything itself, it
will just run install (so install-arch and install-indep sequences
aren't run separately via the binary-(arch|indep) sequences), and then
binary-arch and binary-indep.

> It also is somewhat surprising that, when both build-indep and build-arch
> targets are defined, build still runs dh_auto_build before running either.
> 
> Perhaps not only surprising, but likely to break existing packages. If
> an existing package has its own build targets, and implicit binary-* set to
> depend on it, it can expect dh_auto_build not to run unless it calls it in
> build. But with the patched dh, debian/rules binary will run dh_auto_build
> anyway.

The correct (but slower) way would be for the build sequence to
delegate everything (except maybe configure) to the build-arch and
build-indep rules.  This would, however, require each dh_ helper
to be run twice.  (This is what all my current packages do in any
case, so while it is slower, it's not much slower than existing
practice in non-dh debhelper-using packages.  But it would be slower
for dh users.)

One possible approach here would be to call
rules_explicit_target("build-(arch|indep)") and and then if they exist,
we can skip the entire build sequence up to invoking
"debian/rules build-(arch|indep)".  This would mean if you don't
explicitly write a build-(arch|indep) rule, you get the faster
behaviour by doing all the arch and indep work together; and if you
do define them, you get the separate, slower behaviour.  This would
be correct in both cases, it's just trading speed for flexibility.
The same can be done for the install target.  I've attached a second
patch which implements this optimisation.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
From 5ceeae68258bf2805348e4e7e913bf1f69e3332b Mon Sep 17 00:00:00 2001
From: Roger Leigh <[email protected]>
Date: Fri, 3 Jun 2011 20:41:30 +0100
Subject: [PATCH] dh: Add sequence dependency support

Rather than dh sequences containing dependent sequences within
themselves, invoke the sub-sequence via debian/rules to permit
overriding and customisation using the policy-defined debian/rules
targets.

Signed-off-by: Roger Leigh <[email protected]>
---
 dh |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/dh b/dh
index 50e0f14..75070ea 100755
--- a/dh
+++ b/dh
@@ -151,6 +151,16 @@ either and instead run your own commands.
 	override_dh_auto_build:
 		make universe-explode-in-delight
 
+If running a configure script, it may be necessary to prevent it being
+run twice, once for architecture-independent packages, and again for
+architecture-dependent packages.  This may be accomplished by
+overriding L<dh_autoconfigure(1)>:
+
+	override_dh_auto_configure: config.status
+
+	config.status:
+		dh_auto_configure -- $configure_options
+
 Another common case is wanting to do something manually before or
 after a particular debhelper command is run.
 
@@ -273,6 +283,13 @@ 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 run dependent targets in debian/rules.  For
+example, the "binary" sequence runs the "install" target.  This will
+show up in the dh output as "debian/rules install", but internally
+will be called "rules:install" in the sequence.  The "install"
+sequence likewise runs "debian/rules build", internally named
+"rules:build".
+
 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
@@ -321,14 +338,20 @@ 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}}];
+};
+# The build sequences will call 'debian/rules build-arch' and
+# 'debian/rules build-indep' after running the standard sequence;
+# these will typically be no-ops but this permits the standard targets
+# to be customised by the user and still run as a side-effect of the
+# build target.
+$sequences{build} = [@bd, 'rules:build-arch', 'rules:build-indep'];
+$sequences{'build-indep'} = [@bd];
+$sequences{'build-arch'} = [@bd];
 $sequences{clean} = [qw{
 	dh_testdir
 	dh_auto_clean
@@ -376,9 +399,15 @@ 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];
+# The install sequences will call 'debian/rules build' before running
+# the standard sequence, and 'debian/rules install-arch' and
+# 'debian/rules install-indep' after running the standard sequence;
+# these will typically be no-ops but this permits the install-arch and
+# install-indep targets to be customised by the user and still run as
+# a side-effect of the install target.
+$sequences{'install'} = ['rules:build', @i, 'rules:install-arch', 'rules:install-indep'];
+$sequences{'install-indep'} = ['rules:build-indep', @i];
+$sequences{'install-arch'} = ['rules:build-arch', @i];
 my @ba=qw{
 	dh_strip
 	dh_makeshlibs
@@ -390,9 +419,11 @@ 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];
+# The binary sequences will call 'debian/rules install' before running
+# the standard sequence.
+$sequences{binary} = ['rules:install', 'rules:binary-arch', 'rules:binary-indep'];
+$sequences{'binary-indep'} = ['rules:install-indep', @b];
+$sequences{'binary-arch'} = ['rules:install-arch', @ba, @b];
 
 # Additional command options
 my %command_opts;
@@ -641,11 +672,29 @@ sub run {
 	# to prevent them from being acted on.
 	push @options, map { "-N$_" } @exclude;
 
+	# If the command has a rules: prefix, run debian/rules with
+	# the remainder as the target.
+	my $rules_target = undef;
+	if ($command =~ /^rules:(.*)/) {
+		$rules_target = $1;
+	}
+
 	# Check for override targets in debian/rules and
 	# run them instead of running the command directly.
 	my $override_command;
 	my $has_explicit_target = rules_explicit_target("override_".$command);
-	if (defined $has_explicit_target) {
+
+	if (defined $rules_target) {
+		# Don't pass DH_ environment variables, since this is
+		# a fresh invocation of debian/rules and any sub-dh
+		# commands.
+		$override_command=$command;
+		delete $ENV{DH_INTERNAL_OPTIONS};
+		delete $ENV{DH_INTERNAL_OVERRIDE};
+		$command="debian/rules";
+		@options=$rules_target;
+	}
+	elsif (defined $has_explicit_target) {
 		$override_command=$command;
 		# Check if target isn't noop
 		if ($has_explicit_target) {
-- 
1.7.5.4

From 8389c4637193c706698782de232f75b52ae1f8d2 Mon Sep 17 00:00:00 2001
From: Roger Leigh <[email protected]>
Date: Sun, 12 Jun 2011 20:22:43 +0100
Subject: [PATCH 2/2] dh: Use minimal sequences if delegating work

The build and install rules run a minimal sequence if the build-arch or
build-indep, or install-arch or install-indep targets, respectively,
are present in debian/rules.  The purpose is to not do work ahead of
time, such as building before the build-arch or build-indep targets are
built, which could potentially lead to misbuilds.  If the targets are
not defined, the sequences may be run directly which is faster due to
being able to run the arch and indep commands together.
---
 dh |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/dh b/dh
index 75070ea..48fcfec 100755
--- a/dh
+++ b/dh
@@ -338,6 +338,10 @@ if (is_make_jobserver_unavailable()) {
 
 # Definitions of sequences.
 my %sequences;
+my @bd_minimal = qw{
+	dh_testdir
+	dh_auto_configure
+};
 my @bd = qw{
 	dh_testdir
 	dh_auto_configure
@@ -350,6 +354,12 @@ my @bd = qw{
 # to be customised by the user and still run as a side-effect of the
 # build target.
 $sequences{build} = [@bd, 'rules:build-arch', 'rules:build-indep'];
+# If debian/rules defines build-arch or build-indep, run sequences
+# separately.
+if (rules_explicit_target('build-arch') ||
+    rules_explicit_target('build-arch')) {
+    $sequences{build} = [@bd_minimal, 'rules:build-arch', 'rules:build-indep'];
+}
 $sequences{'build-indep'} = [@bd];
 $sequences{'build-arch'} = [@bd];
 $sequences{clean} = [qw{
@@ -357,6 +367,9 @@ $sequences{clean} = [qw{
 	dh_auto_clean
 	dh_clean
 }];
+my @i_minimal = qw{
+	dh_testroot
+};
 my @i = qw{
 	dh_testroot
 	dh_prep
@@ -406,6 +419,10 @@ my @i = qw{
 # install-indep targets to be customised by the user and still run as
 # a side-effect of the install target.
 $sequences{'install'} = ['rules:build', @i, 'rules:install-arch', 'rules:install-indep'];
+if (rules_explicit_target('build-arch') ||
+    rules_explicit_target('build-arch')) {
+	$sequences{'install'} = ['rules:build', @i_minimal, 'rules:install-arch', 'rules:install-indep'];
+}
 $sequences{'install-indep'} = ['rules:build-indep', @i];
 $sequences{'install-arch'} = ['rules:build-arch', @i];
 my @ba=qw{
-- 
1.7.5.4

Attachment: signature.asc
Description: Digital signature

Reply via email to