dpkg (1.18.25) stretch; urgency=medium
[dpkg] / scripts / Dpkg / Vendor / Ubuntu.pm
CommitLineData
1479465f
GJ
1# Copyright © 2008 Ian Jackson <ijackson@chiark.greenend.org.uk>
2# Copyright © 2008 Canonical, Ltd.
3# written by Colin Watson <cjwatson@ubuntu.com>
4# Copyright © 2008 James Westby <jw+debian@jameswestby.net>
5# Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20package Dpkg::Vendor::Ubuntu;
21
22use strict;
23use warnings;
24
25our $VERSION = '0.01';
26
27use Dpkg::ErrorHandling;
28use Dpkg::Gettext;
29use Dpkg::Path qw(find_command);
30use Dpkg::Control::Types;
31use Dpkg::BuildOptions;
32use Dpkg::Arch qw(debarch_eq get_host_arch);
33
34use parent qw(Dpkg::Vendor::Debian);
35
36=encoding utf8
37
38=head1 NAME
39
40Dpkg::Vendor::Ubuntu - Ubuntu vendor object
41
42=head1 DESCRIPTION
43
44This vendor object customizes the behaviour of dpkg scripts for Ubuntu
45specific behavior and policies.
46
47=cut
48
49sub run_hook {
50 my ($self, $hook, @params) = @_;
51
52 if ($hook eq 'before-source-build') {
53 my $src = shift @params;
54 my $fields = $src->{fields};
55
56 # check that Maintainer/XSBC-Original-Maintainer comply to
57 # https://wiki.ubuntu.com/DebianMaintainerField
58 if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
59 $fields->{'Version'} =~ /ubuntu/) {
60 if ($fields->{'Maintainer'} !~ /ubuntu/i) {
61 if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@ubuntu\.com/) {
62 error(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
63 } else {
64 warning(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
65 }
66 }
67 unless ($fields->{'Original-Maintainer'}) {
68 warning(g_('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
69 }
70 }
71
72 } elsif ($hook eq 'keyrings') {
73 return $self->run_hook('package-keyrings', @params);
74 } elsif ($hook eq 'package-keyrings') {
75 return ($self->SUPER::run_hook($hook),
76 '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
77 } elsif ($hook eq 'archive-keyrings') {
78 return ($self->SUPER::run_hook($hook),
79 '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
80 } elsif ($hook eq 'archive-keyrings-historic') {
81 return ($self->SUPER::run_hook($hook),
82 '/usr/share/keyrings/ubuntu-archive-removed-keys.gpg');
83 } elsif ($hook eq 'register-custom-fields') {
84 my @field_ops = $self->SUPER::run_hook($hook);
85 push @field_ops,
86 [ 'register', 'Launchpad-Bugs-Fixed',
87 CTRL_FILE_CHANGES | CTRL_CHANGELOG ],
88 [ 'insert_after', CTRL_FILE_CHANGES, 'Closes', 'Launchpad-Bugs-Fixed' ],
89 [ 'insert_after', CTRL_CHANGELOG, 'Closes', 'Launchpad-Bugs-Fixed' ];
90 return @field_ops;
91
92 } elsif ($hook eq 'post-process-changelog-entry') {
93 my $fields = shift @params;
94
95 # Add Launchpad-Bugs-Fixed field
96 my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
97 if (scalar(@$bugs)) {
98 $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
99 }
100
101 } elsif ($hook eq 'update-buildflags') {
102 my $flags = shift @params;
103 my $build_opts = Dpkg::BuildOptions->new();
104
105 if (!$build_opts->has('noopt')) {
106 if (debarch_eq(get_host_arch(), 'ppc64el')) {
107 for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
108 FFLAGS FCFLAGS)) {
109 $flags->set($flag, '-g -O3', 'vendor');
110 }
111 }
112 }
113 # Per https://wiki.ubuntu.com/DistCompilerFlags
114 $flags->set('LDFLAGS', '-Wl,-Bsymbolic-functions', 'vendor');
115
116 # Run the Debian hook to add hardening flags
117 $self->SUPER::run_hook($hook, $flags);
118 } else {
119 return $self->SUPER::run_hook($hook, @params);
120 }
121
122}
123
124=head1 PUBLIC FUNCTIONS
125
126=over
127
128=item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
129
130Takes one string as argument and finds "LP: #123456, #654321" statements,
131which are references to bugs on Launchpad. Returns all closed bug
132numbers in an array reference.
133
134=cut
135
136sub find_launchpad_closes {
137 my $changes = shift;
138 my %closes;
139
140 while ($changes &&
141 ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/pig)) {
142 $closes{$_} = 1 foreach (${^MATCH} =~ /\#?\s?(\d+)/g);
143 }
144
145 my @closes = sort { $a <=> $b } keys %closes;
146
147 return \@closes;
148}
149
150=back
151
152=head1 CHANGES
153
154=head2 Version 0.xx
155
156This is a semi-private module. Only documented functions are public.
157
158=cut
159
1601;