Ubuntu.pm 5.4 KB

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