Bug 29881: libdbd-sqlite2-perl is unavailable on deb12 (koha-common wont install)
[koha.git] / debian / list-deps
1 #!/usr/bin/perl
2 #
3 # Write dependency list from Koha cpanfile, in Debian format.
4 #
5 # Copyright 2010  Catalyst IT, Ltd
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 use Modern::Perl;
21 use Parallel::ForkManager;
22 use Sys::CPU;
23
24 use C4::Installer::PerlModules;
25
26 # These are packages that may not be in the apt archive in a way that
27 # apt-file can find, e.g. in the Koha repo rather than the regular
28 # debian one.
29 my %overrides = (
30     'LWP::Protocol::https' => 'liblwp-protocol-https-perl | libwww-perl (<<6.02), libio-socket-ssl-perl',
31     'HTTP::OAI'            => 'libhttp-oai-perl (>= 3.2) | libhttp-oai-3.27-perl, libhttp-oai-perl (<< 4.0) | libhttp-oai-3.27-perl',
32     'IO::Socket::IP'       => 'perl-modules (>= 5.20.0) | libio-socket-ip-perl',
33     'Swagger2'             => 'libswagger2-perl (>= 0.59)',
34     'Mojolicious'          => 'libmojolicious-perl (>= 6.0)',
35     'CPAN::Meta'           => 'libcpan-meta-perl (>= 2.150010) | perl-modules-5.28 | perl-modules-5.30 | perl-modules (>= 5.20.2)',
36     'Locale::Language'     => 'liblocale-codes-perl',
37     'CGI::Compile'         => 'libcgi-compile-perl (>= 0.25) | libcgi-compile-perl (<< 0.24)',
38     'DBD::SQLite2'         => 'libdbd-sqlite2-perl (>= 0.33) | libdbd-sqlite3-perl',
39 );
40
41 # These are packages we're going to ignore
42 my %ignore = (
43     'Data::Pagination'       => 1,
44     'CHI'                    => 1,
45     'CHI::Driver::Memcached' => 1,
46 );
47
48 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.]+)";
49
50 my $pm   = Parallel::ForkManager->new( Sys::CPU::cpu_count() );
51
52 my $modules = C4::Installer::PerlModules->new();
53 my $prereqs = $modules->prereqs;
54 foreach my $phase ($prereqs->phases) {
55     foreach my $type ($prereqs->types_in($phase)) {
56         my $reqs = $prereqs->requirements_for($phase, $type);
57
58         MODULE_LOOP:
59         foreach my $module ( $reqs->required_modules ) {
60             my $pid = $pm->start and next MODULE_LOOP;
61
62             next if $ignore{$module};
63             my $subpath = $module;
64             $subpath =~ s,::,/,g;
65
66             my $output = qx(apt-file -l -x search "$prefix/$subpath.pm\$");
67             my @temp   = split( /\n/, $output );
68             my @lines  = ();
69
70             # Remove packages that are required/essential and always installed on
71             # a Debian system. Debian packages should not have unversioned
72             # dependencies on such packages.
73
74
75             # skip perl-base and problematic version specific libperl* and
76             # perl-module* packages (they get installed as deps. anyway)
77             foreach my $line (@temp) {
78                 if ( $line ne "perl-base" and $line !~ /^libperl5\./ and $line !~ /^perl-modules-5\./ ) {
79                     @lines = ( @lines, $line );
80                 }
81             }
82
83             if ( exists $overrides{$module} ) {
84                 print "$overrides{$module}\n";
85             }
86             elsif ( scalar(@lines) == 1 && $lines[0] ne "" ) {
87                 my $pkg = $lines[0];
88                 print "$pkg\n";
89             }
90             elsif ( scalar(@lines) > 1 ) {
91                 foreach my $pkg (@lines) {
92                     print " | " if ( $pkg ne $lines[0] );
93                     print "$pkg";
94                 }
95                 print "\n";
96             }
97             elsif ( scalar(@temp) != 0 ) {
98                 # hmm, skip module
99             }
100             elsif ( $type ne 'requires' ) {
101                 # Ignore because we don't have it and we don't care.
102             }
103             else {
104                 print "EEEK: unknown package for $module\n";
105             }
106
107             $pm->finish; # Terminates the child process
108         }
109     }
110 }
111 $pm->wait_all_children;