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   1454300 use warnings;
  3         30  
  3         182  
4 3     3   22 use strict;
  3         8  
  3         157  
5             our $VERSION = '0.96';
6 3     3   92 use 5.010; # we use smart matching
  3         11  
7              
8 3     3   20 use base 'DhMakePerl::Command::Packaging';
  3         17  
  3         1597  
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( "https://anonscm.debian.org/git/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             # warn if local::lib usage is detected. cf. #820395
404             if ( $ENV{PERL_LOCAL_LIB_ROOT} ) {
405             $self->warning('It seems that you are running in an active local::lib environment.');
406             $self->warning('local::lib usually sets PERL_MB_OPT=--install_base and PERL_MM_OPT=INSTALL_BASE');
407             $self->warning('which will change the install path in the about to be built package.');
408             $self->warning('We recommend that you disable local::lib temporarily, e.g. by running');
409             $self->warning(' eval $(perl -Mlocal::lib=--deactivate-all)');
410             $self->warning('in your shell. -- Continuing anyway ...');
411             }
412             # uhmf! dpkg-genchanges doesn't cope with the deb being in another dir..
413             #system("dpkg-buildpackage -b -us -uc " . $self->cfg->dbflags) == 0
414             system("fakeroot make -C $main_dir -f debian/rules clean");
415             system("make -C $main_dir -f debian/rules build") == 0
416             || die "Cannot create deb package: 'debian/rules build' failed.\n";
417             system("fakeroot make -C $main_dir -f debian/rules binary") == 0
418             || die "Cannot create deb package: 'fakeroot debian/rules binary' failed.\n";
419             }
420              
421             sub build_source_package {
422             my ( $self ) = @_;
423              
424             my $main_dir = $self->main_dir;
425             # uhmf! dpkg-genchanges doesn't cope with the deb being in another dir..
426             #system("dpkg-buildpackage -S -us -uc " . $self->cfg->dbflags) == 0
427             system("fakeroot make -C $main_dir -f debian/rules clean");
428             system("dpkg-source -b $main_dir") == 0
429             || die "Cannot create source package: 'dpkg-source -b' failed.\n";
430             }
431              
432             sub install_package {
433             my ($self) = @_;
434              
435             my ( $archspec, $debname );
436              
437             my $arch = $self->control->binary_tie->Values(0)->Architecture;
438              
439             if ( !defined $arch || $arch eq 'any' ) {
440             $archspec = `dpkg --print-architecture`;
441             chomp($archspec);
442             }
443             else {
444             $archspec = $arch;
445             }
446              
447             $debname = sprintf( "%s_%s-1_%s.deb", $self->pkgname, $self->version,
448             $archspec );
449              
450             my $deb = $self->main_dir . "/../$debname";
451             my $dpkg_cmd = "dpkg -i $deb";
452             $dpkg_cmd = "sudo $dpkg_cmd" if $>;
453             $self->info("Running '$dpkg_cmd'...");
454             system($dpkg_cmd) == 0
455             || die "Cannot install package $deb\n";
456             }
457              
458             sub findbin_fix {
459             my ($self) = @_;
460              
461             # FindBin requires to know the name of the invoker - and requires it to be
462             # Makefile.PL to function properly :-/
463             $0 = $self->makefile_pl();
464             if ( exists $FindBin::{Bin} ) {
465             FindBin::again();
466             }
467             }
468              
469             # finds the list of modules that the distribution depends on
470             # if $build_deps is true, returns build-time dependencies, otherwise
471             # returns run-time dependencies
472             sub run_depends {
473             my ( $self, $depends_module, $build_deps ) = @_;
474              
475             no warnings;
476             local *STDERR;
477             open( STDERR, ">/dev/null" );
478             my $mod_dep = $depends_module->new();
479              
480             $mod_dep->dist_dir( $self->main_dir );
481             $mod_dep->find_modules();
482              
483             my $deps = $build_deps ? $mod_dep->build_requires : $mod_dep->requires;
484              
485             my $error = $mod_dep->error();
486             die "Error: $error\n" if $error;
487              
488             return $deps;
489             }
490              
491             # filter @deps to contain only one instance of each package
492             # say we have te following list of dependencies:
493             # libppi-perl, libppi-perl (>= 3.0), libarm-perl, libalpa-perl, libarm-perl (>= 2)
494             # we want a clean list instead:
495             # libalpa-perl, libarm-perl (>= 2), libppi-perl (>= 3.0)
496             sub prune_deps(@) {
497             my $self = shift;
498              
499             my %deps;
500             for (@_) {
501             my $p = $_->pkg;
502             my $v = $_->ver;
503             if ( exists $deps{$p} ) {
504             my $cur_ver = $deps{$p};
505              
506             $deps{$p} = $v
507             if defined($v)
508             and ( not defined($cur_ver)
509             or $cur_ver < $v );
510             }
511             else {
512             $deps{$p} = $v;
513             }
514              
515             }
516              
517             return map( Debian::Dependency->new( $_, $deps{$_} ), sort( keys(%deps) ) );
518             }
519              
520             sub create_changelog {
521             my ( $self, $file, $bug ) = @_;
522              
523             my $fh = $self->_file_w($file);
524              
525             my $closes = $bug ? " (Closes: #$bug)" : '';
526             my $changelog_dist = $self->cfg->pkg_perl ? "UNRELEASED" : "unstable";
527              
528             $fh->printf( "%s (%s) %s; urgency=low\n",
529             $self->srcname, $self->pkgversion, $changelog_dist );
530             $fh->print("\n * Initial Release.$closes\n\n");
531             $fh->printf( " -- %s %s\n", $self->get_developer,
532             email_date(time) );
533              
534             #$fh->print("Local variables:\nmode: debian-changelog\nEnd:\n");
535             $fh->close;
536             }
537              
538             sub create_readme {
539             my ( $self, $filename ) = @_;
540              
541             my $fh = $self->_file_w($filename);
542             $fh->printf(
543             "This is the debian package for the %s module.
544             It was created by %s using dh-make-perl.
545             ", $self->perlname, $self->maintainer,
546             );
547             $fh->close;
548             }
549              
550             sub create_watch {
551             my ( $self, $filename ) = @_;
552              
553             my $fh = $self->_file_w($filename);
554              
555             my $version_re = 'v?(\d[\d.-]*)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip)';
556              
557             $fh->printf( "version=3\n%s .*/%s-%s\$\n",
558             $self->upsurl, $self->perlname, $version_re );
559             $fh->close;
560             }
561              
562             sub search_pkg_perl {
563             my $self = shift;
564              
565             return undef unless $self->cfg->network;
566              
567             my $pkg = $self->pkgname;
568              
569             require LWP::UserAgent;
570             require LWP::ConnCache;
571              
572             my ( $ua, $resp );
573              
574             $ua = LWP::UserAgent->new;
575             $ua->env_proxy;
576             $ua->conn_cache( LWP::ConnCache->new );
577              
578             $resp = $ua->get(
579             "https://anonscm.debian.org/cgit/pkg-perl/packages/$pkg.git");
580             return { url => $resp->request->uri }
581             if $resp->is_success;
582              
583             $resp = $ua->get(
584             "https://anonscm.debian.org/cgit/pkg-perl/attic/$pkg.git");
585             return { url => $resp->request->uri }
586             if $resp->is_success;
587              
588             return undef;
589             }
590              
591             sub rename_to_debian_package_dir {
592             my( $self ) = @_;
593             return unless $self->cfg->cpan;
594              
595             my $maindir = $self->main_dir;
596             my $newmaindir = catdir( $maindir, updir(), $self->pkgname );
597              
598             if( -d $newmaindir ) {
599             warn "$newmaindir already exists, skipping rename";
600             return;
601             }
602              
603             rename $maindir, $newmaindir or die "rename failed: $self->main_dir to $newmaindir";
604             $self->main_dir( $newmaindir );
605             return;
606             }
607              
608             sub package_already_exists {
609             my( $self, $apt_contents ) = @_;
610              
611             my $found;
612             if (my $apt_cache = apt_cache())
613             {
614             $found = $apt_cache->packages->lookup( $self->pkgname );
615             }
616              
617             if ($found) {
618             warn "**********\n";
619             warn "WARNING: a package named\n";
620             warn " '" . $self->pkgname ."'\n";
621             warn " is already available in APT repositories\n";
622             warn "Maintainer: ", $found->{Maintainer}, "\n";
623             my $short_desc = (split( /\n/, $found->{LongDesc} ))[0];
624             warn "Description: $short_desc\n";
625             }
626             elsif ($apt_contents) {
627             $found = $apt_contents->find_perl_module_package( $self->perlname );
628              
629             if ($found) {
630             ( my $mod_name = $self->perlname ) =~ s/-/::/g;
631             warn "**********\n";
632             warn "NOTICE: the package '$found', available in APT repositories\n";
633             warn " already contains a module named "
634             . $self->perlname . "\n";
635             }
636             elsif ( $found = $self->search_pkg_perl ) {
637             warn "********************\n";
638             warn sprintf(
639             "The Debian Perl Group has a repository for the %s package\n at %s\n",
640             $self->pkgname, $found->{url} );
641             warn "You may want to contact them to avoid duplication of effort.\n";
642             warn "More information is available at https://wiki.debian.org/Teams/DebianPerlGroup\n";
643             }
644             }
645             else {
646             ( my $mod_name = $self->perlname ) =~ s/-/::/g;
647             require Debian::DpkgLists;
648             my @found = Debian::DpkgLists->scan_perl_mod($mod_name);
649              
650             if (@found) {
651             warn "**********\n";
652             warn "NOTICE: the following locally installed package(s) already\n";
653             warn " contain $mod_name\n";
654             warn " ", join ( ', ', @found ), "\n";
655             $found = 1;
656             }
657             }
658              
659             return $found ? 1 : 0;
660             }
661              
662             sub modules_already_packaged {
663             my( $self, $apt_contents ) = @_;
664              
665             my @modules;
666              
667             File::Find::find(
668             sub {
669             if (basename($File::Find::dir)
670             =~ /^(?:
671             \.(?:git|svn|hg|)
672             |CVS
673             |eg|samples?|examples?
674             |t|xt
675             |inc|privinc
676             )$/x
677             )
678             {
679             $File::Find::prune = 1;
680             return;
681             }
682             if (/.+\.pm$/) {
683             my $mi = Module::Metadata->new_from_file($_);
684             push @modules, $mi->packages_inside;
685             }
686             },
687             $self->main_dir,
688             );
689              
690             my $found;
691              
692             sub show_notice($$) {
693             warn $_[0] unless $_[1];
694             $_[1] = 1;
695             }
696              
697             my $notice = <
698             *** Notice ***
699             Some of the modules in the newly created package are already present
700             in other packages.
701              
702             EOF
703             my $notice_shown = 0;
704              
705             for my $mod (@modules) {
706             if ($apt_contents) {
707             $found = $apt_contents->find_perl_module_package($mod);
708              
709             if ($found) {
710             show_notice( $notice, $notice_shown );
711             warn " $mod is in '$found' (APT)\n";
712             }
713             }
714             if ( !$found ) {
715             require Debian::DpkgLists;
716             my @found = Debian::DpkgLists->scan_perl_mod($mod);
717              
718             if (@found) {
719             show_notice( $notice, $notice_shown );
720             warn " $mod is in " . join( ', ', @found ), " (local .deb)\n";
721             $found = 1;
722             }
723             }
724             }
725              
726             warn "\n" if $notice_shown;
727              
728             return $found ? 1 : 0;
729             }
730              
731             sub reset_git_environment {
732             # The Git environment variables may be set from previous iterations
733             # of this program being run. In this case, it's possible that the
734             # Git module will use these to point to the wrong source tree.
735             delete $ENV{'GIT_DIR'};
736             delete $ENV{'GIT_WORK_TREE'};
737             }
738              
739             sub git_import_upstream__init_debian {
740             my ( $self ) = @_;
741              
742             require Git;
743              
744             $self->reset_git_environment();
745              
746             Git::command( 'init', $self->main_dir );
747             my @git_config = ( '-c', 'user.name=' . $self->get_name,
748             '-c', 'user.email=' . $self->get_email);
749              
750             my $git = Git->repository( $self->main_dir );
751             $git->command( qw(symbolic-ref HEAD refs/heads/upstream) );
752             $git->command( 'add', '.' );
753             $git->command( @git_config, 'commit', '-m',
754             "Import original source of "
755             . $self->perlname . ' '
756             . $self->version );
757             $git->command( 'tag', "upstream/".$self->version, 'upstream' );
758              
759             $git->command( qw( checkout -b master upstream ) );
760             if ( -d $self->debian_dir ) {
761             # remove debian/ directory if the upstream ships it. This goes into the
762             # 'master' branch, so the 'upstream' branch contains the original debian/
763             # directory, and thus matches the pristine-tar. Here I also remove the
764             # debian/ directory from the working tree; git has the history, so I don't
765             # need the debian.bak
766             $git->command( 'rm', '-r', $self->debian_dir );
767             $git->command( @git_config, 'commit', '-m',
768             'Removed debian directory embedded in upstream source' );
769             }
770             }
771              
772             sub git_add_debian {
773             my ( $self, $tarball ) = @_;
774              
775             require Git;
776             require File::Which;
777              
778             $self->reset_git_environment;
779              
780             my $git = Git->repository( $self->main_dir );
781             my $name = $self->get_name;
782             my $email = $self->get_email;
783             my @git_config = ( '-c', "user.name=$name",
784             '-c', "user.email=$email");
785             $git->command( 'add', 'debian' );
786             $git->command( @git_config, 'commit', '-m',
787             "Initial packaging by dh-make-perl $VERSION" );
788             $git->command(
789             qw( remote add origin ),
790             sprintf( "ssh://git.debian.org/git/pkg-perl/packages/%s.git",
791             $self->pkgname ),
792             ) if $self->cfg->pkg_perl;
793              
794             if ( File::Which::which('pristine-tar') ) {
795             if ( $tarball and -f $tarball ) {
796             $ENV{GIT_DIR} = File::Spec->catdir( $self->main_dir, '.git' );
797             my %backup_ENV = %ENV;
798             $ENV{GIT_COMMITTER_NAME} = $name;
799             $ENV{GIT_COMMITTER_EMAIL} = $email;
800             $ENV{GIT_AUTHOR_NAME} = $name;
801             $ENV{GIT_AUTHOR_EMAIL} = $email;
802             my $status = system( 'pristine-tar', 'commit', $tarball, "upstream/".$self->version );
803             %ENV = %backup_ENV;
804             warn "error running pristine-tar: $!\n" if $status < 0;
805             }
806             else {
807             die "No tarball found to handle with pristine-tar. Bailing out."
808             }
809             }
810             else {
811             warn "W: pristine-tar not available. Please run\n";
812             warn "W: apt-get install pristine-tar\n";
813             warn "W: followed by\n";
814             warn "W: pristine-tar commit $tarball upstream/"
815             . $self->version . "\n";
816             }
817             }
818              
819             =item warning I ...
820              
821             In verbose mode, prints supplied arguments on STDERR, prepended with C and
822             suffixed with a new line.
823              
824             Does nothing in non-verbose mode.
825              
826             =cut
827              
828             sub warning {
829             my $self = shift;
830              
831             return unless $self->cfg->verbose;
832              
833             warn "W: ", @_, "\n";
834             }
835              
836             =item info I ...
837              
838             In verbose mode, prints supplied arguments on STDERR, prepended with C and
839             suffixed with a new line.
840              
841             Does nothing in non-verbose mode.
842              
843             =cut
844              
845             sub info {
846             my $self = shift;
847              
848             return unless $self->cfg->verbose;
849              
850             warn "I: ", @_, "\n";
851             }
852              
853             =back
854              
855             =head1 AUTHOR
856              
857             dh-make-perl was created by Paolo Molaro.
858              
859             It is currently maintained by Gunnar Wolf and others, under the umbrella of the
860             Debian Perl Group
861              
862             =head1 BUGS
863              
864             Please report any bugs or feature requests to the Debian Bug Tracking System
865             (L, use I as package name) or to the
866             L mailing list.
867              
868             =head1 SUPPORT
869              
870             You can find documentation for this module with the perldoc command.
871              
872             perldoc DhMakePerl
873              
874             You can also look for information at:
875              
876             =over 4
877              
878             =item * Debian Bugtracking System
879              
880             L
881              
882             =back
883              
884              
885              
886             =head1 COPYRIGHT & LICENSE
887              
888             =over 4
889              
890             =item Copyright (C) 2000, 2001 Paolo Molaro
891              
892             =item Copyright (C) 2002, 2003, 2008 Ivan Kohler
893              
894             =item Copyright (C) 2003, 2004 Marc 'HE' Brockschmidt
895              
896             =item Copyright (C) 2005-2007 Gunnar Wolf
897              
898             =item Copyright (C) 2006 Frank Lichtenheld
899              
900             =item Copyright (C) 2007-2014 Gregor Herrmann
901              
902             =item Copyright (C) 2007,2008,2009,2010,2011,2012,2015 Damyan Ivanov
903              
904             =item Copyright (C) 2008, Roberto C. Sanchez
905              
906             =item Copyright (C) 2009-2010, Salvatore Bonaccorso
907              
908             =item Copyright (C) 2013, Axel Beckert
909              
910             =back
911              
912             This program is free software; you can redistribute it and/or modify it under
913             the terms of the GNU General Public License version 2 as published by the Free
914             Software Foundation.
915              
916             This program is distributed in the hope that it will be useful, but WITHOUT ANY
917             WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
918             PARTICULAR PURPOSE. See the GNU General Public License for more details.
919              
920             You should have received a copy of the GNU General Public License along with
921             this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
922             Street, Fifth Floor, Boston, MA 02110-1301 USA.
923              
924             =cut
925              
926             1; # End of DhMakePerl