From e847eabd3ceca1c46a8611e796fd387f54c105fb Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 11 Oct 2007 04:14:42 +0300 Subject: [PATCH] Switch perl programs to use the new Dpkg/ErrorHandling module --- ChangeLog | 33 +++++++++++++++++++++ debian/changelog | 1 + scripts/822-date.pl | 4 +-- scripts/Dpkg/ErrorHandling.pm | 17 +++++++++-- scripts/changelog/debian.pl | 1 + scripts/controllib.pl | 53 +--------------------------------- scripts/dpkg-architecture.pl | 1 + scripts/dpkg-buildpackage.pl | 4 +-- scripts/dpkg-checkbuilddeps.pl | 1 + scripts/dpkg-distaddfile.pl | 1 + scripts/dpkg-genchanges.pl | 2 ++ scripts/dpkg-gencontrol.pl | 2 ++ scripts/dpkg-gensymbols.pl | 1 + scripts/dpkg-parsechangelog.pl | 4 +-- scripts/dpkg-shlibdeps.pl | 3 +- scripts/dpkg-source.pl | 5 ++-- 16 files changed, 67 insertions(+), 66 deletions(-) mode change 100644 => 100755 scripts/dpkg-buildpackage.pl diff --git a/ChangeLog b/ChangeLog index cb11987c..53f5c89a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,36 @@ +2007-10-11 Guillem Jover + + * scripts/controllib.pl ($warnable_error, $quiet_warnings): Remove + variable declarations. + (failure, syserr, error, internerr, warning, warnerror) + (subprocerr): Remove functions. + (unknown, usageerr): Move functions to ... + * scripts/Dpkg/ErrorHandling.pm: ... here. + (usageerr): Call usage from main::. + (@EXPORT_OK): Add usageerr and unknown. + + * scripts/822-date.pl: Use Dpkg::ErrorHandling. + * scripts/changelog/debian.pl: Likewise. + * scripts/controllib.pl: Likewise. + * scripts/dpkg-architecture.pl: Likewise. + * scripts/dpkg-buildpackage.pl: Likewise. + * scripts/dpkg-checkbuilddeps.pl: Likewise. + * scripts/dpkg-distaddfile.pl: Likewise. + * scripts/dpkg-genchanges.pl: Likewise. + * scripts/dpkg-gencontrol.pl: Likewise. + * scripts/dpkg-gensymbols.pl: Likewise. + * scripts/dpkg-parsechangelog.pl: Likewise. + * scripts/dpkg-shlibdeps.pl: Likewise. + * scripts/dpkg-source.pl: Likewise. + + * scripts/dpkg-buildpackage.pl ($warnable_error): Import from + Dpkg::ErrorHandling instead of declaring as our. + * scripts/dpkg-source.pl ($warnable_error, $quiet_warnings): Likewise. + + * scripts/822-date.pl: Do not require controllib.pl anymore. + * scripts/dpkg-parsechangelog.pl: Likewise. + * scripts/dpkg-shlibdeps.pl: Likewise. + 2007-10-10 Guillem Jover * scripts/Dpkg/ErrorHandling.pm: Use Dpkg. diff --git a/debian/changelog b/debian/changelog index 7e223357..3b851c83 100644 --- a/debian/changelog +++ b/debian/changelog @@ -40,6 +40,7 @@ dpkg (1.14.8) UNRELEASED; urgency=low [ Guillem Jover ] * Use shipped perl modules when calling perl programs at build time. + * Switch perl programs to use the new Dpkg/ErrorHandling module. [ Updated dpkg translations ] * Polish (Robert Luberda). diff --git a/scripts/822-date.pl b/scripts/822-date.pl index aa83d2a9..0a001245 100755 --- a/scripts/822-date.pl +++ b/scripts/822-date.pl @@ -5,12 +5,10 @@ use warnings; use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning); textdomain("dpkg-dev"); -push(@INC, $dpkglibdir); -require 'controllib.pl'; - @ARGV && die _g("Usage: 822-date")."\n"; warning(_g("This program is deprecated. Please use 'date -R' instead.")); diff --git a/scripts/Dpkg/ErrorHandling.pm b/scripts/Dpkg/ErrorHandling.pm index 8601eb51..663927ab 100644 --- a/scripts/Dpkg/ErrorHandling.pm +++ b/scripts/Dpkg/ErrorHandling.pm @@ -4,8 +4,8 @@ use Dpkg; use Dpkg::Gettext; use base qw(Exporter); -our @EXPORT_OK = qw( failure syserr error internerr warning - warnerror subprocerr ); +our @EXPORT_OK = qw(warning warnerror error failure unknown syserr internerr + subprocerr usageerr $warnable_error $quiet_warnings); our $warnable_error = 1; our $quiet_warnings = 0; @@ -31,6 +31,12 @@ sub warnerror } } +sub unknown { + my $field = $_; + warning(sprintf(_g("unknown information field '%s' in input data in %s"), + $field, $_[0])); +} + sub subprocerr { my ($p) = @_; require POSIX; @@ -46,5 +52,12 @@ sub subprocerr { } } +sub usageerr +{ + printf(STDERR "%s: %s\n\n", $progname, "@_"); + # XXX: access to main namespace + main::usage(); + exit(2); +} 1; diff --git a/scripts/changelog/debian.pl b/scripts/changelog/debian.pl index a557009d..85a0b2e3 100755 --- a/scripts/changelog/debian.pl +++ b/scripts/changelog/debian.pl @@ -5,6 +5,7 @@ use warnings; use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(error internerr usageerr); push(@INC,$dpkglibdir); require 'controllib.pl'; diff --git a/scripts/controllib.pl b/scripts/controllib.pl index e7ef8abd..908455fd 100755 --- a/scripts/controllib.pl +++ b/scripts/controllib.pl @@ -7,6 +7,7 @@ use English; use POSIX qw(:errno_h); use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning error failure internerr syserr subprocerr); textdomain("dpkg-dev"); @@ -29,9 +30,6 @@ our @pkg_dep_fields = qw(Pre-Depends Depends Recommends Suggests Enhances our @src_dep_fields = qw(Build-Depends Build-Depends-Indep Build-Conflicts Build-Conflicts-Indep); -our $warnable_error = 1; -our $quiet_warnings = 0; - sub getfowner { @@ -655,57 +653,8 @@ sub parsecdata { return $index; } -sub unknown { - my $field = $_; - warning(sprintf(_g("unknown information field '%s' in input data in %s"), - $field, $_[0])); -} - sub syntax { &error(sprintf(_g("syntax error in %s at line %d: %s"), $whatmsg, $., $_[0])); } -sub failure { die sprintf(_g("%s: failure: %s"), $progname, $_[0])."\n"; } -sub syserr { die sprintf(_g("%s: failure: %s: %s"), $progname, $_[0], $!)."\n"; } -sub error { die sprintf(_g("%s: error: %s"), $progname, $_[0])."\n"; } -sub internerr { die sprintf(_g("%s: internal error: %s"), $progname, $_[0])."\n"; } - -sub warning -{ - if (!$quiet_warnings) { - warn sprintf(_g("%s: warning: %s"), $progname, $_[0])."\n"; - } -} - -sub usageerr -{ - printf(STDERR "%s: %s\n\n", $progname, "@_"); - &usage; - exit(2); -} - -sub warnerror -{ - if ($warnable_error) { - warning(@_); - } else { - error(@_); - } -} - -sub subprocerr { - my ($p) = @_; - require POSIX; - if (POSIX::WIFEXITED($?)) { - die sprintf(_g("%s: failure: %s gave error exit status %s"), - $progname, $p, POSIX::WEXITSTATUS($?))."\n"; - } elsif (POSIX::WIFSIGNALED($?)) { - die sprintf(_g("%s: failure: %s died from signal %s"), - $progname, $p, POSIX::WTERMSIG($?))."\n"; - } else { - die sprintf(_g("%s: failure: %s failed with unknown exit code %d"), - $progname, $p, $?)."\n"; - } -} - 1; diff --git a/scripts/dpkg-architecture.pl b/scripts/dpkg-architecture.pl index 5588976d..ae643d84 100755 --- a/scripts/dpkg-architecture.pl +++ b/scripts/dpkg-architecture.pl @@ -24,6 +24,7 @@ use warnings; use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning syserr usageerr); push(@INC,$dpkglibdir); require 'controllib.pl'; diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl old mode 100644 new mode 100755 index 6e837416..579c1988 --- a/scripts/dpkg-buildpackage.pl +++ b/scripts/dpkg-buildpackage.pl @@ -8,13 +8,13 @@ use File::Basename; use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning error failure syserr subprocerr usageerr + $warnable_error); use Dpkg::BuildOptions; push (@INC, $dpkglibdir); require 'controllib.pl'; -our $warnable_error; - textdomain("dpkg-dev"); sub showversion { diff --git a/scripts/dpkg-checkbuilddeps.pl b/scripts/dpkg-checkbuilddeps.pl index 9e30b84c..6c14ba47 100755 --- a/scripts/dpkg-checkbuilddeps.pl +++ b/scripts/dpkg-checkbuilddeps.pl @@ -7,6 +7,7 @@ use warnings; use Getopt::Long; use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(error); push(@INC,$dpkglibdir); require 'controllib.pl'; diff --git a/scripts/dpkg-distaddfile.pl b/scripts/dpkg-distaddfile.pl index e7ebb329..584ac667 100755 --- a/scripts/dpkg-distaddfile.pl +++ b/scripts/dpkg-distaddfile.pl @@ -7,6 +7,7 @@ use POSIX; use POSIX qw(:errno_h :signal_h); use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(error syserr usageerr); push(@INC,$dpkglibdir); require 'controllib.pl'; diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index d17700b8..ff761240 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -7,6 +7,8 @@ use POSIX; use POSIX qw(:errno_h :signal_h); use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning error failure unknown internerr syserr + subprocerr usageerr); push(@INC,$dpkglibdir); require 'controllib.pl'; diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 140c3cc7..caf40c80 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -7,6 +7,8 @@ use POSIX; use POSIX qw(:errno_h); use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning error failure unknown internerr syserr + subprocerr usageerr); push(@INC,$dpkglibdir); require 'controllib.pl'; diff --git a/scripts/dpkg-gensymbols.pl b/scripts/dpkg-gensymbols.pl index 77189552..ee51c801 100755 --- a/scripts/dpkg-gensymbols.pl +++ b/scripts/dpkg-gensymbols.pl @@ -8,6 +8,7 @@ use Dpkg::Shlibs qw(@librarypaths); use Dpkg::Shlibs::Objdump; use Dpkg::Shlibs::SymbolFile; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning error syserr usageerr); textdomain("dpkg-dev"); diff --git a/scripts/dpkg-parsechangelog.pl b/scripts/dpkg-parsechangelog.pl index 4a2e370c..a95f2136 100755 --- a/scripts/dpkg-parsechangelog.pl +++ b/scripts/dpkg-parsechangelog.pl @@ -7,9 +7,7 @@ use POSIX; use POSIX qw(:errno_h); use Dpkg; use Dpkg::Gettext; - -push(@INC,$dpkglibdir); -require 'controllib.pl'; +use Dpkg::ErrorHandling qw(warning error syserr subprocerr usageerr); textdomain("dpkg-dev"); diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl index 15df7d7f..ab1f9a2d 100755 --- a/scripts/dpkg-shlibdeps.pl +++ b/scripts/dpkg-shlibdeps.pl @@ -7,6 +7,7 @@ use English; use POSIX qw(:errno_h :signal_h); use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning error failure syserr usageerr); use Dpkg::Path qw(relative_to_pkg_root); use Dpkg::Version qw(vercmp); use Dpkg::Shlibs qw(find_library); @@ -20,8 +21,6 @@ chomp $host_arch; my @depfields= qw(Suggests Recommends Depends Pre-Depends); my $i=0; my %depstrength = map { $_ => $i++ } @depfields; -push(@INC, $dpkglibdir); -require 'controllib.pl'; textdomain("dpkg-dev"); my $shlibsoverride= '/etc/dpkg/shlibs.override'; diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index afbd609a..ad4bc045 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -5,6 +5,9 @@ use warnings; use Dpkg; use Dpkg::Gettext; +use Dpkg::ErrorHandling qw(warning warnerror error failure unknown + internerr syserr subprocerr usageerr + $warnable_error $quiet_warnings); my @filesinarchive; my %dirincluded; @@ -109,8 +112,6 @@ require 'controllib.pl'; our (%f, %fi); our $sourcepackage; -our $warnable_error; -our $quiet_warnings; our %substvar; our @src_dep_fields; -- 2.39.5