Native.pm 3.5 KB

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