native.pm 3.2 KB

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