native.pm 3.3 KB

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