]> git.donarmstrong.com Git - debhelper.git/commitdiff
dh is now working
authorJoey Hess <joey@kodama.kitenet.net>
Thu, 24 Apr 2008 00:16:52 +0000 (20:16 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Thu, 24 Apr 2008 00:16:52 +0000 (20:16 -0400)
And debian/rules uses it.

Sweet!

Debian/Debhelper/Dh_Getopt.pm
debian/changelog
debian/rules
dh

index 0b105244c012b9ee0d0ea2874df776a219077414..55e37fd22a86ec42bd7fb974306308139a3a5d30 100644 (file)
@@ -177,8 +177,8 @@ sub parseopts {
                "language=s" => \$options{LANGUAGE},
 
                "until=s" => \$options{UNTIL},
-               "before=s" => \$options{BEFORE},
                "after=s" => \$options{AFTER},
+               "before=s" => \$options{BEFORE},
                "remaining" => \$options{REMAINING},
 
                "<>" => \&NonOption,
index 692b4ea73aa52ea0cf91f770456821260c20f9a8..eb654ceb8e757c65a1384a1b7ab4021026655d4c 100644 (file)
@@ -24,6 +24,10 @@ debhelper (7.0.0) UNRELEASED; urgency=low
     debian/tmp, and then will look in the current directory. This allows
     dh_install to interoperate with dh_auto_install without needing any
     special parameters.
+  * dh: New program that runs a series of debhelper commands in a sequence.
+    This can be used to construct very short rules files (as short as 3
+    lines), while still exposing the full power of debhelper when it's
+    needed.
   * Add a Makefile and simplify this package's own rules file using
     all the new toys.
 
index 9a90b2d64616534acbe560be52d752400fd357e6..5b8fd17cd265d1e2c3f19958b097d820d62f77c6 100755 (executable)
@@ -2,40 +2,9 @@
 # Each debhelper command in this rules file has to be run using ./run,
 # to ensure that the commands and libraries in the source tree are used,
 # rather than the installed ones.
-
-build:
-       ./run dh_auto_configure
-       ./run dh_auto_build
-       ./run dh_auto_test
-
-clean:
-       ./run dh_testdir
-       ./run dh_testroot
-       ./run dh_auto_clean
-       ./run dh_clean
-
-binary-indep: build
-       ./run dh_testdir
-       ./run dh_testroot
-       ./run dh_clean -k
-       ./run dh_auto_install
-       ./run dh_installdocs
-       ./run dh_installexamples
-       ./run dh_installman
-       ./run dh_installchangelogs
-       ./run dh_link
-       ./run dh_compress
-       ./run dh_fixperms
-       ./run dh_perl
-       ./run dh_installdeb
-       ./run dh_gencontrol
-       ./run dh_md5sums
-       ./run dh_builddeb
+%:
+       ./run dh $@
 
 # Not intended for use by anyone except the author.
 announcedir:
        @echo ${HOME}/src/joeywiki/code/debhelper/news
-
-binary-arch:
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary
diff --git a/dh b/dh
index e5a43a9ad926ca63a80790a1510a3dc8cc7f4281..15e922c496b49a9236d6cd6e8547df35fa2f0b8b 100755 (executable)
--- a/dh
+++ b/dh
@@ -58,19 +58,45 @@ Run commands in the sequence that come after I<cmd>.
 
 Run all commands in the sequence that have yet to be run.
 
-=head1 COMMAND SPECIFICATON
+=head1 COMMAND SPECIFICATION
 
 I<cmd> can be a full name of a debhelper command, or a substring. It'll first
 search for a command in the sequence exactly matching the name, to avoid any
 ambiguity. If there are multiple substring matches, the last one in the
 sequence will be used.
 
+=cut
+
+sub command_pos {
+       my $command=shift;
+       my @sequence=@_;
+
+       foreach my $i (0..$#sequence) {
+               if ($command eq $sequence[$i]) {
+                       return $i;
+               }
+       }
+
+       my @matches;
+       foreach my $i (0..$#sequence) {
+               if ($sequence[$i] =~ /\Q$command\E/) {
+                       push @matches, $i;
+               }
+       }
+       if (! @matches) {
+               error "command specification \"$command\" does not match any command in the sequence"
+       }
+       else {
+               return pop @matches;
+       }
+}
+
 =head1 EXAMPLES
 
 To see what commands are included in a sequence, without actually doing
 anything:
 
-       dh binary-arch -n
+       dh binary-arch --no-act
 
 This is a very simple rules file, for packages where the default seqences of
 commands work with no additional options.
@@ -160,7 +186,9 @@ $sequences{clean} = [qw{
        dh_auto_clean
        dh_clean
 }];
-$sequences{install} = [@{$sequences{build}}, "dh_testroot", "dh_clean -k", qw{
+$sequences{install} = [@{$sequences{build}}, qw{
+       dh_testroot
+       dh_clean
        dh_installdirs
        dh_auto_install
 
@@ -181,6 +209,8 @@ $sequences{install} = [@{$sequences{build}}, "dh_testroot", "dh_clean -k", qw{
        dh_installmenu
        dh_installmime
        dh_installmodules
+       dh_installlogcheck
+       dh_installlogrotate
        dh_installpam
        dh_installppp
        dh_installudev
@@ -190,12 +220,10 @@ $sequences{install} = [@{$sequences{build}}, "dh_testroot", "dh_clean -k", qw{
        dh_desktop
        dh_gconf
        dh_icons
-       dh_logcheck
-       dh_logrotate
        dh_perl
        dh_python
        dh_scrollkeeper
-       dh_uselocal
+       dh_usrlocal
 
        dh_link
        dh_compress
@@ -214,7 +242,7 @@ $sequences{binary} = [@{$sequences{install}}, qw{
 }, @b];
 $sequences{'binary-arch'} = [@{$sequences{binary}}];
 
-# Sequence parameter.
+# Get the sequence of commands to run.
 if (! @ARGV) {
        error "specify a sequence to run";
 }
@@ -223,6 +251,7 @@ if (! exists $sequences{$sequence}) {
        error "Unknown sequence $sequence (chose from: ".
                join(" ", sort keys %sequences).")";
 }
+my @sequence=@{$sequences{$sequence}};
 
 # Get the options to pass to commands in the sequence.
 # Filter out options intended only for this program.
@@ -246,17 +275,103 @@ while (@ARGV_orig) {
        push @options, $opt;
 }
 
-@options=grep {
-       $_ ne $sequence && !/^--?(before|after|remaining)$/
-} @options;
+# Figure out at what point in the sequence to start for each package.
+my %logged;
+my %startpoint;
+foreach my $package (@{$dh{DOPACKAGES}}) {
+       if ($dh{AFTER}) {
+               # Run commands in the sequence that come after the
+               # specified command.
+               $startpoint{$package}=command_pos($dh{AFTER}, @sequence) + 1;
+       }
+       elsif ($dh{REMAINING}) {
+               # Start at the beginning so all remaining commands will get
+               # run.
+               $startpoint{$package}=0;
+       }
+       else {
+               # Find the last logged command that is in the sequence, and
+               # continue with the next command after it. If no logged
+               # command is in the sequence, we're starting at the beginning..                         
+               my @log=loadlog($package);
+               $startpoint{$package}=0;
+COMMAND:       foreach my $command (reverse @log) {
+                       foreach my $i (0..$#sequence) {
+                               if ($command eq $sequence[$i]) {
+                                       $startpoint{$package}=$i+1;
+                                       last COMMAND;
+                               }
+                       }
+               }
+       }
+}
+
+# Figure out what point in the sequence to go to.
+my $stoppoint=$#sequence;
+if ($dh{UNTIL}) {
+       $stoppoint=command_pos($dh{UNTIL}, @sequence);
+}
+elsif ($dh{BEFORE}) {
+       $stoppoint=command_pos($dh{BEFORE}, @sequence) - 1;
+}
+
+# Now run the commands in the sequence.
+foreach my $i (0..$stoppoint) {
+       # Figure out which packages need to run this command.
+       my @exclude;
+       foreach my $package (@{$dh{DOPACKAGES}}) {
+               if ($startpoint{$package} > $i ||
+                   $logged{$package}{$sequence[$i]}) {
+                       push @exclude, $package;
+               }
+       }
+       
+       if (@exclude eq @{$dh{DOPACKAGES}}) {
+               # Command already done for all packages.
+               next;
+       }
+       elsif (! @exclude) {
+               # Run command for all packages.
+               run($sequence[$i], @options);
+       }
+       else {
+               # Run command for only a subset of packages.
+               run($sequence[$i], @options,
+                       map { "-N$_" } @exclude);
+       }
+}
+
+sub run {
+       my $command=shift;
+       my @options=@_;
+       
+       # dh_clean -k is a special case
+       if ($command eq 'dh_clean' && $sequence ne 'clean') {
+               unshift @options, "-k";
+       }
+
+       # The 4 spaces is a kind of half indent.
+       print "    ".escape_shell($command, @options)."\n";
 
-foreach my $cmd (@{$sequences{$sequence}}) {
-       print "$cmd @options\n";
+       if (! $dh{NO_ACT}) {
+               my $ret=system($command, @options);
+               exit($ret) if $ret != 0;
+       }
 }
 
-foreach my $package (@{$dh{DOPACKAGES}}) {
-       my $tmp=tmpdir($package);
+sub loadlog {
+       my $package=shift;
        my $ext=pkgext($package);
+       
+       my @log;
+       open(LOG, "<", "debian/${ext}log.debhelper");
+       while (<LOG>) {
+               chomp;
+               push @log, $_;
+               $logged{$package}{$_}=1;
+       }
+       close LOG;
+       return @log;
 }
 
 =head1 SEE ALSO