Ubuntu.pm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. package Dpkg::Vendor::Ubuntu;
  20. use strict;
  21. use warnings;
  22. our $VERSION = '0.01';
  23. use Dpkg::ErrorHandling;
  24. use Dpkg::Gettext;
  25. use Dpkg::Path qw(find_command);
  26. use Dpkg::Control::Types;
  27. use Dpkg::BuildOptions;
  28. use Dpkg::Arch qw(debarch_eq get_host_arch);
  29. use parent qw(Dpkg::Vendor::Debian);
  30. =encoding utf8
  31. =head1 NAME
  32. Dpkg::Vendor::Ubuntu - Ubuntu vendor object
  33. =head1 DESCRIPTION
  34. This vendor object customizes the behaviour of dpkg scripts for Ubuntu
  35. specific behavior and policies.
  36. =cut
  37. sub run_hook {
  38. my ($self, $hook, @params) = @_;
  39. if ($hook eq 'before-source-build') {
  40. my $src = shift @params;
  41. my $fields = $src->{fields};
  42. # check that Maintainer/XSBC-Original-Maintainer comply to
  43. # https://wiki.ubuntu.com/DebianMaintainerField
  44. if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
  45. $fields->{'Version'} =~ /ubuntu/) {
  46. if ($fields->{'Maintainer'} !~ /ubuntu/i) {
  47. if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@ubuntu\.com/) {
  48. error(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
  49. } else {
  50. warning(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
  51. }
  52. }
  53. unless ($fields->{'Original-Maintainer'}) {
  54. warning(g_('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
  55. }
  56. }
  57. } elsif ($hook eq 'keyrings') {
  58. return $self->run_hook('package-keyrings', @params);
  59. } elsif ($hook eq 'package-keyrings') {
  60. return ($self->SUPER::run_hook($hook),
  61. '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
  62. } elsif ($hook eq 'archive-keyrings') {
  63. return ($self->SUPER::run_hook($hook),
  64. '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
  65. } elsif ($hook eq 'archive-keyrings-historic') {
  66. return ($self->SUPER::run_hook($hook),
  67. '/usr/share/keyrings/ubuntu-archive-removed-keys.gpg');
  68. } elsif ($hook eq 'register-custom-fields') {
  69. my @field_ops = $self->SUPER::run_hook($hook);
  70. push @field_ops,
  71. [ 'register', 'Launchpad-Bugs-Fixed',
  72. CTRL_FILE_CHANGES | CTRL_CHANGELOG ],
  73. [ 'insert_after', CTRL_FILE_CHANGES, 'Closes', 'Launchpad-Bugs-Fixed' ],
  74. [ 'insert_after', CTRL_CHANGELOG, 'Closes', 'Launchpad-Bugs-Fixed' ];
  75. return @field_ops;
  76. } elsif ($hook eq 'post-process-changelog-entry') {
  77. my $fields = shift @params;
  78. # Add Launchpad-Bugs-Fixed field
  79. my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
  80. if (scalar(@$bugs)) {
  81. $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
  82. }
  83. } elsif ($hook eq 'update-buildflags') {
  84. my $flags = shift @params;
  85. my $build_opts = Dpkg::BuildOptions->new();
  86. if (!$build_opts->has('noopt')) {
  87. if (debarch_eq(get_host_arch(), 'ppc64el')) {
  88. for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
  89. FFLAGS FCFLAGS)) {
  90. $flags->set($flag, '-g -O3', 'vendor');
  91. }
  92. }
  93. }
  94. # Per https://wiki.ubuntu.com/DistCompilerFlags
  95. $flags->set('LDFLAGS', '-Wl,-Bsymbolic-functions', 'vendor');
  96. # Run the Debian hook to add hardening flags
  97. $self->SUPER::run_hook($hook, $flags);
  98. # Allow control of hardening-wrapper via dpkg-buildpackage DEB_BUILD_OPTIONS
  99. my $hardening;
  100. if ($build_opts->has('hardening')) {
  101. $hardening = $build_opts->get('hardening') // 1;
  102. }
  103. if ($build_opts->has('nohardening')) {
  104. $hardening = 0;
  105. }
  106. if (defined $hardening) {
  107. my $flag = 'DEB_BUILD_HARDENING';
  108. if ($hardening ne '0') {
  109. if (!find_command('hardened-cc')) {
  110. syserr(g_("'hardening' flag found but 'hardening-wrapper' not installed"));
  111. }
  112. if ($hardening ne '1') {
  113. my @options = split(/,\s*/, $hardening);
  114. $hardening = 1;
  115. my @hardopts = qw(format fortify stackprotector pie relro);
  116. foreach my $item (@hardopts) {
  117. my $upitem = uc($item);
  118. foreach my $option (@options) {
  119. if ($option =~ /^(no)?$item$/) {
  120. $flags->set($flag . '_' . $upitem,
  121. not defined $1 or $1 eq '', 'env');
  122. }
  123. }
  124. }
  125. }
  126. }
  127. if (defined $ENV{$flag}) {
  128. info(g_('overriding %s in environment: %s'), $flag, $hardening);
  129. }
  130. $flags->set($flag, $hardening, 'env');
  131. }
  132. } else {
  133. return $self->SUPER::run_hook($hook, @params);
  134. }
  135. }
  136. =head1 PUBLIC FUNCTIONS
  137. =over
  138. =item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
  139. Takes one string as argument and finds "LP: #123456, #654321" statements,
  140. which are references to bugs on Launchpad. Returns all closed bug
  141. numbers in an array reference.
  142. =cut
  143. sub find_launchpad_closes {
  144. my $changes = shift;
  145. my %closes;
  146. while ($changes &&
  147. ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/pig)) {
  148. $closes{$_} = 1 foreach (${^MATCH} =~ /\#?\s?(\d+)/g);
  149. }
  150. my @closes = sort { $a <=> $b } keys %closes;
  151. return \@closes;
  152. }
  153. =back
  154. =head1 CHANGES
  155. =head2 Version 0.xx
  156. This is a semi-private module. Only documented functions are public.
  157. =cut
  158. 1;