Koha/debian/list-deps
Julian Maurice a34d086a24
Bug 19735: Move Perl deps definitions into a cpanfile
cpanfile is a format for describing CPAN dependencies for Perl
applications.
It is more concise - thus easier to read and maintain - than
C4::Installer::PerlDependencies, and allows to describe requirements
more accurately (using version ranges or features for instance)
Additionally it can be read by tools such as cpanm or carton for an
easy way to install dependencies on non-Debian-based systems.

For more information on cpanfile, see
http://search.cpan.org/~miyagawa/Module-CPANfile-1.1002/lib/cpanfile.pod

This patch replace C4::Installer::PerlDependencies by an equivalent
cpanfile and update all scripts/modules that were using PerlDependencies
It also removes dead code from C4::Installer::PerlModules (some
subroutines were not used at all, except in unit tests)

Added dependencies:
 - Module::CPANfile
 - CPAN::Meta (dependency of Module::CPANfile, but we need a more recent
   version than the one Module::CPANfile requires)

Test plan:
  1. Go to About page, tab Perl modules and keep this browser tab open
  2. Apply patch
  3. Install Module::CPANfile and CPAN::Meta
    a. On Debian-based systems:
       # will install libcpan-meta-perl as a dependency
       sudo apt install libmodule-cpanfile-perl
    b. Others:
       # will install CPAN::Meta as a dependency
       sudo cpanm Module::CPANfile
  4. In a new browser tab, go to About page, tab Perl modules and compare
     the table with the one in the previous browser tab
     They should be identical, except for newly added dependencies
     (Module::CPANfile and CPAN::Meta)
  5. Do a 'standard' install
    a. perl Makefile.PL (select 'standard')
    b. make
    c. sudo make install
    d. Configure your database, web server, ... and go through the web
       install process
  6. Verify that the cpanfile got copied into PERL_MODULE_DIR (which
     should be /usr/share/koha/lib)
  7. Go to the about page of this fresh install and compare it with your
     dev install
  8. Verify that debian/list-deps still works
     This takes a lot of time and it may not be necessary to wait until
     the end. If you see some Debian package names that correspond to
     modules in cpanfile, it means it still works
     (you need apt-file for this script to work)
  9. Verify that koha_perl_deps.pl still works
 10. prove t/Installer_pm.t t/Installer_PerlModules.t

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-02-12 16:33:02 +00:00

103 lines
4.1 KiB
Perl
Executable file

#!/usr/bin/perl
#
# Write dependency list from Koha cpanfile, in Debian format.
#
# Copyright 2010 Catalyst IT, Ltd
#
# 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 3 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 <http://www.gnu.org/licenses/>.
use Modern::Perl;
use C4::Installer::PerlModules;
# These are packages that may not be in the apt archive in a way that
# apt-file can find, e.g. in the Koha repo rather than the regular
# debian one.
my %overrides = (
'LWP::Protocol::https' => 'liblwp-protocol-https-perl|libwww-perl (<<6.02), libio-socket-ssl-perl',
'HTTP::OAI' => 'libhttp-oai-perl (>= 3.2) | libhttp-oai-3.27-perl, libhttp-oai-perl (<< 4.0) | libhttp-oai-3.27-perl',
'IO::Socket::IP' => 'perl-modules (>= 5.20.0) | perl-modules-5.22 | perl-modules-5.24 | libio-socket-ip-perl',
'Swagger2' => 'libswagger2-perl (>= 0.59)',
'Mojolicious' => 'libmojolicious-perl (>= 6.0)',
);
# These are packages we're going to ignore
my %ignore = (
'Data::Pagination' => 1,
'CHI' => 1,
'CHI::Driver::Memcached' => 1,
);
my $prefix = "^/usr/((lib|share)/perl5|(lib|share)/perl/[0-9.]+|(lib|share)/.*-linux-gnu.*/perl/[0-9.]+|(lib|share)/.*-linux-gnu.*/perl5/[0-9.]+)";
my $modules = C4::Installer::PerlModules->new();
my $prereqs = $modules->prereqs;
foreach my $phase ($prereqs->phases) {
foreach my $type ($prereqs->types_in($phase)) {
my $reqs = $prereqs->requirements_for($phase, $type);
foreach my $module ( $reqs->required_modules ) {
next if $ignore{$module};
my $subpath = $module;
$subpath =~ s,::,/,g;
my $output = qx(apt-file -l -x search "$prefix/$subpath.pm\$");
my @temp = split( /\n/, $output );
my @lines = ();
# Remove packages that are required/essential and always installed on
# a Debian system. Debian packages should not have unversioned
# dependencies on such packages.
foreach my $line (@temp) {
if ( $line ne "perl-base" ) {
@lines = ( @lines, $line );
}
}
if ( exists $overrides{$module} ) {
print "$overrides{$module}\n";
}
elsif ( scalar(@lines) == 1 && $lines[0] ne "" ) {
my $pkg = $lines[0];
print "$pkg\n";
}
elsif ( scalar(@lines) > 1 ) {
foreach my $pkg (@lines) {
print " | " if ( $pkg ne $lines[0] );
print "$pkg";
print " | $pkg" . "-5.22" if ( $pkg eq "perl-modules" );
print " | $pkg" . "-5.24" if ( $pkg eq "perl-modules" );
}
print "\n";
}
elsif ( scalar(@temp) != 0 ) {
# I'm an Essential and I'm OK,
# I install all night, and work all day.
# I chomp up strings. I eat my bugs.
# I go to the base install.
# On Fridays I go drinking,
# and have buttered commits for git.
# (Beer O'Clock is more than two hours
# away. I don't even drink beer. There
# is no reason to be suspicious of this
# commit.)
# RM note: suspicious? me? always!
}
elsif ( $type ne 'requires' ) {
# Ignore because we don't have it and we don't care.
}
else {
print "EEEK: unknown package for $module\n";
}
}
}
}