File Coverage

File:Dpkg/Vendor/Ubuntu.pm
Coverage:66.1%

linestmtbrancondsubpodtimecode
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
22
3
3
3
6
2
36
use strict;
23
3
3
3
4
3
74
use warnings;
24
25our $VERSION = '0.01';
26
27
3
3
3
4
3
96
use Dpkg::ErrorHandling;
28
3
3
3
7
1
60
use Dpkg::Gettext;
29
3
3
3
5
2
91
use Dpkg::Control::Types;
30
31
3
3
3
5
3
4
use parent qw(Dpkg::Vendor::Debian);
32
33=encoding utf8
34
35 - 44
=head1 NAME

Dpkg::Vendor::Ubuntu - Ubuntu vendor class

=head1 DESCRIPTION

This vendor class customizes the behaviour of dpkg scripts for Ubuntu
specific behavior and policies.

=cut
45
46sub run_hook {
47
253
1
183
    my ($self, $hook, @params) = @_;
48
49
253
356
    if ($hook eq 'before-source-build') {
50
0
0
        my $src = shift @params;
51
0
0
        my $fields = $src->{fields};
52
53        # check that Maintainer/XSBC-Original-Maintainer comply to
54        # https://wiki.ubuntu.com/DebianMaintainerField
55
0
0
        if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
56           $fields->{'Version'} =~ /ubuntu/) {
57
0
0
           if ($fields->{'Maintainer'} !~ /(?:ubuntu|canonical)/i) {
58
0
0
               if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@(?:ubuntu|canonical)\.com/) {
59
0
0
                   error(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
60               } else {
61
0
0
                   warning(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
62               }
63           }
64
0
0
           unless ($fields->{'Original-Maintainer'}) {
65
0
0
               warning(g_('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
66           }
67        }
68    } elsif ($hook eq 'package-keyrings') {
69
0
0
        return ($self->SUPER::run_hook($hook),
70                '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
71    } elsif ($hook eq 'archive-keyrings') {
72
0
0
        return ($self->SUPER::run_hook($hook),
73                '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
74    } elsif ($hook eq 'archive-keyrings-historic') {
75
0
0
        return ($self->SUPER::run_hook($hook),
76                '/usr/share/keyrings/ubuntu-archive-removed-keys.gpg');
77    } elsif ($hook eq 'register-custom-fields') {
78
1
2
        my @field_ops = $self->SUPER::run_hook($hook);
79
1
2
        push @field_ops,
80            [ 'register', 'Launchpad-Bugs-Fixed',
81              CTRL_FILE_CHANGES | CTRL_CHANGELOG  ],
82            [ 'insert_after', CTRL_FILE_CHANGES, 'Closes', 'Launchpad-Bugs-Fixed' ],
83            [ 'insert_after', CTRL_CHANGELOG, 'Closes', 'Launchpad-Bugs-Fixed' ];
84
1
2
        return @field_ops;
85
86    } elsif ($hook eq 'post-process-changelog-entry') {
87
250
141
        my $fields = shift @params;
88
89        # Add Launchpad-Bugs-Fixed field
90
250
172
        my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
91
250
354
        if (scalar(@$bugs)) {
92
7
8
            $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
93        }
94
95    } elsif ($hook eq 'update-buildflags') {
96
2
2
        my $flags = shift @params;
97
98        # Run the Debian hook to add hardening flags
99
2
3
        $self->SUPER::run_hook($hook, $flags);
100
101
2
4
        require Dpkg::BuildOptions;
102
103
2
3
        my $build_opts = Dpkg::BuildOptions->new();
104
105
2
24
        if (!$build_opts->has('noopt')) {
106
2
3
            require Dpkg::Arch;
107
108
2
1
            my $arch = Dpkg::Arch::get_host_arch();
109
2
2
            if (Dpkg::Arch::debarch_eq($arch, 'ppc64el')) {
110
1
1
                for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
111                                 FFLAGS FCFLAGS)) {
112
7
12
                    my $value = $flags->get($flag);
113
7
8
                    $value =~ s/-O[0-9]/-O3/;
114
7
6
                    $flags->set($flag, $value);
115                }
116            }
117        }
118        # Per https://wiki.ubuntu.com/DistCompilerFlags
119
2
3
        $flags->prepend('LDFLAGS', '-Wl,-Bsymbolic-functions');
120    } else {
121
0
0
        return $self->SUPER::run_hook($hook, @params);
122    }
123
124}
125
126 - 136
=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
137
138sub find_launchpad_closes {
139
250
1
140
    my $changes = shift;
140
250
125
    my %closes;
141
142
250
593
    while ($changes &&
143          ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/pig)) {
144
9
37
        $closes{$_} = 1 foreach (${^MATCH} =~ /\#?\s?(\d+)/g);
145    }
146
147
250
13
176
14
    my @closes = sort { $a <=> $b } keys %closes;
148
149
250
214
    return \@closes;
150}
151
152=back
153
154 - 160
=head1 CHANGES

=head2 Version 0.xx

This is a semi-private module. Only documented functions are public.

=cut
161
1621;