This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=837ecfdac680369ce71d96748a8a4762a414f654 commit 837ecfdac680369ce71d96748a8a4762a414f654 Author: Guillem Jover <[email protected]> AuthorDate: Sun Sep 16 23:47:10 2018 +0200 Dpkg::Source::Package::V2: Split BinaryFiles module into its own file --- debian/changelog | 2 + scripts/Dpkg/Source/BinaryFiles.pm | 108 +++++++++++++++++++++++++++++++++++++ scripts/Dpkg/Source/Package/V2.pm | 87 ++---------------------------- scripts/Makefile.am | 1 + scripts/po/POTFILES.in | 1 + 5 files changed, 115 insertions(+), 84 deletions(-) diff --git a/debian/changelog b/debian/changelog index fd83782c3..139a287f6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ dpkg (1.19.2) UNRELEASED; urgency=medium Fixes CPAN#127217. - Dpkg::OpenPGP: Do not read the gpg user configuration file. - Dpkg::Source::Functions: Reimplement is_binary() w/o using diff(1). + - Dpkg::Source::Package::V2: Split the BinaryFiles module into its own + file, and give it a more generic name (Dpkg::Source::BinaryFiles). * Documentation: - dpkg-buildpackage(1): Clarify --build=source explanation. - dsc(5): Clarify what “flattened” means in Testsuite-Triggers. diff --git a/scripts/Dpkg/Source/BinaryFiles.pm b/scripts/Dpkg/Source/BinaryFiles.pm new file mode 100644 index 000000000..c503e42b6 --- /dev/null +++ b/scripts/Dpkg/Source/BinaryFiles.pm @@ -0,0 +1,108 @@ +# Copyright © 2008-2011 Raphaël Hertzog <[email protected]> +# Copyright © 2008-2015 Guillem Jover <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +package Dpkg::Source::BinaryFiles; + +use strict; +use warnings; + +our $VERSION = '0.01'; + +use File::Path qw(make_path); +use File::Spec; + +use Dpkg::ErrorHandling; +use Dpkg::Gettext; + +sub new { + my ($this, $dir) = @_; + my $class = ref($this) || $this; + + my $self = { + dir => $dir, + allowed_binaries => {}, + seen_binaries => {}, + include_binaries_path => + File::Spec->catfile($dir, 'debian', 'source', 'include-binaries'), + }; + bless $self, $class; + $self->load_allowed_binaries(); + return $self; +} + +sub new_binary_found { + my ($self, $path) = @_; + + $self->{seen_binaries}{$path} = 1; +} + +sub load_allowed_binaries { + my $self = shift; + my $incbin_file = $self->{include_binaries_path}; + + if (-f $incbin_file) { + open my $incbin_fh, '<', $incbin_file + or syserr(g_('cannot read %s'), $incbin_file); + while (<$incbin_fh>) { + chomp; + s/^\s*//; + s/\s*$//; + next if /^#/ or length == 0; + $self->{allowed_binaries}{$_} = 1; + } + close $incbin_fh; + } +} + +sub binary_is_allowed { + my ($self, $path) = @_; + + return 1 if exists $self->{allowed_binaries}{$path}; + return 0; +} + +sub update_debian_source_include_binaries { + my $self = shift; + + my @unknown_binaries = $self->get_unknown_binaries(); + return unless scalar @unknown_binaries; + + my $incbin_file = $self->{include_binaries_path}; + make_path(File::Spec->catdir($self->{dir}, 'debian', 'source')); + open my $incbin_fh, '>>', $incbin_file + or syserr(g_('cannot write %s'), $incbin_file); + foreach my $binary (@unknown_binaries) { + print { $incbin_fh } "$binary\n"; + info(g_('adding %s to %s'), $binary, 'debian/source/include-binaries'); + $self->{allowed_binaries}{$binary} = 1; + } + close $incbin_fh; +} + +sub get_unknown_binaries { + my $self = shift; + + return grep { not $self->binary_is_allowed($_) } $self->get_seen_binaries(); +} + +sub get_seen_binaries { + my $self = shift; + my @seen = sort keys %{$self->{seen_binaries}}; + + return @seen; +} + +1; diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm index 2c8529bc1..8be647d7b 100644 --- a/scripts/Dpkg/Source/Package/V2.pm +++ b/scripts/Dpkg/Source/Package/V2.pm @@ -37,6 +37,7 @@ use Dpkg::Path qw(find_command); use Dpkg::Compression; use Dpkg::Source::Archive; use Dpkg::Source::Patch; +use Dpkg::Source::BinaryFiles; use Dpkg::Exit qw(push_exit_handler pop_exit_handler); use Dpkg::Source::Functions qw(erasedir chmod_if_needed is_binary fs_time); use Dpkg::Vendor qw(run_vendor_hook); @@ -517,7 +518,7 @@ sub do_build { my $basenamerev = $self->get_basename(1); # Check if the debian directory contains unwanted binary files - my $binaryfiles = Dpkg::Source::Package::V2::BinaryFiles->new($dir); + my $binaryfiles = Dpkg::Source::BinaryFiles->new($dir); my $unwanted_binaries = 0; my $check_binary = sub { if (-f and is_binary($_)) { @@ -714,7 +715,7 @@ sub do_commit { error(g_("patch file '%s' doesn't exist"), $tmpdiff) if not -e $tmpdiff; } - my $binaryfiles = Dpkg::Source::Package::V2::BinaryFiles->new($dir); + my $binaryfiles = Dpkg::Source::BinaryFiles->new($dir); my $handle_binary = sub { my ($self, $old, $new, %opts) = @_; my $fn = File::Spec->abs2rel($new, $dir); @@ -757,86 +758,4 @@ sub do_commit { info(g_('local changes have been recorded in a new patch: %s'), $patch); } -package Dpkg::Source::Package::V2::BinaryFiles; - -use Dpkg::ErrorHandling; -use Dpkg::Gettext; - -use File::Path qw(make_path); -use File::Spec; - -sub new { - my ($this, $dir) = @_; - my $class = ref($this) || $this; - - my $self = { - dir => $dir, - allowed_binaries => {}, - seen_binaries => {}, - include_binaries_path => - File::Spec->catfile($dir, 'debian', 'source', 'include-binaries'), - }; - bless $self, $class; - $self->load_allowed_binaries(); - return $self; -} - -sub new_binary_found { - my ($self, $path) = @_; - - $self->{seen_binaries}{$path} = 1; -} - -sub load_allowed_binaries { - my $self = shift; - my $incbin_file = $self->{include_binaries_path}; - if (-f $incbin_file) { - open(my $incbin_fh, '<', $incbin_file) - or syserr(g_('cannot read %s'), $incbin_file); - while (<$incbin_fh>) { - chomp; - s/^\s*//; - s/\s*$//; - next if /^#/ or length == 0; - $self->{allowed_binaries}{$_} = 1; - } - close($incbin_fh); - } -} - -sub binary_is_allowed { - my ($self, $path) = @_; - return 1 if exists $self->{allowed_binaries}{$path}; - return 0; -} - -sub update_debian_source_include_binaries { - my $self = shift; - - my @unknown_binaries = $self->get_unknown_binaries(); - return unless scalar(@unknown_binaries); - - my $incbin_file = $self->{include_binaries_path}; - make_path(File::Spec->catdir($self->{dir}, 'debian', 'source')); - open(my $incbin_fh, '>>', $incbin_file) - or syserr(g_('cannot write %s'), $incbin_file); - foreach my $binary (@unknown_binaries) { - print { $incbin_fh } "$binary\n"; - info(g_('adding %s to %s'), $binary, 'debian/source/include-binaries'); - $self->{allowed_binaries}{$binary} = 1; - } - close($incbin_fh); -} - -sub get_unknown_binaries { - my $self = shift; - return grep { not $self->binary_is_allowed($_) } $self->get_seen_binaries(); -} - -sub get_seen_binaries { - my $self = shift; - my @seen = sort keys %{$self->{seen_binaries}}; - return @seen; -} - 1; diff --git a/scripts/Makefile.am b/scripts/Makefile.am index d8160749b..d7bd8d2f7 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -104,6 +104,7 @@ nobase_dist_perllib_DATA = \ Dpkg/Shlibs/SymbolFile.pm \ Dpkg/Shlibs/Cppfilt.pm \ Dpkg/Source/Archive.pm \ + Dpkg/Source/BinaryFiles.pm \ Dpkg/Source/Functions.pm \ Dpkg/Source/Package.pm \ Dpkg/Source/Package/V1.pm \ diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in index 638fd8b97..a486b593d 100644 --- a/scripts/po/POTFILES.in +++ b/scripts/po/POTFILES.in @@ -72,6 +72,7 @@ scripts/Dpkg/Shlibs/Symbol.pm scripts/Dpkg/Shlibs/SymbolFile.pm scripts/Dpkg/Source/Archive.pm scripts/Dpkg/Source/Functions.pm +scripts/Dpkg/Source/BinaryFiles.pm scripts/Dpkg/Source/Package.pm scripts/Dpkg/Source/Package/V1.pm scripts/Dpkg/Source/Package/V2.pm -- Dpkg.Org's dpkg

