File Coverage

blib/lib/Dpkg/Vendor/Ubuntu.pm
Criterion Covered Total %
statement 47 60 78.3
branch 14 28 50.0
condition 3 14 21.4
subroutine 8 8 100.0
pod 2 2 100.0
total 74 112 66.0


line stmt bran cond sub pod time code
1             # Copyright © 2008 Ian Jackson
2             # Copyright © 2008 Canonical, Ltd.
3             # written by Colin Watson
4             # Copyright © 2008 James Westby
5             # Copyright © 2009 Raphaël Hertzog
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 .
19              
20             package Dpkg::Vendor::Ubuntu;
21              
22 3     3   20 use strict;
  3         6  
  3         95  
23 3     3   14 use warnings;
  3         6  
  3         130  
24              
25             our $VERSION = '0.01';
26              
27 3     3   18 use Dpkg::ErrorHandling;
  3         7  
  3         241  
28 3     3   18 use Dpkg::Gettext;
  3         6  
  3         172  
29 3     3   17 use Dpkg::Control::Types;
  3         6  
  3         293  
30              
31 3     3   20 use parent qw(Dpkg::Vendor::Debian);
  3         6  
  3         25  
32              
33             =encoding utf8
34              
35             =head1 NAME
36              
37             Dpkg::Vendor::Ubuntu - Ubuntu vendor class
38              
39             =head1 DESCRIPTION
40              
41             This vendor class customizes the behaviour of dpkg scripts for Ubuntu
42             specific behavior and policies.
43              
44             =cut
45              
46             sub run_hook {
47 253     253 1 529 my ($self, $hook, @params) = @_;
48              
49 253 50       1121 if ($hook eq 'before-source-build') {
    50          
    50          
    50          
    100          
    100          
    50          
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 0     0 if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
      0        
56             $fields->{'Version'} =~ /ubuntu/) {
57 0 0       0 if ($fields->{'Maintainer'} !~ /ubuntu/i) {
58 0 0 0     0 if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@ubuntu\.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       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         5 my @field_ops = $self->SUPER::run_hook($hook);
79 1         4 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         5 return @field_ops;
85              
86             } elsif ($hook eq 'post-process-changelog-entry') {
87 250         398 my $fields = shift @params;
88              
89             # Add Launchpad-Bugs-Fixed field
90 250   50     506 my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
91 250 100       1006 if (scalar(@$bugs)) {
92 7         26 $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
93             }
94              
95             } elsif ($hook eq 'update-buildflags') {
96 2         5 my $flags = shift @params;
97              
98             # Run the Debian hook to add hardening flags
99 2         9 $self->SUPER::run_hook($hook, $flags);
100              
101 2         13 require Dpkg::BuildOptions;
102              
103 2         8 my $build_opts = Dpkg::BuildOptions->new();
104              
105 2 50       5 if (!$build_opts->has('noopt')) {
106 2         7 require Dpkg::Arch;
107              
108 2         5 my $arch = Dpkg::Arch::get_host_arch();
109 2 100       7 if (Dpkg::Arch::debarch_eq($arch, 'ppc64el')) {
110 1         3 for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
111             FFLAGS FCFLAGS)) {
112 7         15 my $value = $flags->get($flag);
113 7         33 $value =~ s/-O[0-9]/-O3/;
114 7         18 $flags->set($flag, $value);
115             }
116             }
117             }
118             # Per https://wiki.ubuntu.com/DistCompilerFlags
119 2         9 $flags->prepend('LDFLAGS', '-Wl,-Bsymbolic-functions');
120             } else {
121 0         0 return $self->SUPER::run_hook($hook, @params);
122             }
123              
124             }
125              
126             =head1 PUBLIC FUNCTIONS
127              
128             =over
129              
130             =item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
131              
132             Takes one string as argument and finds "LP: #123456, #654321" statements,
133             which are references to bugs on Launchpad. Returns all closed bug
134             numbers in an array reference.
135              
136             =cut
137              
138             sub find_launchpad_closes {
139 250     250 1 414 my $changes = shift;
140 250         317 my %closes;
141              
142 250   66     2040 while ($changes &&
143             ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/pig)) {
144 9         103 $closes{$_} = 1 foreach (${^MATCH} =~ /\#?\s?(\d+)/g);
145             }
146              
147 250         628 my @closes = sort { $a <=> $b } keys %closes;
  13         40  
148              
149 250         604 return \@closes;
150             }
151              
152             =back
153              
154             =head1 CHANGES
155              
156             =head2 Version 0.xx
157              
158             This is a semi-private module. Only documented functions are public.
159              
160             =cut
161              
162             1;