native.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Copyright © 2008 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::V3::native;
  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::Exit;
  25. use Dpkg::Source::Archive;
  26. use Dpkg::Source::Functions qw(erasedir);
  27. use Cwd;
  28. use File::Basename;
  29. use File::Temp qw(tempfile);
  30. our $CURRENT_MINOR_VERSION = "0";
  31. sub do_extract {
  32. my ($self, $newdirectory) = @_;
  33. my $sourcestyle = $self->{'options'}{'sourcestyle'};
  34. my $fields = $self->{'fields'};
  35. my $dscdir = $self->{'basedir'};
  36. my $basename = $self->get_basename();
  37. my $basenamerev = $self->get_basename(1);
  38. my $tarfile;
  39. foreach my $file ($self->get_files()) {
  40. if ($file =~ /^\Q$basenamerev\E\.tar\.$compression_re_file_ext$/) {
  41. error(_g("multiple tarfiles in v1.0 source package")) if $tarfile;
  42. $tarfile = $file;
  43. } else {
  44. error(_g("unrecognized file for a native source package: %s"), $file);
  45. }
  46. }
  47. error(_g("no tarfile in Files field")) unless $tarfile;
  48. erasedir($newdirectory);
  49. info(_g("unpacking %s"), $tarfile);
  50. my $tar = Dpkg::Source::Archive->new(filename => "$dscdir$tarfile");
  51. $tar->extract($newdirectory);
  52. }
  53. sub can_build {
  54. return 1;
  55. }
  56. sub do_build {
  57. my ($self, $dir) = @_;
  58. my @tar_ignore = map { "--exclude=$_" } @{$self->{'options'}{'tar_ignore'}};
  59. my @argv = @{$self->{'options'}{'ARGV'}};
  60. if (scalar(@argv)) {
  61. usageerr(_g("-b takes only one parameter with format `%s'"),
  62. $self->{'fields'}{'Format'});
  63. }
  64. my $sourcepackage = $self->{'fields'}{'Source'};
  65. my $basenamerev = $self->get_basename(1);
  66. my $tarname = "$basenamerev.tar." . $self->{'options'}{'comp_ext'};
  67. info(_g("building %s in %s"), $sourcepackage, $tarname);
  68. my ($ntfh, $newtar) = tempfile("$tarname.new.XXXXXX",
  69. DIR => getcwd(), UNLINK => 0);
  70. push @Dpkg::Exit::handlers, sub { unlink($newtar) };
  71. my ($dirname, $dirbase) = fileparse($dir);
  72. my $tar = Dpkg::Source::Archive->new(filename => $newtar,
  73. compression => compression_guess_from_filename($tarname),
  74. compression_level => $self->{'options'}{'comp_level'});
  75. $tar->create(options => \@tar_ignore, 'chdir' => $dirbase);
  76. $tar->add_directory($dirname);
  77. $tar->finish();
  78. rename($newtar, $tarname) ||
  79. syserr(_g("unable to rename `%s' (newly created) to `%s'"),
  80. $newtar, $tarname);
  81. pop @Dpkg::Exit::handlers;
  82. chmod(0666 &~ umask(), $tarname) ||
  83. syserr(_g("unable to change permission of `%s'"), $tarname);
  84. $self->add_file($tarname);
  85. }
  86. 1;