| OLD | NEW |
| (Empty) |
| 1 # Copyright © 2008 Ian Jackson <ian@davenant.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 | |
| 20 package Dpkg::Vendor::Ubuntu; | |
| 21 | |
| 22 use strict; | |
| 23 use warnings; | |
| 24 | |
| 25 our $VERSION = '0.01'; | |
| 26 | |
| 27 use Dpkg::ErrorHandling; | |
| 28 use Dpkg::Gettext; | |
| 29 use Dpkg::Path qw(find_command); | |
| 30 use Dpkg::Control::Types; | |
| 31 use Dpkg::BuildOptions; | |
| 32 use Dpkg::Arch qw(debarch_eq get_host_arch); | |
| 33 | |
| 34 use parent qw(Dpkg::Vendor::Debian); | |
| 35 | |
| 36 =encoding utf8 | |
| 37 | |
| 38 =head1 NAME | |
| 39 | |
| 40 Dpkg::Vendor::Ubuntu - Ubuntu vendor object | |
| 41 | |
| 42 =head1 DESCRIPTION | |
| 43 | |
| 44 This vendor object customize the behaviour of dpkg-source | |
| 45 to check that Maintainers have been modified if necessary. | |
| 46 | |
| 47 =cut | |
| 48 | |
| 49 sub 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'}) a
nd | |
| 59 $fields->{'Version'} =~ /ubuntu/) { | |
| 60 if ($fields->{'Maintainer'} !~ /ubuntu/i) { | |
| 61 if (defined ($ENV{DEBEMAIL}) and $ENV{DEBEMAIL} =~ /\@ubuntu\.com
/) { | |
| 62 error(_g('Version number suggests Ubuntu changes, but Maintai
ner: does not have Ubuntu address')); | |
| 63 } else { | |
| 64 warning(_g('Version number suggests Ubuntu changes, but Maint
ainer: 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 my @keyrings = $self->SUPER::run_hook($hook); | |
| 74 | |
| 75 push(@keyrings, '/usr/share/keyrings/ubuntu-archive-keyring.gpg'); | |
| 76 return @keyrings; | |
| 77 | |
| 78 } elsif ($hook eq 'register-custom-fields') { | |
| 79 my @field_ops = $self->SUPER::run_hook($hook); | |
| 80 push @field_ops, | |
| 81 [ 'register', 'Launchpad-Bugs-Fixed', | |
| 82 CTRL_FILE_CHANGES | CTRL_CHANGELOG ], | |
| 83 [ 'insert_after', CTRL_FILE_CHANGES, 'Closes', 'Launchpad-Bugs-Fixed
' ], | |
| 84 [ 'insert_after', CTRL_CHANGELOG, 'Closes', 'Launchpad-Bugs-Fixed' ]
; | |
| 85 return @field_ops; | |
| 86 | |
| 87 } elsif ($hook eq 'post-process-changelog-entry') { | |
| 88 my $fields = shift @params; | |
| 89 | |
| 90 # Add Launchpad-Bugs-Fixed field | |
| 91 my $bugs = find_launchpad_closes($fields->{'Changes'} || ''); | |
| 92 if (scalar(@$bugs)) { | |
| 93 $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs); | |
| 94 } | |
| 95 | |
| 96 } elsif ($hook eq 'update-buildflags') { | |
| 97 my $flags = shift @params; | |
| 98 my $build_opts = Dpkg::BuildOptions->new(); | |
| 99 | |
| 100 if (!$build_opts->has('noopt')) { | |
| 101 if (debarch_eq(get_host_arch(), 'ppc64el')) { | |
| 102 for my $flag (qw(CFLAGS CXXFLAGS GCJFLAGS FFLAGS)) { | |
| 103 $flags->set($flag, '-g -O3', 'vendor'); | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 # Per https://wiki.ubuntu.com/DistCompilerFlags | |
| 108 $flags->set('LDFLAGS', '-Wl,-Bsymbolic-functions', 'vendor'); | |
| 109 | |
| 110 # Run the Debian hook to add hardening flags | |
| 111 $self->SUPER::run_hook($hook, $flags); | |
| 112 | |
| 113 # Allow control of hardening-wrapper via dpkg-buildpackage DEB_BUILD_OPT
IONS | |
| 114 my $hardening; | |
| 115 if ($build_opts->has('hardening')) { | |
| 116 $hardening = $build_opts->get('hardening') // 1; | |
| 117 } | |
| 118 if ($build_opts->has('nohardening')) { | |
| 119 $hardening = 0; | |
| 120 } | |
| 121 if (defined $hardening) { | |
| 122 my $flag = 'DEB_BUILD_HARDENING'; | |
| 123 if ($hardening ne '0') { | |
| 124 if (!find_command('hardened-cc')) { | |
| 125 syserr(_g("'hardening' flag found but 'hardening-wrapper' no
t installed")); | |
| 126 } | |
| 127 if ($hardening ne '1') { | |
| 128 my @options = split(/,\s*/, $hardening); | |
| 129 $hardening = 1; | |
| 130 | |
| 131 my @hardopts = qw(format fortify stackprotector pie relro); | |
| 132 foreach my $item (@hardopts) { | |
| 133 my $upitem = uc($item); | |
| 134 foreach my $option (@options) { | |
| 135 if ($option =~ /^(no)?$item$/) { | |
| 136 $flags->set($flag . '_' . $upitem, | |
| 137 not defined $1 or $1 eq '', 'env'); | |
| 138 } | |
| 139 } | |
| 140 } | |
| 141 } | |
| 142 } | |
| 143 if (defined $ENV{$flag}) { | |
| 144 info(_g('overriding %s in environment: %s'), $flag, $hardening); | |
| 145 } | |
| 146 $flags->set($flag, $hardening, 'env'); | |
| 147 } | |
| 148 | |
| 149 } else { | |
| 150 return $self->SUPER::run_hook($hook, @params); | |
| 151 } | |
| 152 | |
| 153 } | |
| 154 | |
| 155 =head1 PUBLIC FUNCTIONS | |
| 156 | |
| 157 =over | |
| 158 | |
| 159 =item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes) | |
| 160 | |
| 161 Takes one string as argument and finds "LP: #123456, #654321" statements, | |
| 162 which are references to bugs on Launchpad. Returns all closed bug | |
| 163 numbers in an array reference. | |
| 164 | |
| 165 =cut | |
| 166 | |
| 167 sub find_launchpad_closes { | |
| 168 my ($changes) = @_; | |
| 169 my %closes; | |
| 170 | |
| 171 while ($changes && | |
| 172 ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/ig)) { | |
| 173 $closes{$_} = 1 foreach($& =~ /\#?\s?(\d+)/g); | |
| 174 } | |
| 175 | |
| 176 my @closes = sort { $a <=> $b } keys %closes; | |
| 177 | |
| 178 return \@closes; | |
| 179 } | |
| 180 | |
| 181 =back | |
| 182 | |
| 183 =cut | |
| 184 | |
| 185 1; | |
| OLD | NEW |