Hello,

On pirmadienis 24 Rugpjūtis 2009 21:54:00 Joey Hess wrote:
> Modestas Vainius wrote:
> > the attached patch adds dh addons add_command_arguments() API that allows
> > addons to specify additional arguments which dh will run the specified
> > debhelper command(s) with.
> >
> > I think this could be useful to develop dh addons that would serve as
> > templates. For example, a large group of packages (e.g. KDE) needs to run
> > dh_compress -Xfoobar rather than dh_compress. Currently, there is no way
> > (neither via make includes, nor dh addons unless I'm missing something)
> > to provide the following functionality:
> >
> > 1) Run `dh_compress -Xfoobar` by default.
> > 2) Clearly allow to override this in debian/rules if needed.
> >
> > If this was done via addons, 1) would be configured via addon and 2)
> > would be possible via usual dh overrides.
>
> haskell_devscripts does the following:
>
> insert_before("dh_compress", "dh_compress -X.haddock");
> remove_command("dh_compress");
>
> That's a nasty hack that probably breaks both command logging and overrides
> now that I think about it.

Exactly, I thought about that initially but it breaks overrides and logging 
hence not acceptable.

> Re your patch, it would probably be clearer to have a
> remove_command_arguments rather than having add () clear. It *might*
> make sense for remove_command_arguments to allow removing only specific
> arguments. Although it two sequence addons get into a situation needing
> removal, they're doing something bad and probably failure prone.

Implemented.

> My other concern is that the added arguments are passed via
> DH_INTERNAL_OPTIONS. So if a override target is used, all commands run
> in it will get the arguments passed in it, with no way to override that.
> This could be fixed by only adding to @options after the override command
> block.

Right. Actually, I didn't intend those arguments to be passed via 
DH_INTERNAL_OPTIONS, that was a bug. Thanks for catching.

> Oh, and don't forget to update doc/PROGRAMMING..
Sure.

A new patch is attached. I also did s/arguments/options/ everywhere since 
'option' is more in-line with debhelper terminology.

-- 
Modestas Vainius <[email protected]>
From: Modestas Vainius <[email protected]>
Subject: [PATCH] Allow dh addons to pass options to debhelper commands

Add dh addons APIs add_command_options()/remove_command_options() that
allow addons to add additional options which dh will pass to the specified
debhelper commands.

Signed-off-by: Modestas Vainius <[email protected]>

---
 dh              |   32 ++++++++++++++++++++++++++++++++
 doc/PROGRAMMING |   14 ++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/dh b/dh
index bdd78c5..f03bf00 100755
--- a/dh
+++ b/dh
@@ -293,6 +293,9 @@ $sequences{binary} = [...@{$sequences{install}}, qw{
 }, @b];
 $sequences{'binary-arch'} = [...@{$sequences{binary}}];
 
+# Additional command options
+my %command_opts;
+
 # sequence addon interface
 sub _insert {
 	my $offset=shift;
@@ -333,6 +336,31 @@ sub add_command {
 	my $sequence=shift;
 	unshift @{$sequences{$sequence}}, $command;
 }
+sub add_command_options {
+	my $command=shift;
+	push @{$command_opts{$command}}, @_;
+}
+sub remove_command_options {
+	my $command=shift;
+	if (@_) {
+		# Remove only specified options
+		if (my $opts = $command_opts{$command}) {
+			foreach my $opt (@_) {
+				if (ref($opt) eq "Regexp") {
+					$opts = [ grep ! /$opt/, @$opts ];
+				}
+				else {
+					$opts = [ grep { $_ ne $opt } @$opts ];
+				}
+			}
+			$command_opts{$command} = $opts;
+		}
+	}
+	else {
+		# Clear all additional options
+		delete $command_opts{$command};
+	}
+}
 
 if ($dh{LIST}) {
 	my %addons;
@@ -501,6 +529,10 @@ sub run {
 		$command="debian/rules";
 		@options="override_".$override_command;
 	}
+	else {
+		# Pass additional command options if any
+		unshift @options, @{$command_opts{$command}} if exists $command_opts{$command};
+	}
 
 	# 3 space indent lines the command being run up under the 
 	# sequence name after "dh ".
diff --git a/doc/PROGRAMMING b/doc/PROGRAMMING
index 4be09b1..211e57e 100644
--- a/doc/PROGRAMMING
+++ b/doc/PROGRAMMING
@@ -270,6 +270,20 @@ add_command($new_command, $sequence)
 	Add $new_command to the beginning of the specified sequence.
 	If the sequence does not exist, it will be created.
 
+add_command_options($command, $opt1, $opt2, ...)
+	Append $opt1, $opt2 etc. to the list of additional options which
+	dh passes when running the specified $command. These options are
+	not relayed to debhelper commands called via $command override.
+
+remove_command_options($command)
+	Clear all additional $command options previously added with
+	add_command_options().
+
+remove_command_options($command, $opt1, $opt2, ...)
+	Remove $opt1, $opt2 etc. from the list of additional options which
+	dh passes when running the specified $command. $optX might be a string
+	or a regular expresion.
+
 Buildsystem Classes:
 -------------------
 
-- 
tg: (aaa7cd5..) patch/cmdopts_via_addons (depends on: master)

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to