V2.pm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. # Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package Dpkg::Source::Package::V2;
  16. use strict;
  17. use warnings;
  18. our $VERSION = "0.01";
  19. use base 'Dpkg::Source::Package';
  20. use Dpkg;
  21. use Dpkg::Gettext;
  22. use Dpkg::ErrorHandling;
  23. use Dpkg::Compression;
  24. use Dpkg::Source::Archive;
  25. use Dpkg::Source::Patch;
  26. use Dpkg::Exit;
  27. use Dpkg::Source::Functions qw(erasedir is_binary fs_time);
  28. use Dpkg::Vendor qw(run_vendor_hook);
  29. use Dpkg::Control;
  30. use Dpkg::Changelog::Parse;
  31. use POSIX;
  32. use File::Basename;
  33. use File::Temp qw(tempfile tempdir);
  34. use File::Path;
  35. use File::Spec;
  36. use File::Find;
  37. our $CURRENT_MINOR_VERSION = "0";
  38. sub init_options {
  39. my ($self) = @_;
  40. $self->SUPER::init_options();
  41. $self->{'options'}{'include_removal'} = 0
  42. unless exists $self->{'options'}{'include_removal'};
  43. $self->{'options'}{'include_timestamp'} = 0
  44. unless exists $self->{'options'}{'include_timestamp'};
  45. $self->{'options'}{'include_binaries'} = 0
  46. unless exists $self->{'options'}{'include_binaries'};
  47. $self->{'options'}{'preparation'} = 1
  48. unless exists $self->{'options'}{'preparation'};
  49. $self->{'options'}{'skip_patches'} = 0
  50. unless exists $self->{'options'}{'skip_patches'};
  51. $self->{'options'}{'unapply_patches'} = 0
  52. unless exists $self->{'options'}{'unapply_patches'};
  53. $self->{'options'}{'skip_debianization'} = 0
  54. unless exists $self->{'options'}{'skip_debianization'};
  55. $self->{'options'}{'create_empty_orig'} = 0
  56. unless exists $self->{'options'}{'create_empty_orig'};
  57. $self->{'options'}{'abort_on_upstream_changes'} = 0
  58. unless exists $self->{'options'}{'abort_on_upstream_changes'};
  59. }
  60. sub parse_cmdline_option {
  61. my ($self, $opt) = @_;
  62. if ($opt =~ /^--include-removal$/) {
  63. $self->{'options'}{'include_removal'} = 1;
  64. return 1;
  65. } elsif ($opt =~ /^--include-timestamp$/) {
  66. $self->{'options'}{'include_timestamp'} = 1;
  67. return 1;
  68. } elsif ($opt =~ /^--include-binaries$/) {
  69. $self->{'options'}{'include_binaries'} = 1;
  70. return 1;
  71. } elsif ($opt =~ /^--no-preparation$/) {
  72. $self->{'options'}{'preparation'} = 0;
  73. return 1;
  74. } elsif ($opt =~ /^--skip-patches$/) {
  75. $self->{'options'}{'skip_patches'} = 1;
  76. return 1;
  77. } elsif ($opt =~ /^--unapply-patches$/) {
  78. $self->{'options'}{'unapply_patches'} = 1;
  79. return 1;
  80. } elsif ($opt =~ /^--skip-debianization$/) {
  81. $self->{'options'}{'skip_debianization'} = 1;
  82. return 1;
  83. } elsif ($opt =~ /^--create-empty-orig$/) {
  84. $self->{'options'}{'create_empty_orig'} = 1;
  85. return 1;
  86. } elsif ($opt =~ /^--abort-on-upstream-changes$/) {
  87. $self->{'options'}{'abort_on_upstream_changes'} = 1;
  88. return 1;
  89. }
  90. return 0;
  91. }
  92. sub do_extract {
  93. my ($self, $newdirectory) = @_;
  94. my $fields = $self->{'fields'};
  95. my $dscdir = $self->{'basedir'};
  96. my $basename = $self->get_basename();
  97. my $basenamerev = $self->get_basename(1);
  98. my ($tarfile, $debianfile, %origtar, %seen);
  99. my $re_ext = $compression_re_file_ext;
  100. foreach my $file ($self->get_files()) {
  101. (my $uncompressed = $file) =~ s/\.$re_ext$//;
  102. error(_g("duplicate files in %s source package: %s.*"), "v2.0",
  103. $uncompressed) if $seen{$uncompressed};
  104. $seen{$uncompressed} = 1;
  105. if ($file =~ /^\Q$basename\E\.orig\.tar\.$re_ext$/) {
  106. $tarfile = $file;
  107. } elsif ($file =~ /^\Q$basename\E\.orig-([[:alnum:]-]+)\.tar\.$re_ext$/) {
  108. $origtar{$1} = $file;
  109. } elsif ($file =~ /^\Q$basenamerev\E\.debian\.tar\.$re_ext$/) {
  110. $debianfile = $file;
  111. } else {
  112. error(_g("unrecognized file for a %s source package: %s"),
  113. "v2.0", $file);
  114. }
  115. }
  116. unless ($tarfile and $debianfile) {
  117. error(_g("missing orig.tar or debian.tar file in v2.0 source package"));
  118. }
  119. erasedir($newdirectory);
  120. # Extract main tarball
  121. info(_g("unpacking %s"), $tarfile);
  122. my $tar = Dpkg::Source::Archive->new(filename => "$dscdir$tarfile");
  123. $tar->extract($newdirectory, no_fixperms => 1,
  124. options => [ "--anchored", "--no-wildcards-match-slash",
  125. "--exclude", "*/.pc", "--exclude", ".pc" ]);
  126. # The .pc exclusion is only needed for 3.0 (quilt) and to avoid
  127. # having an upstream tarball provide a directory with symlinks
  128. # that would be blindly followed when applying the patches
  129. # Extract additional orig tarballs
  130. foreach my $subdir (keys %origtar) {
  131. my $file = $origtar{$subdir};
  132. info(_g("unpacking %s"), $file);
  133. if (-e "$newdirectory/$subdir") {
  134. warning(_g("required removal of `%s' installed by original tarball"), $subdir);
  135. erasedir("$newdirectory/$subdir");
  136. }
  137. $tar = Dpkg::Source::Archive->new(filename => "$dscdir$file");
  138. $tar->extract("$newdirectory/$subdir", no_fixperms => 1);
  139. }
  140. # Stop here if debianization is not wanted
  141. return if $self->{'options'}{'skip_debianization'};
  142. # Extract debian tarball after removing the debian directory
  143. info(_g("unpacking %s"), $debianfile);
  144. erasedir("$newdirectory/debian");
  145. # Exclude existing symlinks from extraction of debian.tar.gz as we
  146. # don't want to overwrite something outside of $newdirectory due to a
  147. # symlink
  148. my @exclude_symlinks;
  149. my $wanted = sub {
  150. return if not -l $_;
  151. my $fn = File::Spec->abs2rel($_, $newdirectory);
  152. push @exclude_symlinks, "--exclude", $fn;
  153. };
  154. find({ wanted => $wanted, no_chdir => 1 }, $newdirectory);
  155. $tar = Dpkg::Source::Archive->new(filename => "$dscdir$debianfile");
  156. $tar->extract($newdirectory, in_place => 1,
  157. options => [ '--anchored', '--no-wildcards',
  158. @exclude_symlinks ]);
  159. # Apply patches (in a separate method as it might be overriden)
  160. $self->apply_patches($newdirectory, usage => 'unpack')
  161. unless $self->{'options'}{'skip_patches'};
  162. }
  163. sub get_autopatch_name {
  164. return "zz_debian-diff-auto";
  165. }
  166. sub get_patches {
  167. my ($self, $dir, %opts) = @_;
  168. $opts{"skip_auto"} = 0 unless defined($opts{"skip_auto"});
  169. my @patches;
  170. my $pd = "$dir/debian/patches";
  171. my $auto_patch = $self->get_autopatch_name();
  172. if (-d $pd) {
  173. opendir(DIR, $pd) || syserr(_g("cannot opendir %s"), $pd);
  174. foreach my $patch (sort readdir(DIR)) {
  175. # patches match same rules as run-parts
  176. next unless $patch =~ /^[\w-]+$/ and -f "$pd/$patch";
  177. next if $opts{"skip_auto"} and $patch eq $auto_patch;
  178. push @patches, $patch;
  179. }
  180. closedir(DIR);
  181. }
  182. return @patches;
  183. }
  184. sub apply_patches {
  185. my ($self, $dir, %opts) = @_;
  186. $opts{"skip_auto"} = 0 unless defined($opts{"skip_auto"});
  187. my @patches = $self->get_patches($dir, %opts);
  188. return unless scalar(@patches);
  189. my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
  190. open(APPLIED, '>', $applied) || syserr(_g("cannot write %s"), $applied);
  191. print APPLIED "# During $opts{'usage'}\n";
  192. my $timestamp = fs_time($applied);
  193. foreach my $patch ($self->get_patches($dir, %opts)) {
  194. my $path = File::Spec->catfile($dir, "debian", "patches", $patch);
  195. info(_g("applying %s"), $patch) unless $opts{"skip_auto"};
  196. my $patch_obj = Dpkg::Source::Patch->new(filename => $path);
  197. $patch_obj->apply($dir, force_timestamp => 1,
  198. timestamp => $timestamp,
  199. add_options => [ '-E' ]);
  200. print APPLIED "$patch\n";
  201. }
  202. close(APPLIED);
  203. }
  204. sub unapply_patches {
  205. my ($self, $dir, %opts) = @_;
  206. my @patches = reverse($self->get_patches($dir, %opts));
  207. return unless scalar(@patches);
  208. my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
  209. my $timestamp = fs_time($applied);
  210. foreach my $patch (@patches) {
  211. my $path = File::Spec->catfile($dir, "debian", "patches", $patch);
  212. info(_g("unapplying %s"), $patch) unless $opts{"quiet"};
  213. my $patch_obj = Dpkg::Source::Patch->new(filename => $path);
  214. $patch_obj->apply($dir, force_timestamp => 1, verbose => 0,
  215. timestamp => $timestamp,
  216. add_options => [ '-E', '-R' ]);
  217. }
  218. unlink($applied);
  219. }
  220. sub upstream_tarball_template {
  221. my ($self) = @_;
  222. my $ext = "{" . join(",",
  223. sort map {
  224. compression_get_property($_, "file_ext")
  225. } compression_get_list()) . "}";
  226. return "../" . $self->get_basename() . ".orig.tar.$ext";
  227. }
  228. sub can_build {
  229. my ($self, $dir) = @_;
  230. return 1 if $self->find_original_tarballs(include_supplementary => 0);
  231. return 1 if $self->{'options'}{'create_empty_orig'} and
  232. $self->find_original_tarballs(include_main => 0);
  233. return (0, sprintf(_g("no upstream tarball found at %s"),
  234. $self->upstream_tarball_template()));
  235. }
  236. sub before_build {
  237. my ($self, $dir) = @_;
  238. $self->check_patches_applied($dir) if $self->{'options'}{'preparation'};
  239. }
  240. sub after_build {
  241. my ($self, $dir) = @_;
  242. my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
  243. my $reason = "";
  244. if (-e $applied) {
  245. open(APPLIED, "<", $applied) || syserr(_g("cannot read %s"), $applied);
  246. $reason = <APPLIED>;
  247. close(APPLIED);
  248. }
  249. if ($reason =~ /^# During preparation/ or
  250. $self->{'options'}{'unapply_patches'}) {
  251. $self->unapply_patches($dir);
  252. }
  253. }
  254. sub prepare_build {
  255. my ($self, $dir) = @_;
  256. $self->{'diff_options'} = {
  257. diff_ignore_regexp => $self->{'options'}{'diff_ignore_regexp'},
  258. include_removal => $self->{'options'}{'include_removal'},
  259. include_timestamp => $self->{'options'}{'include_timestamp'},
  260. use_dev_null => 1,
  261. };
  262. push @{$self->{'options'}{'tar_ignore'}}, "debian/patches/.dpkg-source-applied";
  263. $self->check_patches_applied($dir) if $self->{'options'}{'preparation'};
  264. if ($self->{'options'}{'create_empty_orig'} and
  265. not $self->find_original_tarballs(include_supplementary => 0))
  266. {
  267. # No main orig.tar, create a dummy one
  268. my $filename = $self->get_basename() . ".orig.tar." .
  269. $self->{'options'}{'comp_ext'};
  270. my $tar = Dpkg::Source::Archive->new(filename => $filename);
  271. $tar->create();
  272. $tar->finish();
  273. }
  274. }
  275. sub check_patches_applied {
  276. my ($self, $dir) = @_;
  277. my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
  278. unless (-e $applied) {
  279. info(_g("patches are not applied, applying them now"));
  280. $self->apply_patches($dir, usage => 'preparation');
  281. }
  282. }
  283. sub do_build {
  284. my ($self, $dir) = @_;
  285. my ($dirname, $updir) = fileparse($dir);
  286. my @argv = @{$self->{'options'}{'ARGV'}};
  287. if (scalar(@argv)) {
  288. usageerr(_g("-b takes only one parameter with format `%s'"),
  289. $self->{'fields'}{'Format'});
  290. }
  291. $self->prepare_build($dir);
  292. my $include_binaries = $self->{'options'}{'include_binaries'};
  293. my @tar_ignore = map { "--exclude=$_" } @{$self->{'options'}{'tar_ignore'}};
  294. my $sourcepackage = $self->{'fields'}{'Source'};
  295. my $basenamerev = $self->get_basename(1);
  296. my $basename = $self->get_basename();
  297. my $basedirname = $basename;
  298. $basedirname =~ s/_/-/;
  299. # Identify original tarballs
  300. my ($tarfile, %origtar);
  301. my @origtarballs;
  302. foreach (sort $self->find_original_tarballs()) {
  303. if (/\.orig\.tar\.$compression_re_file_ext$/) {
  304. if (defined($tarfile)) {
  305. error(_g("several orig.tar files found (%s and %s) but only " .
  306. "one is allowed"), $tarfile, $_);
  307. }
  308. $tarfile = $_;
  309. push @origtarballs, $_;
  310. $self->add_file($_);
  311. } elsif (/\.orig-([[:alnum:]-]+)\.tar\.$compression_re_file_ext$/) {
  312. $origtar{$1} = $_;
  313. push @origtarballs, $_;
  314. $self->add_file($_);
  315. }
  316. }
  317. error(_g("no upstream tarball found at %s"),
  318. $self->upstream_tarball_template()) unless $tarfile;
  319. info(_g("building %s using existing %s"),
  320. $sourcepackage, "@origtarballs");
  321. # Unpack a second copy for comparison
  322. my $tmp = tempdir("$dirname.orig.XXXXXX", DIR => $updir);
  323. push @Dpkg::Exit::handlers, sub { erasedir($tmp) };
  324. # Extract main tarball
  325. my $tar = Dpkg::Source::Archive->new(filename => $tarfile);
  326. $tar->extract($tmp);
  327. # Extract additional orig tarballs
  328. foreach my $subdir (keys %origtar) {
  329. my $file = $origtar{$subdir};
  330. $tar = Dpkg::Source::Archive->new(filename => $file);
  331. $tar->extract("$tmp/$subdir");
  332. }
  333. # Copy over the debian directory
  334. erasedir("$tmp/debian");
  335. system("cp", "-a", "--", "$dir/debian", "$tmp/");
  336. subprocerr(_g("copy of the debian directory")) if $?;
  337. # Apply all patches except the last automatic one
  338. $self->apply_patches($tmp, skip_auto => 1, usage => 'build');
  339. # Prepare handling of binary files
  340. my %auth_bin_files;
  341. my $incbin_file = File::Spec->catfile($dir, "debian", "source", "include-binaries");
  342. if (-f $incbin_file) {
  343. open(INC, "<", $incbin_file) || syserr(_g("cannot read %s"), $incbin_file);
  344. while(defined($_ = <INC>)) {
  345. chomp; s/^\s*//; s/\s*$//;
  346. next if /^#/ or /^$/;
  347. $auth_bin_files{$_} = 1;
  348. }
  349. close(INC);
  350. }
  351. my @binary_files;
  352. my $handle_binary = sub {
  353. my ($self, $old, $new) = @_;
  354. my $relfn = File::Spec->abs2rel($new, $dir);
  355. # Include binaries if they are whitelisted or if
  356. # --include-binaries has been given
  357. if ($include_binaries or $auth_bin_files{$relfn}) {
  358. push @binary_files, $relfn;
  359. } else {
  360. errormsg(_g("cannot represent change to %s: %s"), $new,
  361. _g("binary file contents changed"));
  362. errormsg(_g("add %s in debian/source/include-binaries if you want" .
  363. " to store the modified binary in the debian tarball"),
  364. $relfn);
  365. $self->register_error();
  366. }
  367. };
  368. # Check if the debian directory contains unwanted binary files
  369. my $unwanted_binaries = 0;
  370. my $check_binary = sub {
  371. my $fn = File::Spec->abs2rel($_, $dir);
  372. if (-f $_ and is_binary($_)) {
  373. if ($include_binaries or $auth_bin_files{$fn}) {
  374. push @binary_files, $fn;
  375. } else {
  376. errormsg(_g("unwanted binary file: %s"), $fn);
  377. $unwanted_binaries++;
  378. }
  379. }
  380. };
  381. my $tar_ignore_glob = "{" . join(",",
  382. map {
  383. my $copy = $_;
  384. $copy =~ s/,/\\,/g;
  385. $copy;
  386. } @{$self->{'options'}{'tar_ignore'}}) . "}";
  387. my $filter_ignore = sub {
  388. # Filter out files that are not going to be included in the debian
  389. # tarball due to ignores.
  390. my %exclude;
  391. my $reldir = File::Spec->abs2rel($File::Find::dir, $dir);
  392. my $cwd = getcwd();
  393. # Apply the pattern both from the top dir and from the inspected dir
  394. chdir($dir) || syserr(_g("unable to chdir to `%s'"), $dir);
  395. $exclude{$_} = 1 foreach glob($tar_ignore_glob);
  396. chdir($cwd) || syserr(_g("unable to chdir to `%s'"), $cwd);
  397. chdir($File::Find::dir) ||
  398. syserr(_g("unable to chdir to `%s'"), $File::Find::dir);
  399. $exclude{$_} = 1 foreach glob($tar_ignore_glob);
  400. chdir($cwd) || syserr(_g("unable to chdir to `%s'"), $cwd);
  401. my @result;
  402. foreach my $fn (@_) {
  403. unless (exists $exclude{$fn} or exists $exclude{"$reldir/$fn"}) {
  404. push @result, $fn;
  405. }
  406. }
  407. return @result;
  408. };
  409. find({ wanted => $check_binary, preprocess => $filter_ignore,
  410. no_chdir => 1 }, File::Spec->catdir($dir, "debian"));
  411. error(P_("detected %d unwanted binary file (add it in " .
  412. "debian/source/include-binaries to allow its inclusion).",
  413. "detected %d unwanted binary files (add them in " .
  414. "debian/source/include-binaries to allow their inclusion).",
  415. $unwanted_binaries), $unwanted_binaries)
  416. if $unwanted_binaries;
  417. # Create a patch
  418. my $autopatch = File::Spec->catfile($dir, "debian", "patches",
  419. $self->get_autopatch_name());
  420. my ($difffh, $tmpdiff) = tempfile("$basenamerev.diff.XXXXXX",
  421. DIR => $updir, UNLINK => 0);
  422. push @Dpkg::Exit::handlers, sub { unlink($tmpdiff) };
  423. my $diff = Dpkg::Source::Patch->new(filename => $tmpdiff,
  424. compression => "none");
  425. $diff->create();
  426. $diff->set_header($self->get_patch_header($dir, $autopatch));
  427. $diff->add_diff_directory($tmp, $dir, basedirname => $basedirname,
  428. %{$self->{'diff_options'}}, handle_binary_func => $handle_binary,
  429. order_from => $autopatch);
  430. error(_g("unrepresentable changes to source")) if not $diff->finish();
  431. # The previous auto-patch must be removed, it has not been used and it
  432. # will be recreated if it's still needed
  433. if (-e $autopatch) {
  434. unlink($autopatch) || syserr(_g("cannot remove %s"), $autopatch);
  435. }
  436. # Install the diff as the new autopatch
  437. if (not -s $tmpdiff) {
  438. unlink($tmpdiff) || syserr(_g("cannot remove %s"), $tmpdiff);
  439. } else {
  440. mkpath(File::Spec->catdir($dir, "debian", "patches"));
  441. info(_g("local changes stored in %s, the modified files are:"), $autopatch);
  442. my $analysis = $diff->analyze($dir, verbose => 0);
  443. foreach my $fn (sort keys %{$analysis->{'filepatched'}}) {
  444. print " $fn\n";
  445. }
  446. rename($tmpdiff, $autopatch) ||
  447. syserr(_g("cannot rename %s to %s"), $tmpdiff, $autopatch);
  448. chmod(0666 & ~ umask(), $autopatch) ||
  449. syserr(_g("unable to change permission of `%s'"), $autopatch);
  450. }
  451. $self->register_autopatch($dir);
  452. if (-e $autopatch and $self->{'options'}{'abort_on_upstream_changes'}) {
  453. error(_g("aborting due to --abort-on-upstream-changes"));
  454. }
  455. rmdir(File::Spec->catdir($dir, "debian", "patches")); # No check on purpose
  456. pop @Dpkg::Exit::handlers;
  457. # Remove the temporary directory
  458. erasedir($tmp);
  459. pop @Dpkg::Exit::handlers;
  460. # Update debian/source/include-binaries if needed
  461. if (scalar(@binary_files) and $include_binaries) {
  462. mkpath(File::Spec->catdir($dir, "debian", "source"));
  463. open(INC, ">>", $incbin_file) || syserr(_g("cannot write %s"), $incbin_file);
  464. foreach my $binary (@binary_files) {
  465. unless ($auth_bin_files{$binary}) {
  466. print INC "$binary\n";
  467. info(_g("adding %s to %s"), $binary, "debian/source/include-binaries");
  468. }
  469. }
  470. close(INC);
  471. }
  472. # Create the debian.tar
  473. my $debianfile = "$basenamerev.debian.tar." . $self->{'options'}{'comp_ext'};
  474. info(_g("building %s in %s"), $sourcepackage, $debianfile);
  475. $tar = Dpkg::Source::Archive->new(filename => $debianfile);
  476. $tar->create(options => \@tar_ignore, 'chdir' => $dir);
  477. $tar->add_directory("debian");
  478. foreach my $binary (@binary_files) {
  479. $tar->add_file($binary) unless $binary =~ m{^debian/};
  480. }
  481. $tar->finish();
  482. $self->add_file($debianfile);
  483. }
  484. sub get_patch_header {
  485. my ($self, $dir) = @_;
  486. my $ph = File::Spec->catfile($dir, "debian", "source", "local-patch-header");
  487. unless (-f $ph) {
  488. $ph = File::Spec->catfile($dir, "debian", "source", "patch-header");
  489. }
  490. my $text;
  491. if (-f $ph) {
  492. open(PH, "<", $ph) || syserr(_g("cannot read %s"), $ph);
  493. $text = join("", <PH>);
  494. close(PH);
  495. return $text;
  496. }
  497. my $ch_info = changelog_parse(offset => 0, count => 1,
  498. file => File::Spec->catfile($dir, "debian", "changelog"));
  499. return '' if not defined $ch_info;
  500. my $header = Dpkg::Control->new(type => CTRL_UNKNOWN);
  501. $header->{'Description'} = "<short summary of the patch>\n";
  502. $header->{'Description'} .=
  503. "TODO: Put a short summary on the line above and replace this paragraph
  504. with a longer explanation of this change. Complete the meta-information
  505. with other relevant fields (see below for details). To make it easier, the
  506. information below has been extracted from the changelog. Adjust it or drop
  507. it.\n";
  508. $header->{'Description'} .= $ch_info->{'Changes'} . "\n";
  509. $header->{'Author'} = $ch_info->{'Maintainer'};
  510. $text = "$header";
  511. run_vendor_hook("extend-patch-header", \$text, $ch_info);
  512. $text .= "\n---
  513. The information above should follow the Patch Tagging Guidelines, please
  514. checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
  515. are templates for supplementary fields that you might want to add:
  516. Origin: <vendor|upstream|other>, <url of original patch>
  517. Bug: <url in upstream bugtracker>
  518. Bug-Debian: http://bugs.debian.org/<bugnumber>
  519. Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
  520. Forwarded: <no|not-needed|url proving that it has been forwarded>
  521. Reviewed-By: <name and email of someone who approved the patch>
  522. Last-Update: <YYYY-MM-DD>\n\n";
  523. return $text;
  524. }
  525. sub register_autopatch {
  526. my ($self, $dir) = @_;
  527. my $autopatch = File::Spec->catfile($dir, "debian", "patches",
  528. $self->get_autopatch_name());
  529. if (-e $autopatch) {
  530. my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied");
  531. open(APPLIED, '>>', $applied) || syserr(_g("cannot write %s"), $applied);
  532. print APPLIED ($self->get_autopatch_name() . "\n");
  533. close(APPLIED);
  534. }
  535. }
  536. # vim:et:sw=4:ts=8
  537. 1;