Dpkg
view release on metacpan or search on metacpan
lib/Dpkg/Source/Package/V2.pm view on Meta::CPAN
# Copyright © 2008-2011 Raphaël Hertzog <hertzog@debian.org>
# Copyright © 2008-2015 Guillem Jover <guillem@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
=encoding utf8
=head1 NAME
Dpkg::Source::Package::V2 - class for source format 2.0
=head1 DESCRIPTION
This module provides a class to handle the source package format 2.0.
B<Note>: This is a private module, its API can change at any time.
=cut
package Dpkg::Source::Package::V2 0.01;
use v5.36;
use List::Util qw(first);
use Cwd;
use File::Basename;
use File::Temp;
use File::Path qw(make_path);
use File::Spec;
use File::Find;
use File::Copy;
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::File;
use Dpkg::Path qw(find_command);
use Dpkg::Version;
use Dpkg::Compression;
use Dpkg::Source::Archive;
use Dpkg::Source::Patch;
use Dpkg::Source::BinaryFiles;
use Dpkg::Exit qw(push_exit_handler pop_exit_handler);
use Dpkg::Source::Functions qw(erasedir chmod_if_needed fs_time);
use Dpkg::Vendor qw(run_vendor_hook);
use Dpkg::Control;
use Dpkg::Changelog::Parse;
use parent qw(Dpkg::Source::Package);
our $CURRENT_MINOR_VERSION = '0';
sub init_options {
my $self = shift;
$self->SUPER::init_options();
$self->{options}{include_removal} //= 0;
$self->{options}{include_timestamp} //= 0;
$self->{options}{include_binaries} //= 0;
$self->{options}{preparation} //= 1;
$self->{options}{skip_patches} //= 0;
$self->{options}{unapply_patches} //= 'auto';
$self->{options}{skip_debianization} //= 0;
$self->{options}{create_empty_orig} //= 0;
$self->{options}{auto_commit} //= 0;
$self->{options}{ignore_bad_version} //= 0;
}
my @module_cmdline = (
{
name => '--include-removal',
help => N_('include removed files in the patch'),
when => 'build',
}, {
name => '--include-timestamp',
help => N_('include timestamp in the patch'),
when => 'build',
}, {
name => '--include-binaries',
help => N_('include binary files in the tarball'),
when => 'build',
}, {
name => '--no-preparation',
help => N_('do not prepare build tree by applying patches'),
when => 'build',
}, {
name => '--no-unapply-patches',
help => N_('do not unapply patches if previously applied'),
when => 'build',
}, {
name => '--unapply-patches',
help => N_('unapply patches if previously applied (default)'),
when => 'build',
}, {
name => '--create-empty-orig',
help => N_('create an empty original tarball if missing'),
when => 'build',
}, {
name => '--abort-on-upstream-changes',
help => N_('abort if generated diff has upstream files changes'),
when => 'build',
}, {
name => '--auto-commit',
help => N_('record generated patches, instead of aborting'),
when => 'build',
lib/Dpkg/Source/Package/V2.pm view on Meta::CPAN
if ($self->{options}->{single_debian_patch}) {
return <<'AUTOGEN_HEADER';
Description: Autogenerated patch header for a single-debian-patch file.
The delta against upstream is either kept as a single patch, or maintained
in some VCS, and exported as a single patch instead of more manageable
atomic patches.
Forwarded: not-needed
---
AUTOGEN_HEADER
}
my $ch_info = changelog_parse(
filename => $self->{options}{changelog_file},
offset => 0,
count => 1,
);
return '' if not defined $ch_info;
my $patch_date = POSIX::strftime('%b, %d %Y %T %z', gmtime);
my $text = <<"HEADER";
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: $ch_info->{'Maintainer'}
Date: $patch_date
Subject: [PATCH] <short summary of the patch>
TODO: Put a short summary on the line above and replace this paragraph
with a longer explanation of this change. Complete the meta-information
with other relevant fields (see below for details). To make it easier, the
information below has been extracted from the changelog. Adjust it or drop
it.
HEADER
run_vendor_hook('extend-patch-header', \$text, $ch_info);
$text .= <<'TRAILER';
---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:
Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-<Vendor>: <vendor-bugtracker-url>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
TRAILER
return $text;
}
sub register_patch {
my ($self, $dir, $patch_file, $patch_name) = @_;
my $patch = File::Spec->catfile($dir, 'debian', 'patches', $patch_name);
if (-s $patch_file) {
copy($patch_file, $patch)
or syserr(g_('failed to copy %s to %s'), $patch_file, $patch);
chmod_if_needed(0o666 & ~ umask(), $patch)
or syserr(g_("unable to change permission of '%s'"), $patch);
my $applied = File::Spec->catfile($dir, 'debian', 'patches', '.dpkg-source-applied');
open(my $applied_fh, '>>', $applied)
or syserr(g_('cannot write %s'), $applied);
print { $applied_fh } "$patch\n";
close($applied_fh) or syserr(g_('cannot close %s'), $applied);
} elsif (-e $patch) {
unlink($patch) or syserr(g_('cannot remove %s'), $patch);
}
return $patch;
}
sub _is_bad_patch_name {
my ($dir, $patch_name) = @_;
return 1 if not defined($patch_name);
return 1 if not length($patch_name);
my $patch = File::Spec->catfile($dir, 'debian', 'patches', $patch_name);
if (-e $patch) {
warning(g_('cannot register changes in %s, this patch already exists'),
$patch);
return 1;
}
return 0;
}
sub do_commit {
my ($self, $dir) = @_;
my ($patch_name, $tmpdiff) = @{$self->{options}{ARGV}};
$self->prepare_build($dir);
# Try to fix up a broken relative filename for the patch.
if ($tmpdiff and not -e $tmpdiff) {
$tmpdiff = File::Spec->catfile($dir, $tmpdiff)
unless File::Spec->file_name_is_absolute($tmpdiff);
error(g_("patch file '%s' does not exist"), $tmpdiff)
if not -e $tmpdiff;
}
my $binaryfiles = Dpkg::Source::BinaryFiles->new($dir);
my $handle_binary = sub {
my ($self, $old, $new, %opts) = @_;
my $fn = File::Spec->abs2rel($new, $dir);
$binaryfiles->new_binary_found($fn);
};
unless ($tmpdiff) {
$tmpdiff = $self->_generate_patch($dir,
handle_binary => $handle_binary,
usage => 'commit',
);
$binaryfiles->update_debian_source_include_binaries();
}
push_exit_handler(sub { unlink($tmpdiff) });
unless (-s $tmpdiff) {
unlink($tmpdiff) or syserr(g_('cannot remove %s'), $tmpdiff);
info(g_('there are no local changes to record'));
return;
( run in 2.127 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )