File Coverage

blib/lib/DhMakePerl/Command/make.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             package DhMakePerl::Command::make;
2              
3 3     3   2701411 use warnings;
  3         9  
  3         292  
4 3     3   28 use strict;
  3         17  
  3         208  
5             our $VERSION = '0.84';
6 3     3   228 use 5.010; # we use smart matching
  3         28  
7              
8 3     3   27 use base 'DhMakePerl::Command::Packaging';
  3         16  
  3         3004  
9             use DhMakePerl::Utils qw(apt_cache);
10              
11             __PACKAGE__->mk_accessors(
12             qw(
13             cfg apt_contents main_dir debian_dir meta
14             perlname version pkgversion
15             copyright author
16             extrasfields extrapfields
17             docs examples
18             )
19             );
20              
21             =head1 NAME
22              
23             DhMakePerl::Command::make - implementation of 'dh-make-perl make'
24              
25             =cut
26              
27             =head1 SYNOPSIS
28              
29             TO BE FILLED
30              
31             use DhMakePerl;
32              
33             my $foo = DhMakePerl->new();
34             ...
35              
36             =head1 METHODS
37              
38             =over
39              
40             =cut
41              
42             use CPAN ();
43             use Cwd qw( realpath );
44             use Debian::Dependencies ();
45             use Debian::Dependency ();
46             use Debian::WNPP::Query;
47             use DhMakePerl::Utils qw(
48             find_cpan_module find_cpan_distribution
49             is_core_module );
50             use Email::Date::Format qw(email_date);
51             use File::Basename qw( basename dirname );
52             use File::Copy qw( copy move );
53             use File::Path ();
54             use File::Spec::Functions qw( catdir catfile updir );
55             use Module::Depends ();
56             use Module::Metadata;
57             use Text::Wrap qw( wrap );
58              
59             sub check_deprecated_overrides {
60             my $self = shift;
61              
62             my $overrides = catfile( $self->cfg->data_dir, 'overrides' );
63              
64             if ( -e $overrides ) {
65             warn "*** deprecated overrides file ignored\n";
66             warn "***\n";
67             warn "*** Overrides mechanism is deprecated in dh-make-perl 0.65\n";
68             warn "*** You may want to remove $overrides\n";
69             }
70             }
71              
72             sub execute {
73             my ( $self, $already_done ) = @_;
74              
75             die "CPANPLUS support disabled, sorry" if $self->cfg->cpanplus;
76              
77             $self->check_deprecated_overrides;
78              
79             my $tarball = $self->setup_dir();
80             $self->process_meta;
81             $self->findbin_fix();
82              
83             $self->extract_basic();
84              
85             $tarball //= $self->guess_debian_tarball if $self->cfg->{vcs} eq 'git';
86              
87             unless ( defined $self->cfg->version ) {
88             $self->pkgversion( $self->version . '-1' );
89             }
90             else {
91             $self->pkgversion( $self->cfg->version );
92             }
93              
94             $self->fill_maintainer;
95              
96             my $bin = $self->control->binary_tie->Values(0);
97             $bin->short_description( $self->cfg->desc )
98             if $self->cfg->desc;
99              
100             if ( $tarball and $tarball =~ /(?:\.tar\.gz|\.tgz)$/ ) {
101             my $dest = sprintf( "%s/%s_%s.orig.tar.gz",
102             dirname($tarball), $self->pkgname, $self->version );
103              
104             move( $tarball, $dest ) or die "move($tarball, $dest): $!";
105              
106             $tarball = $dest;
107             }
108              
109             # Here I init the git repo. If the upstream has a debian/ directory, this is
110             # removed in a separate git commit
111             $self->git_import_upstream__init_debian
112             if $self->cfg->{vcs} eq 'git';
113              
114             # if the upstream has a debian/ directory, rename it to debian.bak so that
115             # dh-make-perl can create its own debian/ directory. If we're creating a git
116             # repo, the original debian/ directory was already dealt with by
117             # git_import_upstream__init_debian()
118             if ( -d $self->debian_dir ) {
119             $self->warning( $self->debian_dir . ' already exists' );
120             my $bak = $self->debian_dir . '.bak';
121             $self->warning( "moving to $bak" );
122             if ( -d $bak ) {
123             $self->warning("overwriting existing $bak");
124             File::Path::rmtree($bak);
125             }
126             rename $self->debian_dir, $bak or die $!;
127             }
128              
129             my $apt_contents = $self->get_apt_contents;
130             my $src = $self->control->source;
131              
132             $src->Testsuite('autopkgtest-pkg-perl') if $self->cfg->{pkg_perl};
133              
134             my @missing = $self->discover_dependencies;
135              
136             $bin->Depends->add( $self->cfg->depends )
137             if $self->cfg->depends;
138              
139             $src->Build_Depends->add( $self->cfg->bdepends )
140             if $self->cfg->bdepends;
141              
142             $src->Build_Depends_Indep->add( $self->cfg->bdependsi )
143             if $self->cfg->bdependsi;
144              
145             $self->extract_docs;
146             $self->extract_examples;
147              
148             die "Cannot find a description for the package: use the --desc switch\n"
149             unless $bin->short_description;
150              
151             print "Package does not provide a long description - ",
152             " Please fill it in manually.\n"
153             if ( !defined $bin->long_description
154             or $bin->long_description =~ /^\s*\.?\s*$/ )
155             and $self->cfg->verbose;
156              
157             printf( "Using maintainer: %s\n", $src->Maintainer )
158             if $self->cfg->verbose;
159              
160             print "Found docs: @{ $self->docs }\n" if $self->cfg->verbose;
161             print "Found examples: @{ $self->examples }\n"
162             if @{ $self->examples } and $self->cfg->verbose;
163              
164             # start writing out the data
165             mkdir( $self->debian_dir, 0755 )
166             || die "Cannot create " . $self->debian_dir . " dir: $!\n";
167             $self->write_source_format(
168             catfile( $self->debian_dir, 'source', 'format' ) );
169             $self->create_changelog( $self->debian_file('changelog'),
170             $self->cfg->closes // $self->get_wnpp( $self->pkgname ) );
171             $self->create_rules;
172              
173             # now that rules are there, see if we need some dependency for them
174             $self->discover_utility_deps( $self->control );
175             $self->control->prune_perl_deps;
176             $self->prune_deps;
177             $src->Standards_Version( $self->debstdversion );
178             $src->Homepage( $self->upsurl );
179             if ( $self->cfg->pkg_perl ) {
180             my $vcs = lc( $self->cfg->vcs );
181             if ( $vcs eq 'svn' ) {
182             $self->control->source->Vcs_Svn(
183             sprintf( "svn://svn.debian.org/pkg-perl/trunk/%s/",
184             $self->pkgname )
185             );
186             $self->control->source->Vcs_Browser(
187             sprintf( "http://anonscm.debian.org/viewvc/pkg-perl/trunk/%s/",
188             $self->pkgname )
189             );
190             }
191             elsif ( $vcs eq 'git' ) {
192             $self->control->source->Vcs_Git(
193             sprintf( "git://anonscm.debian.org/pkg-perl/packages/%s.git",
194             $self->pkgname )
195             );
196             $self->control->source->Vcs_Browser(
197             sprintf( "https://anonscm.debian.org/cgit/pkg-perl/packages/%s.git",
198             $self->pkgname )
199             );
200             }
201             else {
202             warn "Version control system '$vcs' not known. Please submit a patch :)\n";
203             }
204             }
205             $self->control->write( $self->debian_file('control') );
206              
207             $self->create_compat( $self->debian_file('compat') );
208             $self->create_watch( $self->debian_file('watch') );
209              
210             #create_readme("$debiandir/README.Debian");
211             $self->create_copyright( $self->debian_file('copyright') );
212             $self->update_file_list( docs => $self->docs, examples => $self->examples );
213              
214             $self->create_upstream_metadata;
215              
216             if ( $self->cfg->recursive ) {
217             $already_done //= {};
218             my $mod_name = $self->perlname;
219             $mod_name =~ s/-/::/g;
220             $already_done->{$mod_name} = 1;
221              
222             for my $m (@missing) {
223             next if exists $already_done->{$m};
224              
225             if ( $self->cfg->verbose ) {
226             print "\n";
227             print "==================================\n";
228             print " recursively building $m\n";
229             print "==================================\n";
230             }
231              
232             my $new_cfg
233             = DhMakePerl::Config->new( { %{ $self->cfg }, cpan => $m, } );
234             my $maker = $self->new( { cfg => $new_cfg } );
235             $maker->execute($already_done)
236             }
237             }
238              
239             $self->git_add_debian($tarball)
240             if $self->cfg->{vcs} eq 'git';
241              
242             $self->build_source_package
243             if $self->cfg->build_source;
244             $self->build_package
245             if $self->cfg->build or $self->cfg->install;
246             $self->install_package if $self->cfg->install;
247             print "--- Done\n" if $self->cfg->verbose;
248              
249             $self->package_already_exists($apt_contents)
250             or $self->modules_already_packaged($apt_contents);
251              
252             # explicitly call Debian::Rules destroy
253             # this is needed because after the rename the object's
254             # destroy method would update a file on a stale path
255             $self->rules( undef );
256             $self->rename_to_debian_package_dir;
257              
258             return(0);
259             }
260              
261             sub guess_debian_tarball {
262             my $self = shift;
263              
264             my $prefix = catfile( $self->main_dir, '..',
265             $self->control->source->Source . '_'
266             . $self->version
267             . '.orig' );
268             $self->guess_tarball($prefix);
269             }
270              
271             sub guess_tarball {
272             my $self = shift;
273             my $prefix = shift;
274             die "guess_tarball(): Needs everything except the file type suffix as parameter"
275             unless defined $prefix;
276              
277             foreach my $compression_suffix (qw(gz bz2 xz lzma)) {
278             my $try = "$prefix.tar.$compression_suffix";
279              
280             print "Trying $try...";
281             if ( -f $try ) {
282             print " found!\n";
283             return $try;
284             }
285             else {
286             print " not found.\n";
287             }
288             }
289             return undef;
290             }
291              
292             sub setup_dir {
293             my ($self) = @_;
294              
295             my ( $tarball );
296             if ( $self->cfg->cpan ) {
297             my ( $new_maindir, $orig_pwd, $mod, $dist );
298              
299             # CPAN::Distribution::get() sets $ENV{'PWD'} to $CPAN::Config->{build_dir}
300             # so we have to save it here
301             $orig_pwd = $ENV{'PWD'};
302              
303             # Is the module a core module?
304             if ( is_core_module( $self->cfg->cpan ) ) {
305             die $self->cfg->cpan
306             . " is a standard module. Will not build without --core-ok.\n"
307             unless $self->cfg->core_ok;
308             }
309              
310             $self->configure_cpan;
311              
312             if ( $mod = find_cpan_module( $self->cfg->cpan ) ) {
313             $self->mod_cpan_version( $mod->cpan_version );
314              
315             $dist = $CPAN::META->instance( 'CPAN::Distribution',
316             $mod->cpan_file );
317             }
318             elsif ( $dist = find_cpan_distribution( $self->cfg->cpan ) ) {
319             my $ver;
320             if ( $dist->base_id =~ /-v?(\d[\d._]*)\./ ) {
321             $self->mod_cpan_version($1);
322             }
323             else {
324             die "Unable to determine the version of "
325             . $dist->base_id . "\n";
326             }
327             }
328             else {
329             die "Can't find '"
330             . $self->cfg->cpan
331             . "' module or distribution on CPAN\n";
332             }
333              
334             $dist->get; # <- here $ENV{'PWD'} gets set to $HOME/.cpan/build
335             chdir $orig_pwd; # so set it back
336             $dist->pretty_id =~ /^(.)(.)/;
337             $tarball = $CPAN::Config->{'keep_source_where'} . "/authors/id/$1/$1$2/";
338             # the file is under authors/id/A/AU/AUTHOR directory
339             # how silly there is no $dist->filename method
340              
341             $tarball .= $dist->pretty_id;
342             $self->main_dir( $dist->dir );
343              
344             copy( $tarball, $orig_pwd ) or die "copy($tarball, $orig_pwd): $!";
345             $tarball = $orig_pwd . "/" . basename($tarball);
346              
347             # build_dir contains a random part since 1.88_59
348             # use the new CPAN::Distribution::base_id (introduced in 1.91_53)
349             $new_maindir = $orig_pwd . "/" . $dist->base_id;
350              
351             # rename existing directory
352             my $new_inc;
353             my $rename_to = "$new_maindir.$$";
354             while (-d $rename_to)
355             {
356             $new_inc++;
357             $rename_to = "$new_maindir.$$-$new_inc";
358             }
359             if ( -d $new_maindir
360             && rename $new_maindir, $rename_to)
361             {
362             print '=' x 70, "\n";
363             print
364             "Unpacked tarball already existed, directory renamed to $rename_to\n";
365             print '=' x 70, "\n";
366             }
367             system( "mv", $self->main_dir, "$new_maindir" ) == 0
368             or die "Failed to move " . $self->main_dir . " to $new_maindir: $!";
369             $self->main_dir($new_maindir);
370              
371             }
372             elsif ( $self->cfg->cpanplus ) {
373             die "CPANPLUS support is b0rken at the moment.";
374              
375             # my ($cb, $href, $file);
376              
377             # eval "use CPANPLUS 0.045;";
378             # $cb = CPANPLUS::Backend->new(conf => {debug => 1, verbose => 1});
379             # $href = $cb->fetch( modules => [ $self->cfg->cpanplus ], fetchdir => $ENV{'PWD'});
380             # die "Cannot get " . $self->cfg->cpanplus . "\n" if keys(%$href) != 1;
381             # $file = (values %$href)[0];
382             # print $file, "\n\n";
383             # $self->main_dir(
384             # $cb->extract( files => [ $file ], extractdir => $ENV{'PWD'} )->{$file}
385             # );
386             }
387             else {
388             my $maindir = realpath( shift(@ARGV) || '.' );
389             $maindir =~ s/\/$//;
390             $self->main_dir($maindir);
391             my $guessed_tarball_prefix = catfile( $self->main_dir, "..",
392             basename( $self->main_dir ) );
393              
394             $tarball = $self->guess_tarball($guessed_tarball_prefix);
395             }
396             return $tarball;
397             }
398              
399             sub build_package {
400             my ( $self ) = @_;
401              
402             my $main_dir = $self->main_dir;
403             # uhmf! dpkg-genchanges doesn't cope with the deb being in another dir..
404             #system("dpkg-buildpackage -b -us -uc " . $self->cfg->dbflags) == 0
405             system("fakeroot make -C $main_dir -f debian/rules clean");
406             system("make -C $main_dir -f debian/rules build") == 0
407             || die "Cannot create deb package: 'debian/rules build' failed.\n";
408             system("fakeroot make -C $main_dir -f debian/rules binary") == 0
409             || die "Cannot create deb package: 'fakeroot debian/rules binary' failed.\n";
410             }
411              
412             sub build_source_package {
413             my ( $self ) = @_;
414              
415             my $main_dir = $self->main_dir;
416             # uhmf! dpkg-genchanges doesn't cope with the deb being in another dir..
417             #system("dpkg-buildpackage -S -us -uc " . $self->cfg->dbflags) == 0
418             system("fakeroot make -C $main_dir -f debian/rules clean");
419             system("dpkg-source -b $main_dir") == 0
420             || die "Cannot create source package: 'dpkg-source -b' failed.\n";
421             }
422              
423             sub install_package {
424             my ($self) = @_;
425              
426             my ( $archspec, $debname );
427              
428             my $arch = $self->control->binary_tie->Values(0)->Architecture;
429              
430             if ( !defined $arch || $arch eq 'any' ) {
431             $archspec = `dpkg --print-architecture`;
432             chomp($archspec);
433             }
434             else {
435             $archspec = $arch;
436             }
437              
438             $debname = sprintf( "%s_%s-1_%s.deb", $self->pkgname, $self->version,
439             $archspec );
440              
441             my $deb = $self->main_dir . "/../$debname";
442             my $dpkg_cmd = "dpkg -i $deb";
443             $dpkg_cmd = "sudo $dpkg_cmd" if $>;
444             $self->info("Running '$dpkg_cmd'...");
445             system($dpkg_cmd) == 0
446             || die "Cannot install package $deb\n";
447             }
448              
449             sub findbin_fix {
450             my ($self) = @_;
451              
452             # FindBin requires to know the name of the invoker - and requires it to be
453             # Makefile.PL to function properly :-/
454             $0 = $self->makefile_pl();
455             if ( exists $FindBin::{Bin} ) {
456             FindBin::again();
457             }
458             }
459              
460             # finds the list of modules that the distribution depends on
461             # if $build_deps is true, returns build-time dependencies, otherwise
462             # returns run-time dependencies
463             sub run_depends {
464             my ( $self, $depends_module, $build_deps ) = @_;
465              
466             no warnings;
467             local *STDERR;
468             open( STDERR, ">/dev/null" );
469             my $mod_dep = $depends_module->new();
470              
471             $mod_dep->dist_dir( $self->main_dir );
472             $mod_dep->find_modules();
473              
474             my $deps = $build_deps ? $mod_dep->build_requires : $mod_dep->requires;
475              
476             my $error = $mod_dep->error();
477             die "Error: $error\n" if $error;
478              
479             return $deps;
480             }
481              
482             # filter @deps to contain only one instance of each package
483             # say we have te following list of dependencies:
484             # libppi-perl, libppi-perl (>= 3.0), libarm-perl, libalpa-perl, libarm-perl (>= 2)
485             # we want a clean list instead:
486             # libalpa-perl, libarm-perl (>= 2), libppi-perl (>= 3.0)
487             sub prune_deps(@) {
488             my $self = shift;
489              
490             my %deps;
491             for (@_) {
492             my $p = $_->pkg;
493             my $v = $_->ver;
494             if ( exists $deps{$p} ) {
495             my $cur_ver = $deps{$p};
496              
497             $deps{$p} = $v
498             if defined($v)
499             and ( not defined($cur_ver)
500             or $cur_ver < $v );
501             }
502             else {
503             $deps{$p} = $v;
504             }
505              
506             }
507              
508             return map( Debian::Dependency->new( $_, $deps{$_} ), sort( keys(%deps) ) );
509             }
510              
511             sub create_changelog {
512             my ( $self, $file, $bug ) = @_;
513              
514             my $fh = $self->_file_w($file);
515              
516             my $closes = $bug ? " (Closes: #$bug)" : '';
517             my $changelog_dist = $self->cfg->pkg_perl ? "UNRELEASED" : "unstable";
518              
519             $fh->printf( "%s (%s) %s; urgency=low\n",
520             $self->srcname, $self->pkgversion, $changelog_dist );
521             $fh->print("\n * Initial Release.$closes\n\n");
522             $fh->printf( " -- %s %s\n", $self->get_developer,
523             email_date(time) );
524              
525             #$fh->print("Local variables:\nmode: debian-changelog\nEnd:\n");
526             $fh->close;
527             }
528              
529             sub create_readme {
530             my ( $self, $filename ) = @_;
531              
532             my $fh = $self->_file_w($filename);
533             $fh->printf(
534             "This is the debian package for the %s module.
535             It was created by %s using dh-make-perl.
536             ", $self->perlname, $self->maintainer,
537             );
538             $fh->close;
539             }
540              
541             sub create_watch {
542             my ( $self, $filename ) = @_;
543              
544             my $fh = $self->_file_w($filename);
545              
546             my $version_re = 'v?(\d[\d.-]*)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip)';
547              
548             $fh->printf( "version=3\n%s .*/%s-%s\$\n",
549             $self->upsurl, $self->perlname, $version_re );
550             $fh->close;
551             }
552              
553             sub search_pkg_perl {
554             my $self = shift;
555              
556             return undef unless $self->cfg->network;
557              
558             my $pkg = $self->pkgname;
559              
560             require LWP::UserAgent;
561             require LWP::ConnCache;
562              
563             my ( $ua, $resp );
564              
565             $ua = LWP::UserAgent->new;
566             $ua->env_proxy;
567             $ua->conn_cache( LWP::ConnCache->new );
568              
569             $resp = $ua->get(
570             "https://anonscm.debian.org/cgit/pkg-perl/packages/$pkg.git");
571             return { url => $resp->request->uri }
572             if $resp->is_success;
573              
574             $resp = $ua->get(
575             "https://anonscm.debian.org/cgit/pkg-perl/attic/$pkg.git");
576             return { url => $resp->request->uri }
577             if $resp->is_success;
578              
579             return undef;
580             }
581              
582             sub rename_to_debian_package_dir {
583             my( $self ) = @_;
584             return unless $self->cfg->cpan;
585              
586             my $maindir = $self->main_dir;
587             my $newmaindir = catdir( $maindir, updir(), $self->pkgname );
588              
589             if( -d $newmaindir ) {
590             warn "$newmaindir already exists, skipping rename";
591             return;
592             }
593              
594             rename $maindir, $newmaindir or die "rename failed: $self->main_dir to $newmaindir";
595             $self->main_dir( $newmaindir );
596             return;
597             }
598              
599             sub package_already_exists {
600             my( $self, $apt_contents ) = @_;
601              
602             my $found;
603             if (my $apt_cache = apt_cache())
604             {
605             $found = $apt_cache->packages->lookup( $self->pkgname );
606             }
607              
608             if ($found) {
609             warn "**********\n";
610             warn "WARNING: a package named\n";
611             warn " '" . $self->pkgname ."'\n";
612             warn " is already available in APT repositories\n";
613             warn "Maintainer: ", $found->{Maintainer}, "\n";
614             my $short_desc = (split( /\n/, $found->{LongDesc} ))[0];
615             warn "Description: $short_desc\n";
616             }
617             elsif ($apt_contents) {
618             $found = $apt_contents->find_perl_module_package( $self->perlname );
619              
620             if ($found) {
621             ( my $mod_name = $self->perlname ) =~ s/-/::/g;
622             warn "**********\n";
623             warn "NOTICE: the package '$found', available in APT repositories\n";
624             warn " already contains a module named "
625             . $self->perlname . "\n";
626             }
627             elsif ( $found = $self->search_pkg_perl ) {
628             warn "********************\n";
629             warn sprintf(
630             "The Debian Perl Group has a repository for the %s package\n at %s\n",
631             $self->pkgname, $found->{url} );
632             warn "You may want to contact them to avoid duplication of effort.\n";
633             warn "More information is available at https://wiki.debian.org/Teams/DebianPerlGroup\n";
634             }
635             }
636             else {
637             ( my $mod_name = $self->perlname ) =~ s/-/::/g;
638             require Debian::DpkgLists;
639             my @found = Debian::DpkgLists->scan_perl_mod($mod_name);
640              
641             if (@found) {
642             warn "**********\n";
643             warn "NOTICE: the following locally installed package(s) already\n";
644             warn " contain $mod_name\n";
645             warn " ", join ( ', ', @found ), "\n";
646             $found = 1;
647             }
648             }
649              
650             return $found ? 1 : 0;
651             }
652              
653             sub modules_already_packaged {
654             my( $self, $apt_contents ) = @_;
655              
656             my @modules;
657              
658             File::Find::find(
659             sub {
660             if (basename($File::Find::dir)
661             =~ /^(?:
662             \.(?:git|svn|hg|)
663             |CVS
664             |eg|samples?|examples?
665             |t|xt
666             |inc|privinc
667             )$/x
668             )
669             {
670             $File::Find::prune = 1;
671             return;
672             }
673             if (/.+\.pm$/) {
674             my $mi = Module::Metadata->new_from_file($_);
675             push @modules, $mi->packages_inside;
676             }
677             },
678             $self->main_dir,
679             );
680              
681             my $found;
682              
683             sub show_notice($$) {
684             warn $_[0] unless $_[1];
685             $_[1] = 1;
686             }
687              
688             my $notice = <
689             *** Notice ***
690             Some of the modules in the newly created package are already present
691             in other packages.
692              
693             EOF
694             my $notice_shown = 0;
695              
696             for my $mod (@modules) {
697             if ($apt_contents) {
698             $found = $apt_contents->find_perl_module_package($mod);
699              
700             if ($found) {
701             show_notice( $notice, $notice_shown );
702             warn " $mod is in '$found' (APT)\n";
703             }
704             }
705             if ( !$found ) {
706             require Debian::DpkgLists;
707             my @found = Debian::DpkgLists->scan_perl_mod($mod);
708              
709             if (@found) {
710             show_notice( $notice, $notice_shown );
711             warn " $mod is in " . join( ', ', @found ), " (local .deb)\n";
712             $found = 1;
713             }
714             }
715             }
716              
717             warn "\n" if $notice_shown;
718              
719             return $found ? 1 : 0;
720             }
721              
722             sub reset_git_environment {
723             # The Git environment variables may be set from previous iterations
724             # of this program being run. In this case, it's possible that the
725             # Git module will use these to point to the wrong source tree.
726             delete $ENV{'GIT_DIR'};
727             delete $ENV{'GIT_WORK_TREE'};
728             }
729              
730             sub git_import_upstream__init_debian {
731             my ( $self ) = @_;
732              
733             require Git;
734              
735             $self->reset_git_environment();
736              
737             Git::command( 'init', $self->main_dir );
738              
739             my $git = Git->repository( $self->main_dir );
740             $git->command( qw(symbolic-ref HEAD refs/heads/upstream) );
741             $git->command( 'add', '.' );
742             $git->command( 'commit', '-m',
743             "Import original source of "
744             . $self->perlname . ' '
745             . $self->version );
746             $git->command( 'tag', "upstream/".$self->version, 'upstream' );
747              
748             $git->command( qw( checkout -b master upstream ) );
749             if ( -d $self->debian_dir ) {
750             # remove debian/ directory if the upstream ships it. This goes into the
751             # 'master' branch, so the 'upstream' branch contains the original debian/
752             # directory, and thus matches the pristine-tar. Here I also remove the
753             # debian/ directory from the working tree; git has the history, so I don't
754             # need the debian.bak
755             $git->command( 'rm', '-r', $self->debian_dir );
756             $git->command( 'commit', '-m',
757             'Removed debian directory embedded in upstream source' );
758             }
759             }
760              
761             sub git_add_debian {
762             my ( $self, $tarball ) = @_;
763              
764             require Git;
765             require File::Which;
766              
767             $self->reset_git_environment;
768              
769             my $git = Git->repository( $self->main_dir );
770             $git->command( 'add', 'debian' );
771             $git->command( 'commit', '-m',
772             "Initial packaging by dh-make-perl $VERSION" );
773             $git->command(
774             qw( remote add origin ),
775             sprintf( "ssh://git.debian.org/git/pkg-perl/packages/%s.git",
776             $self->pkgname ),
777             ) if $self->cfg->pkg_perl;
778              
779             if ( File::Which::which('pristine-tar') ) {
780             if ( $tarball and -f $tarball ) {
781             $ENV{GIT_DIR} = File::Spec->catdir( $self->main_dir, '.git' );
782             system( 'pristine-tar', 'commit', $tarball, "upstream/".$self->version ) >= 0
783             or warn "error running pristine-tar: $!\n";
784             }
785             else {
786             die "No tarball found to handle with pristine-tar. Bailing out."
787             }
788             }
789             else {
790             warn "W: pristine-tar not available. Please run\n";
791             warn "W: apt-get install pristine-tar\n";
792             warn "W: followed by\n";
793             warn "W: pristine-tar commit $tarball upstream/"
794             . $self->version . "\n";
795             }
796             }
797              
798             =item warning I ...
799              
800             In verbose mode, prints supplied arguments on STDERR, prepended with C and
801             suffixed with a new line.
802              
803             Does nothing in non-verbose mode.
804              
805             =cut
806              
807             sub warning {
808             my $self = shift;
809              
810             return unless $self->cfg->verbose;
811              
812             warn "W: ", @_, "\n";
813             }
814              
815             =item info I ...
816              
817             In verbose mode, prints supplied arguments on STDERR, prepended with C and
818             suffixed with a new line.
819              
820             Does nothing in non-verbose mode.
821              
822             =cut
823              
824             sub info {
825             my $self = shift;
826              
827             return unless $self->cfg->verbose;
828              
829             warn "I: ", @_, "\n";
830             }
831              
832             =back
833              
834             =head1 AUTHOR
835              
836             dh-make-perl was created by Paolo Molaro.
837              
838             It is currently maintained by Gunnar Wolf and others, under the umbrella of the
839             Debian Perl Group
840              
841             =head1 BUGS
842              
843             Please report any bugs or feature requests to the Debian Bug Tracking System
844             (L, use I as package name) or to the
845             L mailing list.
846              
847             =head1 SUPPORT
848              
849             You can find documentation for this module with the perldoc command.
850              
851             perldoc DhMakePerl
852              
853             You can also look for information at:
854              
855             =over 4
856              
857             =item * Debian Bugtracking System
858              
859             L
860              
861             =back
862              
863              
864              
865             =head1 COPYRIGHT & LICENSE
866              
867             =over 4
868              
869             =item Copyright (C) 2000, 2001 Paolo Molaro
870              
871             =item Copyright (C) 2002, 2003, 2008 Ivan Kohler
872              
873             =item Copyright (C) 2003, 2004 Marc 'HE' Brockschmidt
874              
875             =item Copyright (C) 2005-2007 Gunnar Wolf
876              
877             =item Copyright (C) 2006 Frank Lichtenheld
878              
879             =item Copyright (C) 2007-2014 Gregor Herrmann
880              
881             =item Copyright (C) 2007,2008,2009,2010,2011,2012,2015 Damyan Ivanov
882              
883             =item Copyright (C) 2008, Roberto C. Sanchez
884              
885             =item Copyright (C) 2009-2010, Salvatore Bonaccorso
886              
887             =item Copyright (C) 2013, Axel Beckert
888              
889             =back
890              
891             This program is free software; you can redistribute it and/or modify it under
892             the terms of the GNU General Public License version 2 as published by the Free
893             Software Foundation.
894              
895             This program is distributed in the hope that it will be useful, but WITHOUT ANY
896             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
897             PARTICULAR PURPOSE. See the GNU General Public License for more details.
898              
899             You should have received a copy of the GNU General Public License along with
900             this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
901             Street, Fifth Floor, Boston, MA 02110-1301 USA.
902              
903             =cut
904              
905             1; # End of DhMakePerl