native.pm 3.2 KB

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