From 0a47c6cde2c9bca0f650b8731bb9fd11a7797f9e Mon Sep 17 00:00:00 2001 From: joey Date: Tue, 17 Aug 1999 04:56:57 +0000 Subject: r109: Initial Import --- Dh_Getopt.pm | 34 +++++---------- Dh_Lib.pm | 119 ++++++++++++++++++++++++++++++++++------------------- debian/changelog | 15 +++++++ dh_getopt.pl | 25 ++++++++++- dh_installdocs | 4 +- dh_installexamples | 48 ++++++++++----------- dh_movefiles | 4 +- doc/TODO | 17 ++++---- 8 files changed, 163 insertions(+), 103 deletions(-) diff --git a/Dh_Getopt.pm b/Dh_Getopt.pm index eb6aef98..85f0e15b 100644 --- a/Dh_Getopt.pm +++ b/Dh_Getopt.pm @@ -7,12 +7,12 @@ package Dh_Getopt; use strict; -use Exporter; -my @ISA=qw(Exporter); -my @EXPORT=qw(&parseopts); - use Dh_Lib; use Getopt::Long; +use Exporter; +#use vars qw{@ISA @EXPORT}; +#@ISA=qw(Exporter); +#@EXPORT=qw(&aparseopts); # FIXME: for some reason, this doesn't work. my (%options, %exclude_package); @@ -46,11 +46,6 @@ sub AddExclude { my($option,$value)=@_; push @{$options{EXCLUDE}},$value; } -sub import { - # Enable bundling of short command line options. - Getopt::Long::config("bundling"); -} - # Parse options and return a hash of the values. sub parseopts { undef %options; @@ -72,8 +67,8 @@ sub parseopts { "no-package=s" => \&ExcludePackage, "n" => \$options{NOSCRIPTS}, -# "noscripts" => \$options(NOSCRIPTS}, - + "noscripts" => \$options{NOSCRIPTS}, + "x" => \$options{INCLUDE_CONFFILES}, # is -x for some unknown historical reason.. "include-conffiles" => \$options{INCLUDE_CONFFILES}, @@ -120,18 +115,6 @@ sub parseopts { $options{V_FLAG_SET}=1; } - # Check to see if DH_VERBOSE environment variable was set, if so, - # make sure verbose is on. - if ($ENV{DH_VERBOSE} ne undef) { - $options{VERBOSE}=1; - } - - # Check to see if DH_NO_ACT environment variable was set, if so, - # make sure no act mode is on. - if ($ENV{DH_NO_ACT} ne undef) { - $options{NO_ACT}=1; - } - # Remove excluded packages from the list of packages to act on. my @package_list; my $package; @@ -145,4 +128,9 @@ sub parseopts { return %options; } +sub import { + # Enable bundling of short command line options. + Getopt::Long::config("bundling"); +} + 1 diff --git a/Dh_Lib.pm b/Dh_Lib.pm index c9b964c1..c58d5c08 100644 --- a/Dh_Lib.pm +++ b/Dh_Lib.pm @@ -5,9 +5,10 @@ # Joey Hess, GPL copyright 1997, 1998. package Dh_Lib; +use strict; use Exporter; -use vars qw(%dh); +use vars qw(@ISA @EXPORT %dh); @ISA=qw(Exporter); @EXPORT=qw(&init &doit &complex_doit &verbose_print &error &warning &tmpdir &pkgfile &pkgext &isnative &autoscript &filearray &GetPackages @@ -18,6 +19,7 @@ sub init { # if so, we need to pass this off to the resource intensive Getopt::Long, # which I'd prefer to avoid loading at all if possible. my $parseopt=undef; + my $arg; foreach $arg (@ARGV) { if ($arg=~m/^-/) { $parseopt=1; @@ -30,6 +32,18 @@ sub init { %dh=Dh_Getopt::parseopts(); } + # Check to see if DH_VERBOSE environment variable was set, if so, + # make sure verbose is on. + if (defined $ENV{DH_VERBOSE} && $ENV{DH_VERBOSE} ne "") { + $dh{VERBOSE}=1; + } + + # Check to see if DH_NO_ACT environment variable was set, if so, + # make sure no act mode is on. + if (defined $ENV{DH_NO_ACT} && $ENV{DH_NO_ACT} ne "") { + $dh{NO_ACT}=1; + } + # Get the name of the main binary package (first one listed in # debian/control). my @allpackages=GetPackages(); @@ -37,17 +51,19 @@ sub init { # Check if packages to build have been specified, if not, fall back to # the default, doing them all. - if (! @{$dh{DOPACKAGES}}) { - if ($dh{DH_DOINDEP} || $dh{DH_DOARCH}) { - error("I have no package to build."); + if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) { + if ($dh{DOINDEP} || $dh{DOARCH}) { + # User specified that all arch (in)dep package be + # built, and there are none of that type. + error("I have no package to build"); } push @{$dh{DOPACKAGES}},@allpackages; } # Check to see if -P was specified. If so, we can only act on a single # package. - if ($dh{TMPDIR} || $#{$dh{DOPACKAGES}} > 0) { - error("-P was specified, but multiple packages would be acted on."); + if ($dh{TMPDIR} && $#{$dh{DOPACKAGES}} > 0) { + error("-P was specified, but multiple packages would be acted on (".join(",",@{$dh{DOPACKAGES}}).")."); } # Figure out which package is the first one we were instructed to build. @@ -63,7 +79,7 @@ sub init { # Note that this cannot handle complex commands, especially anything # involving redirection. Use complex_doit instead. sub doit { - verbose_print(join(" ",,@_)); + verbose_print(join(" ",@_)); if (! $dh{NO_ACT}) { system(@_) == 0 @@ -72,10 +88,18 @@ sub doit { } } -# This is an identical command to doit, except the parameters passed to it -# can include complex shell stull like redirection and compound commands. +# Run a command and display the command to stdout if verbose mode is on. +# Use doit() if you can, instead of this function, because this function +# forks a shell. However, this function can handle more complicated stuff +# like redirection. sub complex_doit { - error("complex_doit() not yet supported"); + verbose_print(join(" ",@_)); + + if (! $dh{NO_ACT}) { + # The join makes system get a scalar so it forks off a shell. + system(join(" ",@_)) == 0 + || error("command returned error code"); + } } # Print something if the verbose flag is on. @@ -93,9 +117,14 @@ sub error { my $message=shift; # Output a warning. sub warning { my $message=shift; + print STDERR basename().": $message\n"; +} + +# Returns the basename of the program. +sub basename { my $fn=$0; $fn=~s:.*/(.*?):$1:; - print STDERR "$fn: $message\n"; + return $fn; } # Pass it a name of a binary package, it returns the name of the tmp dir to @@ -132,7 +161,7 @@ sub pkgfile { my $package=shift; my $filename=shift; # Pass it a name of a binary package, it returns the name to prefix to files # in debian for this package. sub pkgext { my $package=shift; - if ($package ne $MAINPACKAGE) { + if ($package ne $dh{MAINPACKAGE}) { return "$package."; } return ""; @@ -173,40 +202,45 @@ sub pkgext { my $package=shift; # Only works if the script has #DEBHELPER# in it. # # Parameters: -# 1: script to add to -# 2: filename of snippet -# 3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/ -sub autoscript { +# 1: package +# 2: script to add to +# 3: filename of snippet +# 4: sed to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/ +sub autoscript { my $package=shift; my $script=shift; my $filename=shift; my $sed=shift; error "autoscript() not yet implemented (lazy, lazy!)"; -# autoscript_script=$1 -# autoscript_filename=$2 -# autoscript_sed=$3 -# autoscript_debscript=debian/`pkgext $PACKAGE`$autoscript_script.debhelper -# -# if [ -e "$DH_AUTOSCRIPTDIR/$autoscript_filename" ]; then -# autoscript_filename="$DH_AUTOSCRIPTDIR/$autoscript_filename" -# else -# if [ -e "/usr/lib/debhelper/autoscripts/$autoscript_filename" ]; then -# autoscript_filename="/usr/lib/debhelper/autoscripts/$autoscript_filename" -# else -# error "/usr/lib/debhelper/autoscripts/$autoscript_filename does not exist" -# fi -# fi -# -# complex_doit "echo \"# Automatically added by `basename $0`\" >> $autoscript_debscript" -# complex_doit "sed \"$autoscript_sed\" $autoscript_filename >> $autoscript_debscript" -# complex_doit "echo '# End automatically added section' >> $autoscript_debscript" + + # This is the file we will append to. + my $outfile="debian/".pkgext($package)."$script.debhelper"; + + # Figure out what shell script snippet to use. + my $infile; + if ( -e "$main::ENV{DH_AUTOSCRIPTDIR}/$filename" ) { + $infile="$main::ENV{DH_AUTOSCRIPTDIR}/$filename"; + } + else { + if ( -e "/usr/lib/debhelper/autoscripts/$filename" ) { + $infile="/usr/lib/debhelper/autoscripts/$filename"; + } + else { + error("/usr/lib/debhelper/autoscripts/$filename does not exist"); + } + } + + # TODO: do this in perl, perhaps? + complex_doit("echo \"# Automatically added by ".basename().">> $outfile"); + complex_doit("sed \"$sed\" $infile >> $outfile"); + complex_doit("echo '# End automatically added section' >> $outfile"); } # Reads in the specified file, one word at a time, and returns an array of # the result. -sub filearray { $file=shift; +sub filearray { my $file=shift; my @ret; open (DH_FARRAY_IN,"<$file") || error("cannot read $file: $1"); while () { push @ret,split(/\s/,$_); } - close DH_ARRAY; + close DH_FARRAY_IN; return @ret; } @@ -214,10 +248,11 @@ sub filearray { $file=shift; # Returns a list of packages in the control file. # Must pass "arch" or "indep" to specify arch-dependant or -independant # packages. If nothing is specified, returns all packages. -sub GetPackages { $type=shift; - my $package; - my $arch; - my @list; +sub GetPackages { my $type=shift; + $type="" if ! defined $type; + my $package=""; + my $arch=""; + my @list=(); open (CONTROL,") { @@ -235,8 +270,8 @@ sub GetPackages { $type=shift; ($type eq 'arch' && $arch ne 'all') || ! $type)) { push @list, $package; - undef $package; - undef $arch; + $package=""; + $arch=""; } } } diff --git a/debian/changelog b/debian/changelog index 9d4a6a4e..22b55879 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +debhelper (1.1.3) unstable; urgency=low + + * dh_md5sums: -x was broken since version 1.1.1 - fixed. + * dh_lib: removed get_arch_indep_packages() function that hasn't been used + at all for a long while. + * Added Dh_Lib.pm, a translation of dh_lib into perl. + * dh_getopt.pl: moved most of it into new Dh_Getopt.pm module, rewriting + large chunks in the process. + * dh_installdocs: completly rewritten in perl. Now it's faster and it can + install many oddly named files it died on before. + * dh_installdocs: fixed a bug that installed TODO files mode 655 in native + debian packages. + + -- Joey Hess Mon, 10 Aug 1998 15:01:15 -0700 + debhelper (1.1.2) unstable; urgency=low * dh_strip: added -X to specify files to not strip (#25590). diff --git a/dh_getopt.pl b/dh_getopt.pl index 4abe9160..b1dcf7b1 100755 --- a/dh_getopt.pl +++ b/dh_getopt.pl @@ -7,6 +7,7 @@ # Joey Hess, GPL copyright 1998. BEGIN { push @INC, "debian", "/usr/lib/debhelper" } +use strict; use Dh_Getopt; # This is a tricky (and nasty) bit: override the error() function, which @@ -18,7 +19,7 @@ sub Dh_Getopt::error { my $message=shift; } # Parse options. -%options=Dh_Getopt::parseopts(); +my %options=Dh_Getopt::parseopts(); # Change a few lists in %options into strings, # generate some options that only need to be visible to the @@ -33,8 +34,28 @@ if ($#{$options{EXCLUDE}} > -1) { } $options{EXCLUDE}=join " ",@{$options{EXCLUDE}}; +# Check to see if DH_VERBOSE environment variable was set, if so, +# make sure verbose is on. +if (defined $main::ENV{DH_VERBOSE}) { + if ($main::ENV{DH_VERBOSE} ne undef) { + $options{VERBOSE}=1; + } +} + +# Check to see if DH_NO_ACT environment variable was set, if so, +# make sure no act mode is on. +if (defined $main::ENV{DH_NO_ACT}) { + if ($main::ENV{DH_NO_ACT} ne undef) { + $options{NO_ACT}=1; + } +} + # Now output everything, in a format suitable for a shell to eval it. -foreach (keys(%options)) { print "DH_$_='$options{$_}'\n" }; +foreach (keys(%options)) { + if (defined $options{$_}) { + print "DH_$_='$options{$_}'\n"; + } +} # This sets $@ in the shell to whatever arguements remain. print "set -- @ARGV\n" diff --git a/dh_installdocs b/dh_installdocs index f4662431..3229cd15 100755 --- a/dh_installdocs +++ b/dh_installdocs @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # # Reads debian/docs, installs all files listed there into /usr/doc/$PACKAGE # Also installs the debian/copyright and debian/README.debian and debian/TODO @@ -21,7 +21,7 @@ foreach $PACKAGE (@{$dh{DOPACKAGES}}) { @docs=filearray($file); } - if (($PACKAGE = $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) { + if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) { push @docs, @ARGV; } diff --git a/dh_installexamples b/dh_installexamples index 623d882b..88e964ba 100755 --- a/dh_installexamples +++ b/dh_installexamples @@ -1,31 +1,31 @@ -#!/bin/sh -e +#!/usr/bin/perl -w # # Reads debian/examples, installs all files listed there into # /usr/doc/$PACKAGE/examples -PATH=debian:$PATH:/usr/lib/debhelper -. dh_lib +BEGIN { push @INC, "debian", "/usr/lib/debhelper" } +use Dh_Lib; +init(); -for PACKAGE in $DH_DOPACKAGES; do - TMP=`tmpdir $PACKAGE` - file=`pkgfile $PACKAGE examples` +foreach $PACKAGE (@{$dh{DOPACKAGES}}) { + $TMP=tmpdir($PACKAGE); + $file=pkgfile($PACKAGE,"examples"); + + undef @examples; + + if ($file) { + @examples=filearray($file); + } - examples="" + if (($PACKAGE eq $dh{FIRSTPACKAGE} || $dh{PARAMS_ALL}) && @ARGV) { + push @examples, @ARGV; + } - if [ "$file" ]; then - examples=`tr "\n" " " < $file` - fi - - if [ \( "$PACKAGE" = "$DH_FIRSTPACKAGE" -o "$DH_PARAMS_ALL" \) \ - -a "$*" ]; then - examples="$* $examples" - fi - - if [ "$examples" ]; then - if [ ! -d $TMP/usr/doc/$PACKAGE/examples ]; then - doit "install -d $TMP/usr/doc/$PACKAGE/examples" - fi - - doit "cp -a $examples $TMP/usr/doc/$PACKAGE/examples/" - fi -done + if (@examples) { + if (! -d "$TMP/usr/doc/$PACKAGE/examples") { + doit("install","-d","$TMP/usr/doc/$PACKAGE/examples"); + } + + doit("cp","-a",@examples,"$TMP/usr/doc/$PACKAGE/examples"); + } +} diff --git a/dh_movefiles b/dh_movefiles index f44121c8..ba482050 100755 --- a/dh_movefiles +++ b/dh_movefiles @@ -44,13 +44,13 @@ for PACKAGE in $DH_DOPACKAGES; do # moved. doit "rm -f movelist" for i in `(cd debian/tmp; echo $tomove)`; do - if [ ! -e "debian/tmp/$i" ]; then + if [ ! -e "debian/tmp/$i" -o -L "debian/tmp/$i" ]; then fail=1 fi complex_doit "(cd debian/tmp ; find $i ! -type d -and ! -type l -print || true) >> movelist" done for i in `(cd debian/tmp; echo $tomove)`; do - if [ ! -e "debian/tmp/$i" ]; then + if [ ! -e "debian/tmp/$i" -o -L "debian/tmp/$i" ]; then fail=1 fi complex_doit "(cd debian/tmp ; find $i ! -type d -and -type l -print || true) >> movelist" diff --git a/doc/TODO b/doc/TODO index e3042fbc..756eb4bd 100644 --- a/doc/TODO +++ b/doc/TODO @@ -3,11 +3,9 @@ list grows - I welcome patches to fix items on it! Bugs: -* dh_installdocs fails if debian/docs is empty except for a blank line. - There are probably other instances of this. Debhelper should behave better - (#24686). * all commands should print a warning message if non-cumulative parameters - are given more than once (ie, two -u's to dh_gencontrol). + are given more than once (ie, two -u's to dh_gencontrol). (#22588) + (Bug currently under dispute, I think this is bogus). Wishlist items: @@ -58,13 +56,16 @@ Depricated: * remove dh_installdebfiles, dh_du. - need to wait a reasonable length of time. I'm currently planning - on doing this after slink is released. + on doing this after slink is released or one year after they were + depricated, whichever comes first. Be sure to grep whole debian + archive for alls to them before removing them, though! Long term goals: -Convert selected debhelper commands (dh_installmanpages?) to be perl -programs, for speed, ease of maintainence, and 8-bit cleanness. +* Convert selected debhelper commands to be perl programs, for speed, ease + of maintainence, and 8-bit cleanness. Fixes to backport to 1.0 tree: -* dh_installdocs used -m 655 for a TODO file. +* dh_installdocs used -m 655 for a TODO file. (minor, dh_fixperms cleans up + after it) -- cgit v1.2.3