[dpkg] 128/200: Dpkg::ErrorHandling: Add a new debug() function
Ximin Luo
infinity0 at debian.org
Wed Apr 5 15:17:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository dpkg.
commit 8c6b68c0b0c7d323dbd440f880f2661a2ea58c3b
Author: Guillem Jover <guillem at debian.org>
Date: Thu Jan 26 18:00:11 2017 +0100
Dpkg::ErrorHandling: Add a new debug() function
Switch scripts to use the new function instead of using ad-hoc
implementations.
---
debian/changelog | 1 +
scripts/Dpkg/ErrorHandling.pm | 19 +++++++++++++++++++
scripts/dpkg-gensymbols.pl | 14 ++++++++------
scripts/dpkg-scansources.pl | 8 +++-----
scripts/dpkg-shlibdeps.pl | 39 ++++++++++++++++++++-------------------
5 files changed, 51 insertions(+), 30 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index feff819..03939b2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -28,6 +28,7 @@ dpkg (1.18.19) UNRELEASED; urgency=medium
- Call anonymous subs via -> operator instead of casting with &, and fix
bogus POD documentation to match the code.
- Add new Auto-Built-Package field to Dpkg::Control::Fields.
+ - Add a new debug() reporting function, and switch code to use it.
* Documentation:
- Cleanup software requirements in README.
- Move control member file references from dpkg(1) to deb(5).
diff --git a/scripts/Dpkg/ErrorHandling.pm b/scripts/Dpkg/ErrorHandling.pm
index 122b645..51424ef 100644
--- a/scripts/Dpkg/ErrorHandling.pm
+++ b/scripts/Dpkg/ErrorHandling.pm
@@ -21,6 +21,7 @@ our @EXPORT_OK = qw(
REPORT_PROGNAME
REPORT_COMMAND
REPORT_STATUS
+ REPORT_DEBUG
REPORT_INFO
REPORT_NOTICE
REPORT_WARN
@@ -31,6 +32,7 @@ our @EXPORT_OK = qw(
);
our @EXPORT = qw(
report_options
+ debug
info
notice
warning
@@ -49,6 +51,7 @@ use Dpkg ();
use Dpkg::Gettext;
my $quiet_warnings = 0;
+my $debug_level = 0;
my $info_fh = \*STDOUT;
my $use_color = 0;
@@ -76,6 +79,7 @@ use constant {
REPORT_NOTICE => 5,
REPORT_WARN => 6,
REPORT_ERROR => 7,
+ REPORT_DEBUG => 8,
};
my %report_mode = (
@@ -91,6 +95,12 @@ my %report_mode = (
# part of the interface.
name => 'status',
},
+ REPORT_DEBUG() => {
+ color => 'clear',
+ # We do not translate this name because it is a developer interface
+ # and all debug messages are untranslated anyway.
+ name => 'debug',
+ },
REPORT_INFO() => {
color => 'green',
name => g_('info'),
@@ -116,6 +126,9 @@ sub report_options
if (exists $options{quiet_warnings}) {
$quiet_warnings = $options{quiet_warnings};
}
+ if (exists $options{debug_level}) {
+ $debug_level = $options{debug_level};
+ }
if (exists $options{info_fh}) {
$info_fh = $options{info_fh};
}
@@ -170,6 +183,12 @@ sub report(@)
return "$progname$typename: $msg\n";
}
+sub debug
+{
+ my $level = shift;
+ print report(REPORT_DEBUG, @_) if $level <= $debug_level;
+}
+
sub info($;@)
{
print { $info_fh } report(REPORT_INFO, @_) if not $quiet_warnings;
diff --git a/scripts/dpkg-gensymbols.pl b/scripts/dpkg-gensymbols.pl
index 036f288..09b0aa6 100755
--- a/scripts/dpkg-gensymbols.pl
+++ b/scripts/dpkg-gensymbols.pl
@@ -141,6 +141,8 @@ while (@ARGV) {
}
}
+report_options(debug_level => $debug);
+
umask 0022; # ensure sane default permissions for created files
if (exists $ENV{DPKG_GENSYMBOLS_CHECK_LEVEL}) {
@@ -171,7 +173,7 @@ foreach my $file ($input, $output, "debian/$oppackage.symbols.$host_arch",
'debian/symbols')
{
if (defined $file and -e $file) {
- print "Using references symbols from $file\n" if $debug;
+ debug(1, "Using references symbols from $file");
$symfile->load($file);
$ref_symfile->load($file) if $compare || ! $quiet;
last;
@@ -205,7 +207,7 @@ if (not scalar @files) {
# Merge symbol information
my $od = Dpkg::Shlibs::Objdump->new();
foreach my $file (@files) {
- print "Scanning $file for symbol information\n" if $debug;
+ debug(1, "Scanning $file for symbol information");
my $objid = $od->analyze($file);
unless (defined($objid) && $objid) {
warning(g_("Dpkg::Shlibs::Objdump couldn't parse %s\n"), $file);
@@ -213,13 +215,13 @@ foreach my $file (@files) {
}
my $object = $od->get_object($objid);
if ($object->{SONAME}) { # Objects without soname are of no interest
- print "Merging symbols from $file as $object->{SONAME}\n" if $debug;
+ debug(1, "Merging symbols from $file as $object->{SONAME}");
if (not $symfile->has_object($object->{SONAME})) {
$symfile->create_object($object->{SONAME}, "$oppackage #MINVER#");
}
$symfile->merge_symbols($object, $sourceversion);
} else {
- print "File $file doesn't have a soname. Ignoring.\n" if $debug;
+ debug(1, "File $file doesn't have a soname. Ignoring.");
}
}
$symfile->clear_except(keys %{$od->{objects}});
@@ -239,13 +241,13 @@ if ($stdout) {
}
}
if (defined($output)) {
- print "Storing symbols in $output.\n" if $debug;
+ debug(1, "Storing symbols in $output.");
$symfile->save($output, package => $oppackage,
template_mode => $template_mode,
with_pattern_matches => $verbose_output,
with_deprecated => $verbose_output);
} else {
- print "No symbol information to store.\n" if $debug;
+ debug(1, 'No symbol information to store.');
}
}
diff --git a/scripts/dpkg-scansources.pl b/scripts/dpkg-scansources.pl
index f8c6ea5..70f56a1 100755
--- a/scripts/dpkg-scansources.pl
+++ b/scripts/dpkg-scansources.pl
@@ -70,10 +70,6 @@ my @option_spec = (
'extra-override|e=s' => \$extra_override_file,
);
-sub debug {
- print @_, "\n" if $debug;
-}
-
sub version {
printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
}
@@ -165,7 +161,7 @@ sub load_src_override {
return;
}
- debug "source override file $file";
+ debug(1, "source override file $file");
my $comp_file = Dpkg::Compression::FileHandle->new(filename => $file);
while (<$comp_file>) {
s/#.*//;
@@ -300,6 +296,8 @@ push @ARGV, undef if @ARGV < 2;
push @ARGV, '' if @ARGV < 3;
my ($dir, $override, $prefix) = @ARGV;
+report_options(debug_level => $debug);
+
load_override $override if defined $override;
load_src_override $src_override, $override;
load_override_extra $extra_override_file if defined $extra_override_file;
diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl
index e121aae..892aeff 100755
--- a/scripts/dpkg-shlibdeps.pl
+++ b/scripts/dpkg-shlibdeps.pl
@@ -143,6 +143,8 @@ foreach (@ARGV) {
}
usageerr(g_('need at least one executable')) unless scalar keys %exec;
+report_options(debug_level => $debug);
+
sub ignore_pkgdir {
my $path = shift;
return any { $path =~ /^\Q$_\E/ } @pkg_dir_to_ignore;
@@ -181,7 +183,7 @@ my $error_count = 0;
my $cur_field;
foreach my $file (keys %exec) {
$cur_field = $exec{$file};
- print ">> Scanning $file (for $cur_field field)\n" if $debug;
+ debug(1, ">> Scanning $file (for $cur_field field)");
my $obj = Dpkg::Shlibs::Objdump::Object->new($file);
my @sonames = $obj->get_needed_libraries;
@@ -212,7 +214,7 @@ foreach my $file (keys %exec) {
if ($reallib ne $lib) {
$altlibfiles{$reallib} = $soname;
}
- print "Library $soname found in $lib\n" if $debug;
+ debug(1, "Library $soname found in $lib");
}
}
my $file2pkg = find_packages(keys %libfiles, keys %altlibfiles);
@@ -237,7 +239,7 @@ foreach my $file (keys %exec) {
# Empty package name will lead to consideration of symbols
# file from the package being built only
$file2pkg->{$lib} = [''];
- print "No associated package found for $lib\n" if $debug;
+ debug(1, "No associated package found for $lib");
}
# Load symbols/shlibs files from packages providing libraries
@@ -256,7 +258,7 @@ foreach my $file (keys %exec) {
}
if (defined($symfile_path)) {
# Load symbol information
- print "Using symbols file $symfile_path for $soname\n" if $debug;
+ debug(1, "Using symbols file $symfile_path for $soname");
$symfile_cache{$symfile_path} //=
Dpkg::Shlibs::SymbolFile->new(file => $symfile_path);
$symfile->merge_object_from_symfile($symfile_cache{$symfile_path}, $soname);
@@ -269,11 +271,10 @@ foreach my $file (keys %exec) {
my $dep = $symfile->get_dependency($soname);
my $minver = $symfile->get_smallest_version($soname) || '';
update_dependency_version($dep, $minver);
- print " Minimal version of ($dep) initialized with ($minver)\n"
- if $debug > 1;
+ debug(2, " Minimal version of ($dep) initialized with ($minver)");
} else {
# No symbol file found, fall back to standard shlibs
- print "Using shlibs+objdump for $soname (file $lib)\n" if $debug;
+ debug(1, "Using shlibs+objdump for $soname (file $lib)");
$objdump_cache{$lib} //= Dpkg::Shlibs::Objdump::Object->new($lib);
my $libobj = $objdump_cache{$lib};
my $id = $dumplibs_wo_symfile->add_object($libobj);
@@ -335,7 +336,7 @@ foreach my $file (keys %exec) {
warning(g_('binaries to analyze should already be ' .
"installed in their package's directory"));
}
- print "Analyzing all undefined symbols\n" if $debug > 1;
+ debug(2, 'Analyzing all undefined symbols');
foreach my $sym ($obj->get_undefined_dynamic_symbols()) {
my $name = $sym->{name};
if ($sym->{version}) {
@@ -343,13 +344,13 @@ foreach my $file (keys %exec) {
} else {
$name .= '@' . 'Base';
}
- print " Looking up symbol $name\n" if $debug > 1;
+ debug(2, " Looking up symbol $name");
my %symdep = $symfile->lookup_symbol($name, \@sonames);
if (keys %symdep) {
my $depends = $symfile->get_dependency($symdep{soname},
$symdep{symbol}{dep_id});
- print " Found in symbols file of $symdep{soname} (minver: " .
- "$symdep{symbol}{minver}, dep: $depends)\n" if $debug > 1;
+ debug(2, " Found in symbols file of $symdep{soname} (minver: " .
+ "$symdep{symbol}{minver}, dep: $depends)");
$soname_used{$symdep{soname}}++;
$global_soname_used{$symdep{soname}}++;
if (exists $alt_soname{$symdep{soname}}) {
@@ -361,7 +362,7 @@ foreach my $file (keys %exec) {
} else {
my $syminfo = $dumplibs_wo_symfile->locate_symbol($name);
if (not defined($syminfo)) {
- print " Not found\n" if $debug > 1;
+ debug(2, ' Not found');
next unless ($warnings & WARN_SYM_NOT_FOUND);
next if $disable_warnings;
# Complain about missing symbols only for executables
@@ -389,7 +390,7 @@ foreach my $file (keys %exec) {
}
}
} else {
- print " Found in $syminfo->{soname} ($syminfo->{objid})\n" if $debug > 1;
+ debug(2, " Found in $syminfo->{soname} ($syminfo->{objid})");
if (exists $alt_soname{$syminfo->{soname}}) {
# Also count usage on alternate soname
$soname_used{$alt_soname{$syminfo->{soname}}}++;
@@ -409,15 +410,15 @@ foreach my $file (keys %exec) {
# extracted from build-dependencies
my $dev_pkg = $symfile->get_field($soname, 'Build-Depends-Package');
if (defined $dev_pkg) {
- print "Updating dependencies of $soname with build-dependencies\n" if $debug;
+ debug(1, "Updating dependencies of $soname with build-dependencies");
my $minver = get_min_version_from_deps($build_deps, $dev_pkg);
if (defined $minver) {
foreach my $dep ($symfile->get_dependencies($soname)) {
update_dependency_version($dep, $minver, 1);
- print " Minimal version of $dep updated with $minver\n" if $debug;
+ debug(1, " Minimal version of $dep updated with $minver");
}
} else {
- print " No minimal version found in $dev_pkg build-dependency\n" if $debug;
+ debug(1, " No minimal version found in $dev_pkg build-dependency");
}
}
@@ -654,12 +655,12 @@ sub add_shlibs_dep {
push @shlibs, $control_file if defined $control_file;
}
push @shlibs, $shlibsdefault;
- print " Looking up shlibs dependency of $soname provided by '$pkg'\n" if $debug;
+ debug(1, " Looking up shlibs dependency of $soname provided by '$pkg'");
foreach my $file (@shlibs) {
next if not -e $file;
my $dep = extract_from_shlibs($soname, $file);
if (defined($dep)) {
- print " Found $dep in $file\n" if $debug;
+ debug(1, " Found $dep in $file");
foreach (split(/,\s*/, $dep)) {
# Note: the value is empty for shlibs based dependency
# symbol based dependency will put a valid version as value
@@ -668,7 +669,7 @@ sub add_shlibs_dep {
return 1;
}
}
- print " Found nothing\n" if $debug;
+ debug(1, ' Found nothing');
return 0;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list