dpkg: improved Trisquel.pm vendor file

This commit is contained in:
Ruben Rodriguez 2022-07-14 14:37:02 -04:00
parent c36017de60
commit 91bbe8169a
2 changed files with 16 additions and 78 deletions

View file

@ -3,6 +3,7 @@
# written by Colin Watson <cjwatson@ubuntu.com> # written by Colin Watson <cjwatson@ubuntu.com>
# Copyright © 2008 James Westby <jw+debian@jameswestby.net> # Copyright © 2008 James Westby <jw+debian@jameswestby.net>
# Copyright © 2009 Raphaël Hertzog <hertzog@debian.org> # Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
# Copyright © 2022 Ruben Rodriguez <ruben@trisquel.org>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -34,11 +35,11 @@ use parent qw(Dpkg::Vendor::Debian);
=head1 NAME =head1 NAME
Dpkg::Vendor::Trisquel - Trisquel vendor object Dpkg::Vendor::Trisquel - Trisquel vendor class
=head1 DESCRIPTION =head1 DESCRIPTION
This vendor object customizes the behaviour of dpkg scripts for Trisquel This vendor class customizes the behaviour of dpkg scripts for Trisquel
specific behavior and policies. specific behavior and policies.
=cut =cut
@ -46,29 +47,7 @@ specific behavior and policies.
sub run_hook { sub run_hook {
my ($self, $hook, @params) = @_; my ($self, $hook, @params) = @_;
if ($hook eq 'before-source-build') { if ($hook eq 'package-keyrings') {
my $src = shift @params;
my $fields = $src->{fields};
# check that Maintainer/XSBC-Original-Maintainer comply to
# https://wiki.ubuntu.com/DebianMaintainerField
if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
$fields->{'Version'} =~ /ubuntu/) {
if ($fields->{'Maintainer'} !~ /ubuntu/i) {
if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@ubuntu\.com/) {
error(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
} else {
warning(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
}
}
unless ($fields->{'Original-Maintainer'}) {
warning(g_('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
}
}
} elsif ($hook eq 'keyrings') {
return $self->run_hook('package-keyrings', @params);
} elsif ($hook eq 'package-keyrings') {
return ($self->SUPER::run_hook($hook), return ($self->SUPER::run_hook($hook),
'/usr/share/keyrings/trisquel-archive-keyring.gpg'); '/usr/share/keyrings/trisquel-archive-keyring.gpg');
} elsif ($hook eq 'archive-keyrings') { } elsif ($hook eq 'archive-keyrings') {
@ -77,27 +56,12 @@ sub run_hook {
} elsif ($hook eq 'archive-keyrings-historic') { } elsif ($hook eq 'archive-keyrings-historic') {
return ($self->SUPER::run_hook($hook), return ($self->SUPER::run_hook($hook),
'/usr/share/keyrings/trisquel-archive-removed-keys.gpg'); '/usr/share/keyrings/trisquel-archive-removed-keys.gpg');
} elsif ($hook eq 'register-custom-fields') {
my @field_ops = $self->SUPER::run_hook($hook);
push @field_ops,
[ 'register', 'Launchpad-Bugs-Fixed',
CTRL_FILE_CHANGES | CTRL_CHANGELOG ],
[ 'insert_after', CTRL_FILE_CHANGES, 'Closes', 'Launchpad-Bugs-Fixed' ],
[ 'insert_after', CTRL_CHANGELOG, 'Closes', 'Launchpad-Bugs-Fixed' ];
return @field_ops;
} elsif ($hook eq 'post-process-changelog-entry') {
my $fields = shift @params;
# Add Launchpad-Bugs-Fixed field
my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
if (scalar(@$bugs)) {
$fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
}
} elsif ($hook eq 'update-buildflags') { } elsif ($hook eq 'update-buildflags') {
my $flags = shift @params; my $flags = shift @params;
# Run the Debian hook to add hardening flags
$self->SUPER::run_hook($hook, $flags);
require Dpkg::BuildOptions; require Dpkg::BuildOptions;
my $build_opts = Dpkg::BuildOptions->new(); my $build_opts = Dpkg::BuildOptions->new();
@ -109,54 +73,27 @@ sub run_hook {
if (Dpkg::Arch::debarch_eq($arch, 'ppc64el')) { if (Dpkg::Arch::debarch_eq($arch, 'ppc64el')) {
for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
FFLAGS FCFLAGS)) { FFLAGS FCFLAGS)) {
$flags->set($flag, '-g -O3', 'vendor'); my $value = $flags->get($flag);
$value =~ s/-O[0-9]/-O3/;
$flags->set($flag, $value);
} }
} }
} }
# Per https://wiki.ubuntu.com/DistCompilerFlags # Per https://wiki.ubuntu.com/DistCompilerFlags
$flags->set('LDFLAGS', '-Wl,-Bsymbolic-functions', 'vendor'); $flags->prepend('LDFLAGS', '-Wl,-Bsymbolic-functions');
# Run the Debian hook to add hardening flags
$self->SUPER::run_hook($hook, $flags);
} else { } else {
return $self->SUPER::run_hook($hook, @params); return $self->SUPER::run_hook($hook, @params);
} }
# Default return value for unknown/unimplemented hooks
return;
} }
=head1 PUBLIC FUNCTIONS
=over
=item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
Takes one string as argument and finds "LP: #123456, #654321" statements,
which are references to bugs on Launchpad. Returns all closed bug
numbers in an array reference.
=cut
sub find_launchpad_closes {
my $changes = shift;
my %closes;
while ($changes &&
($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/pig)) {
$closes{$_} = 1 foreach (${^MATCH} =~ /\#?\s?(\d+)/g);
}
my @closes = sort { $a <=> $b } keys %closes;
return \@closes;
}
=back
=head1 CHANGES =head1 CHANGES
=head2 Version 0.xx =head2 Version 0.xx
This is a semi-private module. Only documented functions are public. This is a private module.
=cut =cut

View file

@ -17,10 +17,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# #
VERSION=2 VERSION=3
COMPONENT=main COMPONENT=main
. ./config . ./config
exit
cat << EOF > scripts/t/origins/trisquel cat << EOF > scripts/t/origins/trisquel
Vendor: Trisquel Vendor: Trisquel