Custom.pm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <https://www.gnu.org/licenses/>.
  15. package Dpkg::Source::Package::V3::Custom;
  16. use strict;
  17. use warnings;
  18. our $VERSION = '0.01';
  19. use Dpkg::Gettext;
  20. use Dpkg::ErrorHandling;
  21. use parent qw(Dpkg::Source::Package);
  22. our $CURRENT_MINOR_VERSION = '0';
  23. my @module_cmdline = (
  24. {
  25. name => '--target-format=<value>',
  26. help => N_('define the format of the generated source package'),
  27. when => 'build',
  28. }
  29. );
  30. sub describe_cmdline_options {
  31. return @module_cmdline;
  32. }
  33. sub parse_cmdline_option {
  34. my ($self, $opt) = @_;
  35. if ($opt =~ /^--target-format=(.*)$/) {
  36. $self->{options}{target_format} = $1;
  37. return 1;
  38. }
  39. return 0;
  40. }
  41. sub do_extract {
  42. error(g_("Format '3.0 (custom)' is only used to create source packages"));
  43. }
  44. sub can_build {
  45. my ($self, $dir) = @_;
  46. return (0, g_('no files indicated on command line'))
  47. unless scalar(@{$self->{options}{ARGV}});
  48. return 1;
  49. }
  50. sub do_build {
  51. my ($self, $dir) = @_;
  52. # Update real target format
  53. my $format = $self->{options}{target_format};
  54. error(g_('--target-format option is missing')) unless $format;
  55. $self->{fields}{'Format'} = $format;
  56. # Add all files
  57. foreach my $file (@{$self->{options}{ARGV}}) {
  58. $self->add_file($file);
  59. }
  60. }
  61. 1;