Ubuntu.pm 5.2 KB

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