native.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Copyright 2008 Raphaël Hertzog <hertzog@debian.org>
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2 of the License, or
  5. # (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License along
  11. # with this program; if not, write to the Free Software Foundation, Inc.,
  12. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  13. package Dpkg::Source::Package::V3_0::native;
  14. use strict;
  15. use warnings;
  16. use base 'Dpkg::Source::Package';
  17. use Dpkg;
  18. use Dpkg::Gettext;
  19. use Dpkg::ErrorHandling qw(error syserr info usageerr);
  20. use Dpkg::Compression;
  21. use Dpkg::Source::Archive;
  22. use Dpkg::Source::Functions qw(erasedir);
  23. use POSIX;
  24. use File::Basename;
  25. use File::Temp qw(tempfile);
  26. sub do_extract {
  27. my ($self, $newdirectory) = @_;
  28. my $sourcestyle = $self->{'options'}{'sourcestyle'};
  29. my $fields = $self->{'fields'};
  30. my $dscdir = $self->{'basedir'};
  31. my $basename = $self->get_basename();
  32. my $basenamerev = $self->get_basename(1);
  33. my $tarfile;
  34. foreach my $file ($self->get_files()) {
  35. if ($file =~ /^\Q$basenamerev\E\.tar\.$comp_regex$/) {
  36. error(_g("multiple tarfiles in v1.0 source package")) if $tarfile;
  37. $tarfile = $file;
  38. } else {
  39. error(_g("unrecognized file for a native source package: %s"), $file);
  40. }
  41. }
  42. error(_g("no tarfile in Files field")) unless $tarfile;
  43. erasedir($newdirectory);
  44. info(_g("unpacking %s"), $tarfile);
  45. my $tar = Dpkg::Source::Archive->new(filename => "$dscdir$tarfile");
  46. $tar->extract($newdirectory);
  47. }
  48. sub can_build {
  49. return 1;
  50. }
  51. sub do_build {
  52. my ($self, $dir) = @_;
  53. my @tar_ignore = map { "--exclude=$_" } @{$self->{'options'}{'tar_ignore'}};
  54. my @argv = @{$self->{'options'}{'ARGV'}};
  55. if (scalar(@argv)) {
  56. usageerr(_g("-b takes only one parameter with format `%s'"),
  57. $self->{'fields'}{'Format'});
  58. }
  59. my $sourcepackage = $self->{'fields'}{'Source'};
  60. my $basenamerev = $self->get_basename(1);
  61. my $tarname = "$basenamerev.tar." . $self->{'options'}{'comp_ext'};
  62. info(_g("building %s in %s"), $sourcepackage, $tarname);
  63. my ($ntfh, $newtar) = tempfile("$tarname.new.XXXXXX",
  64. DIR => getcwd(), UNLINK => 0);
  65. my ($dirname, $dirbase) = fileparse($dir);
  66. my $tar = Dpkg::Source::Archive->new(filename => $newtar,
  67. compression => get_compression_from_filename($tarname),
  68. compression_level => $self->{'options'}{'comp_level'});
  69. $tar->create(options => \@tar_ignore, 'chdir' => $dirbase);
  70. $tar->add_directory($dirname);
  71. $tar->finish();
  72. rename($newtar, $tarname) ||
  73. syserr(_g("unable to rename `%s' (newly created) to `%s'"),
  74. $newtar, $tarname);
  75. $self->add_file($tarname);
  76. # For backward compatibility, drop version to 1.0 if we can
  77. if ($self->{'options'}{'compression'} eq "gzip") {
  78. $self->{'fields'}{'Format'} = "1.0";
  79. }
  80. }
  81. # vim: set et sw=4 ts=8
  82. 1;