2008-11-02 08:23:09 -01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
2012-07-08 16:06:54 +00:00
|
|
|
# Copyright 1999 Raphaël Hertzog <hertzog@debian.org>
|
2008-11-02 08:23:09 -01:00
|
|
|
# See the README file for the license
|
|
|
|
#
|
|
|
|
# This script takes 1 argument on input :
|
|
|
|
# - a filename listing all the packages to include
|
|
|
|
#
|
|
|
|
# and it sorts those packages such that dependencies are met in order
|
|
|
|
#
|
|
|
|
# Used to be called list2cds, renamed as it now just sorts
|
|
|
|
# dependencies. Later code in make_disc_trees.pl actually splits on a
|
|
|
|
# per-disc basis now.
|
|
|
|
|
|
|
|
use strict;
|
2012-09-26 18:18:47 +00:00
|
|
|
use Data::Dumper;
|
|
|
|
use Dpkg::Version;
|
2008-11-02 08:23:09 -01:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
my $listfile = shift;
|
2008-11-02 08:23:09 -01:00
|
|
|
|
2012-06-05 13:56:51 +00:00
|
|
|
my $nonfree = read_env('NONFREE', 0);
|
|
|
|
my $extranonfree = read_env('EXTRANONFREE', 0);
|
|
|
|
my $force_firmware = read_env('FORCE_FIRMWARE', 0);
|
|
|
|
my $local = read_env('LOCAL', 0);
|
|
|
|
my $complete = read_env('COMPLETE', 0);
|
|
|
|
my $norecommends = read_env('NORECOMMENDS', 1);
|
|
|
|
my $nosuggests = read_env('NOSUGGESTS', 1);
|
|
|
|
my $verbose = read_env('VERBOSE', 0);
|
|
|
|
my $max_pkg_size = read_env('MAX_PKG_SIZE', 9999999999999);
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
my $apt = "$ENV{'BASEDIR'}/tools/apt-selection";
|
|
|
|
my $adir = "$ENV{'APTTMP'}/$ENV{'CODENAME'}-$ENV{'ARCH'}";
|
|
|
|
my $arch = "$ENV{'ARCH'}";
|
|
|
|
my $dir = "$ENV{'TDIR'}/$ENV{'CODENAME'}";
|
|
|
|
|
2012-07-08 18:16:05 +00:00
|
|
|
my $force_unstable_tasks = read_env('FORCE_SID_TASKSEL', 0);
|
|
|
|
my $tasks_packages = read_env('TASKS_PACKAGES',
|
2012-07-08 18:20:44 +00:00
|
|
|
"$ENV{'MIRROR'}/dists/sid/main/binary-$ENV{'ARCH'}/Packages.gz");
|
2012-09-26 18:18:47 +00:00
|
|
|
my @output = ();
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
$| = 1; # Autoflush for debugging
|
|
|
|
|
2010-04-27 12:25:41 +00:00
|
|
|
open(LOG, ">$dir/sort_deps.$arch.log")
|
|
|
|
|| die "Can't write in $dir/sort_deps.$arch.log !\n";
|
2008-11-02 08:23:09 -01:00
|
|
|
|
2012-06-05 13:56:51 +00:00
|
|
|
sub read_env {
|
|
|
|
my $env_var = shift;
|
|
|
|
my $default = shift;
|
|
|
|
|
|
|
|
if (exists($ENV{$env_var})) {
|
|
|
|
return $ENV{$env_var};
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:23:09 -01:00
|
|
|
sub msg {
|
|
|
|
my $level = shift;
|
|
|
|
if ($verbose >= $level) {
|
|
|
|
print @_;
|
|
|
|
}
|
|
|
|
print LOG @_;
|
|
|
|
}
|
|
|
|
|
|
|
|
my %included;
|
|
|
|
my %excluded;
|
|
|
|
my %packages;
|
|
|
|
|
|
|
|
msg(0, "Running sort_deps to sort packages for $arch:\n");
|
|
|
|
msg(1, "======================================================================
|
|
|
|
Here are the settings you've chosen for making the list:
|
|
|
|
Architecture: $arch
|
2012-09-26 18:18:47 +00:00
|
|
|
List of prefered packages: $listfile
|
2008-11-02 08:23:09 -01:00
|
|
|
Output file: $dir/packages.$arch
|
|
|
|
");
|
|
|
|
msg(1, "Complete selected packages with all the rest: ");
|
|
|
|
msg(1, yesno($complete)."\n");
|
|
|
|
msg(1, "Include non-free packages: ");
|
|
|
|
msg(1, yesno($nonfree)."\n");
|
2010-05-27 00:52:25 +00:00
|
|
|
msg(1, "Force inclusion of firmware packages: ");
|
|
|
|
msg(1, yesno($force_firmware)."\n");
|
2012-06-05 13:56:51 +00:00
|
|
|
msg(1, "Ignore Recommends: ");
|
|
|
|
msg(1, yesno($norecommends)."\n");
|
|
|
|
msg(1, "Ignore Suggests: ");
|
|
|
|
msg(1, yesno($nosuggests)."\n");
|
2015-07-23 17:39:43 +00:00
|
|
|
msg(1, "Maximum allowed package size: $max_pkg_size bytes\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
msg(1, "======================================================================
|
|
|
|
");
|
|
|
|
|
|
|
|
# Get the information on all packages
|
|
|
|
my $oldrs = $/;
|
|
|
|
$/ = '';
|
|
|
|
open(AVAIL, "$apt cache dumpavail |") || die "Can't fork : $!\n";
|
|
|
|
my ($p, $re);
|
|
|
|
while (defined($_=<AVAIL>)) {
|
|
|
|
next if not m/^Package: (\S+)\s*$/m;
|
2012-07-08 18:16:05 +00:00
|
|
|
if (!$force_unstable_tasks || $1 !~ /^task-/) {
|
|
|
|
parse_package($_);
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
close AVAIL or die "apt-cache failed : $@ ($!)\n";
|
2012-07-08 18:16:05 +00:00
|
|
|
|
|
|
|
# Read in the extra (new/unstable) tasks packages
|
|
|
|
if ($force_unstable_tasks) {
|
2012-07-08 18:37:42 +00:00
|
|
|
my $num = 0;
|
2012-07-08 18:16:05 +00:00
|
|
|
if ($tasks_packages =~ /\.gz$/) {
|
|
|
|
open(AVAIL, "zcat $tasks_packages |") || die "Can't zcat $tasks_packages : $!\n";
|
|
|
|
} else {
|
|
|
|
open(AVAIL, "< $tasks_packages") || die "Can't open $tasks_packages for reading: $!\n";
|
|
|
|
}
|
|
|
|
while (defined($_=<AVAIL>)) {
|
|
|
|
next if not m/^Package: (\S+)\s*$/m;
|
|
|
|
if ($1 =~ /^task-/) {
|
|
|
|
parse_package($_);
|
2012-07-08 18:37:42 +00:00
|
|
|
$num++;
|
2012-07-08 18:16:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close AVAIL or die "reading unstable tasks failed : $@ ($!)\n";
|
2012-07-08 18:40:21 +00:00
|
|
|
msg(0, " Read $num tasks packages from $tasks_packages\n");
|
2012-07-08 18:16:05 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 08:23:09 -01:00
|
|
|
$/ = $oldrs;
|
|
|
|
|
|
|
|
# Get the list of excluded packages
|
|
|
|
%excluded = %included;
|
|
|
|
my $count_excl = 0;
|
|
|
|
|
|
|
|
# Now exclude packages because of the non-free rules
|
|
|
|
if (not $nonfree) {
|
|
|
|
foreach (grep { $packages{$_}{"Section"} =~ /non-free/ }
|
|
|
|
(keys %packages)) {
|
2010-05-27 00:52:25 +00:00
|
|
|
if ($force_firmware and $packages{$_}{"IsFirmware"}) {
|
|
|
|
msg(1, "force_firmware: keeping non-free package $_\n");
|
|
|
|
} else {
|
|
|
|
$excluded{$_} = 'nonfree';
|
|
|
|
$count_excl++;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg(1, "Statistics:
|
|
|
|
Number of packages: @{ [scalar(keys %packages)] }
|
|
|
|
Number of excluded: $count_excl of @{ [scalar(keys %excluded)] }
|
|
|
|
======================================================================
|
|
|
|
|
|
|
|
");
|
|
|
|
|
|
|
|
open(STATS, "> $dir/stats.excluded.$arch")
|
|
|
|
|| die "Can't write in stats.excluded.$arch: $!\n";
|
|
|
|
foreach (keys %excluded) {
|
|
|
|
print STATS "$_ => $excluded{$_}\n";
|
|
|
|
}
|
|
|
|
close (STATS);
|
|
|
|
|
|
|
|
# Browse the list of packages to include
|
2012-09-26 18:18:47 +00:00
|
|
|
my ($output_size, $size) = (0, 0);
|
2008-11-02 08:23:09 -01:00
|
|
|
my %cds;
|
|
|
|
|
|
|
|
# Generate a dependency tree for each package
|
|
|
|
msg(0, " Generating dependency tree with apt-cache depends...\n");
|
|
|
|
my (@list) = keys %packages;
|
|
|
|
while (@list) {
|
|
|
|
my (@pkg) = splice(@list,0,200);
|
|
|
|
$ENV{'LC_ALL'} = 'C'; # Required since apt is now translated
|
|
|
|
open (APT, "$apt cache depends @pkg |") || die "Can't fork : $!\n";
|
|
|
|
my (@res) = (<APT>);
|
2012-07-08 16:06:54 +00:00
|
|
|
close APT or die "'apt-cache depends failed ... \n" .
|
2008-11-02 08:23:09 -01:00
|
|
|
"you must have apt >= 0.3.11.1 !\n";
|
|
|
|
# Getting rid of conflicts/replaces/provides
|
|
|
|
my $i = 0;
|
|
|
|
my $nb_lines = scalar @res;
|
|
|
|
push @res, ""; # Avoid warnings ...
|
|
|
|
while ($i < $nb_lines) {
|
|
|
|
if ($res[$i] !~ m/^(\S+)\s*$/) {
|
|
|
|
msg(0, "UNEXPECTED: Line `$res[$i]' while parsing " .
|
|
|
|
"end of deptree from '$p'\n");
|
2012-09-26 18:18:47 +00:00
|
|
|
die "sort_deps failed! :-(\n";
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
$p = lc $1;
|
|
|
|
$i++;
|
|
|
|
msg(2, " Dependency tree of `$p' ...\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
read_depends (\$i, \@res, $p);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msg(0, " Adding standard, required, important and base packages first\n");
|
|
|
|
# Automatically include packages listed in the status file
|
|
|
|
open(STATUS, "< $adir/status") || die "Can't open status file $adir/status: $!\n";
|
|
|
|
while (defined($_ = <STATUS>)) {
|
|
|
|
next if not m/^Package: (\S+)/;
|
|
|
|
$p = $1;
|
|
|
|
if (not exists $packages{$p}) {
|
|
|
|
msg(1, "WARNING: Package `$p' is listed in the status file "
|
|
|
|
. "but doesn't exist ! (ignored) \n",
|
|
|
|
" TIP: Try to generate the status file with " .
|
|
|
|
"make (correct)status (after a make distclean)...\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
next if $excluded{$p};
|
|
|
|
add_package($p, ! $norecommends, ! $nosuggests);
|
|
|
|
}
|
|
|
|
close STATUS;
|
|
|
|
msg(0, " S/R/I/B packages take $output_size bytes\n");
|
|
|
|
|
|
|
|
# Now start to look for packages wanted by the user ...
|
|
|
|
msg(0, " Adding the rest of the requested packages\n");
|
2012-09-26 18:18:47 +00:00
|
|
|
open (LIST, "< $listfile") || die "Can't open $listfile : $!\n";
|
2008-11-02 08:23:09 -01:00
|
|
|
while (defined($_=<LIST>)) {
|
|
|
|
chomp;
|
|
|
|
next if m/^\s*$/;
|
|
|
|
if (not exists $packages{$_}) {
|
|
|
|
msg(1, "WARNING: '$_' does not appear to be available ... " .
|
|
|
|
"(ignored)\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
next if $excluded{$_};
|
|
|
|
if ($included{$_}) {
|
|
|
|
msg(3, "$_ has already been included.\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
# This is because udebs tend to have bad dependencies but work
|
|
|
|
# nevertheless ... this may be removed once the udebs have a
|
|
|
|
# better depencency system
|
|
|
|
if ($packages{$_}{"IsUdeb"}) {
|
2012-09-26 18:18:47 +00:00
|
|
|
add_to_output($_);
|
2008-11-02 08:23:09 -01:00
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
add_package ($_, ! $norecommends, ! $nosuggests);
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
close LIST;
|
|
|
|
|
|
|
|
msg(0, " Now up to $output_size bytes\n");
|
|
|
|
# All requested packages have been included
|
|
|
|
# But we'll continue to add if $complete was requested
|
|
|
|
if ($complete) {
|
|
|
|
msg(0, " COMPLETE=1; add all remaining packages\n");
|
|
|
|
# Try to sort them by section even if packages from
|
|
|
|
# other sections will get in through dependencies
|
|
|
|
# With some luck, most of them will already be here
|
|
|
|
foreach my $p (sort { ($packages{lc $a}{"Section"} cmp $packages{lc $b}{"Section"})
|
|
|
|
|| (lc $a cmp lc $b) }
|
|
|
|
grep { not ($included{$_} or $excluded{$_}) } keys %packages) {
|
|
|
|
# At this point, we should *not* be adding any more udebs,
|
|
|
|
# as they're no use to anybody.
|
|
|
|
if ($packages{lc $p}{"IsUdeb"}) {
|
|
|
|
msg(2, " Ignoring udeb $p ...\n");
|
|
|
|
} else {
|
|
|
|
add_package (lc $p, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now select the non-free packages for an extra CD
|
|
|
|
if ($extranonfree and (! $nonfree))
|
|
|
|
{
|
|
|
|
my ($p, @toinclude);
|
|
|
|
|
|
|
|
msg(0, " Adding non-free packages now\n");
|
|
|
|
|
|
|
|
# Finally accept non-free packages ...
|
|
|
|
foreach $p (grep { $excluded{$_} eq "nonfree" } (keys %excluded))
|
|
|
|
{
|
|
|
|
$excluded{$p} = 0;
|
|
|
|
push @toinclude, $p;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Include non-free packages
|
|
|
|
foreach $p (@toinclude)
|
|
|
|
{
|
|
|
|
add_package(lc $p, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
# If a contrib package was listed in the list of packages to
|
|
|
|
# include and if COMPLETE=0 there's a chance that the package
|
|
|
|
# will not get included in any CD ... so I'm checking the complete
|
|
|
|
# list again
|
2012-09-26 18:18:47 +00:00
|
|
|
open (LIST, "< $listfile") || die "Can't open $listfile : $!\n";
|
2008-11-02 08:23:09 -01:00
|
|
|
while (defined($_=<LIST>)) {
|
|
|
|
chomp;
|
|
|
|
next if m/^\s*$/;
|
|
|
|
next if $included{$_};
|
|
|
|
next if $included{lc $_};
|
|
|
|
next if $excluded{$_};
|
|
|
|
next if $excluded{lc $_};
|
|
|
|
if (not exists $packages{$_} && not exists $packages{lc $_}) {
|
|
|
|
msg(1, "WARNING: '$_' does not appear to be available ... " .
|
|
|
|
"(ignored)\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if ($packages{lc $p}{"IsUdeb"}) {
|
|
|
|
msg(2, " Ignoring udeb $p ...\n");
|
|
|
|
} else {
|
|
|
|
add_package (lc $_, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close LIST;
|
|
|
|
|
|
|
|
# Try to include other packages that could not be included
|
|
|
|
# before (because they depends on excluded non-free packages)
|
|
|
|
if ($complete)
|
|
|
|
{
|
|
|
|
foreach $p (sort { ($packages{$a}{"Section"}
|
|
|
|
cmp $packages{$b}{"Section"}) || ($a cmp $b) }
|
|
|
|
grep { not ($included{$_} or $excluded{$_}) }
|
|
|
|
keys %packages)
|
|
|
|
{
|
|
|
|
if ($packages{lc $p}{"IsUdeb"}) {
|
|
|
|
msg(2, " Ignoring udeb $p ...\n");
|
|
|
|
} else {
|
|
|
|
add_package (lc $p, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove old files
|
|
|
|
foreach (glob("$dir/*.packages*")) {
|
|
|
|
unlink $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now write the list down
|
|
|
|
my $count = 0;
|
|
|
|
open(CDLIST, "> $dir/packages.$arch")
|
|
|
|
|| die "Can't write in $dir/$_.packages.$arch: $!\n";
|
2010-05-27 00:52:25 +00:00
|
|
|
open(FWLIST, ">> $dir/firmware-packages")
|
|
|
|
|| die "Can't write in $dir/firmware-packages: $!\n";
|
2008-11-02 08:23:09 -01:00
|
|
|
foreach (@output) {
|
|
|
|
my $component = $packages{$_}{"Component"};
|
2009-12-29 00:27:25 -01:00
|
|
|
my $size = $packages{$_}{"Size"};
|
2013-01-24 09:26:30 -01:00
|
|
|
my $bu = $packages{$_}{"Built-Using"};
|
|
|
|
print CDLIST "$arch:$component:$_:$size:$bu\n";
|
2010-05-27 00:52:25 +00:00
|
|
|
if ($packages{$_}{"IsFirmware"}) {
|
|
|
|
print FWLIST "$_\n";
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
close CDLIST;
|
2010-05-27 00:52:25 +00:00
|
|
|
close FWLIST;
|
2008-11-02 08:23:09 -01:00
|
|
|
msg(0, "Done: processed/sorted $count packages, total size $output_size bytes.\n");
|
|
|
|
|
|
|
|
close LOG;
|
|
|
|
|
|
|
|
## END OF MAIN
|
|
|
|
## BEGINNING OF SUBS
|
|
|
|
|
2012-07-08 17:14:53 +00:00
|
|
|
sub parse_package {
|
2012-07-08 17:44:34 +00:00
|
|
|
my $p;
|
2012-07-08 17:14:53 +00:00
|
|
|
m/^Package: (\S+)\s*$/m and $p = $1;
|
|
|
|
$included{$p} = 0;
|
|
|
|
$packages{$p}{"Package"} = $p;
|
|
|
|
foreach $re (qw(Version Priority Section Filename Size MD5sum)) {
|
|
|
|
(m/^$re: (\S+)\s*$/m and $packages{$p}{$re} = $1)
|
|
|
|
|| msg(1, "Header field '$re' missing for package '$p'.\n");
|
|
|
|
}
|
|
|
|
$packages{$p}{"Depends"} = [];
|
|
|
|
$packages{$p}{"Suggests"} = [];
|
|
|
|
$packages{$p}{"Recommends"} = [];
|
2013-01-24 09:26:30 -01:00
|
|
|
$packages{$p}{"Built-Using"} = "";
|
|
|
|
if (m/^Built-Using: (.*)$/m) {
|
|
|
|
my $built = $1;
|
|
|
|
$built =~ s/ \(= \S*\)//g;
|
|
|
|
$built =~ s/,//g;
|
|
|
|
$built =~ s/ /,/g;
|
|
|
|
$packages{$p}{"Built-Using"} = $built;
|
|
|
|
}
|
2012-07-08 17:14:53 +00:00
|
|
|
$packages{$p}{"IsUdeb"} = ($packages{$p}{"Filename"} =~ /.udeb$/) ? 1 : 0;
|
|
|
|
$packages{$p}{"IsFirmware"} = ($packages{$p}{"Filename"} =~ /(firmware|microcode)/) ? 1 : 0;
|
|
|
|
if ($packages{$p}{"Section"} =~ /contrib\//) {
|
|
|
|
$packages{$p}{"Component"} = "contrib";
|
|
|
|
} elsif ($packages{$p}{"Section"} =~ /non-free\//) {
|
|
|
|
$packages{$p}{"Component"} = "non-free";
|
|
|
|
} elsif ($packages{$p}{"IsUdeb"}) {
|
|
|
|
$packages{$p}{"Component"} = "main-installer";
|
|
|
|
} else {
|
|
|
|
$packages{$p}{"Component"} = "main";
|
|
|
|
}
|
2012-07-08 17:44:34 +00:00
|
|
|
}
|
2012-07-08 17:14:53 +00:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
sub dump_depend {
|
|
|
|
my $tmpin = shift;
|
|
|
|
my %d;
|
|
|
|
my $ret = "";
|
|
|
|
|
|
|
|
if ("ARRAY" eq ref($tmpin)) {
|
|
|
|
my @array = @{$tmpin};
|
|
|
|
foreach (@array) {
|
|
|
|
%d = %$_;
|
|
|
|
$ret .= $d{"Package"};
|
|
|
|
if ($d{"CmpOp"} ne "") {
|
|
|
|
$ret .= " (" . $d{"CmpOp"} . " " . $d{"Version"} . ")";
|
|
|
|
}
|
|
|
|
$ret .= " ";
|
|
|
|
}
|
|
|
|
} elsif ("HASH" eq ref($tmpin)) {
|
|
|
|
%d = %$tmpin;
|
|
|
|
$ret .= $d{"Package"};
|
|
|
|
if ($d{"CmpOp"} ne "") {
|
|
|
|
$ret .= " (" . $d{"CmpOp"} . " " . $d{"Version"} . ")";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
die "dump_depend: $tmpin is neither an array nor a hash!\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2012-09-27 18:26:19 +00:00
|
|
|
sub dump_or_list {
|
|
|
|
my $out_type = shift;
|
|
|
|
my $elt = shift;
|
|
|
|
my @or = @$elt;
|
|
|
|
|
|
|
|
if (scalar @or == 1) {
|
|
|
|
msg(1, " $out_type: " . dump_depend($or[0]) . "\n");
|
|
|
|
} else {
|
|
|
|
msg(1, " $out_type: OR (");
|
|
|
|
foreach my $t (@or) {
|
|
|
|
msg(1, dump_depend($t) . " ");
|
|
|
|
}
|
|
|
|
msg(1, ")\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:23:09 -01:00
|
|
|
sub read_depends {
|
|
|
|
my $i = shift; # Ref
|
|
|
|
my $lines = shift; # Ref
|
|
|
|
my $pkg = shift; # string
|
2009-08-09 14:50:38 +00:00
|
|
|
my $types = "(?:Pre)?Depends|Suggests|Recommends|Replaces|Conflicts|Breaks|Enhances";
|
2008-11-02 08:23:09 -01:00
|
|
|
my (@dep, @rec, @sug);
|
2012-09-26 18:18:47 +00:00
|
|
|
my ($type, $or);
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
while ($lines->[$$i] =~ m/^\s([\s\|])($types):/) {
|
|
|
|
$type = $2; $or = $1;
|
2012-09-26 18:18:47 +00:00
|
|
|
# Get rid of replaces, conflicts and any other fields we don't
|
|
|
|
# care about...
|
2009-05-16 13:48:49 +00:00
|
|
|
if (($type eq "Replaces") or
|
|
|
|
($type eq "Conflicts") or
|
2009-08-09 14:50:38 +00:00
|
|
|
($type eq "Breaks") or
|
|
|
|
($type eq "Enhances")) {
|
2008-11-02 08:23:09 -01:00
|
|
|
$$i++;
|
|
|
|
while ($lines->[$$i] =~ m/^\s{4}/) {
|
|
|
|
$$i++;
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
|
|
|
|
my $out_type = $type;
|
|
|
|
$out_type =~ s/^Pre//; # PreDepends are like Depends for me
|
|
|
|
|
2008-11-02 08:23:09 -01:00
|
|
|
# Check the kind of depends : or, virtual, normal
|
|
|
|
if ($or eq '|') {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $elt = read_ordepends ($i, $lines);
|
2012-09-27 18:26:19 +00:00
|
|
|
dump_or_list($out_type, \@$elt);
|
2012-09-26 18:18:47 +00:00
|
|
|
push @{$packages{$pkg}{$out_type}}, $elt;
|
2008-11-02 08:23:09 -01:00
|
|
|
} elsif ($lines->[$$i] =~ m/^\s\s$type: <([^>]+)>/) {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $elt = read_virtualdepends ($i, $lines);
|
|
|
|
foreach my $t (@$elt) {
|
2012-09-27 16:52:00 +00:00
|
|
|
msg(1, " $out_type: " . dump_depend($t) . " <virt>\n");
|
2012-09-26 18:18:47 +00:00
|
|
|
}
|
|
|
|
push @{$packages{$pkg}{$out_type}}, $elt;
|
|
|
|
} elsif ($lines->[$$i] =~ m/^\s\s$type: (\S+)( \((\S+) (\S+)\))*/) {
|
2012-09-27 18:26:19 +00:00
|
|
|
my @or;
|
2012-09-26 18:18:47 +00:00
|
|
|
my %elt;
|
|
|
|
$elt{"Package"} = $1;
|
|
|
|
if (defined $2) {
|
|
|
|
$elt{"CmpOp"} = $3;
|
|
|
|
$elt{"Version"} = $4;
|
|
|
|
} else {
|
|
|
|
$elt{"CmpOp"} = "";
|
|
|
|
$elt{"Version"} = "";
|
|
|
|
}
|
2012-09-27 18:26:19 +00:00
|
|
|
push @or, \%elt;
|
2012-09-26 18:18:47 +00:00
|
|
|
$$i++;
|
|
|
|
|
2008-11-02 08:23:09 -01:00
|
|
|
# Special case for packages providing not
|
2012-09-26 18:18:47 +00:00
|
|
|
# truly virtual packages
|
2008-11-02 08:23:09 -01:00
|
|
|
if ($lines->[$$i] =~ m/^\s{4}/) {
|
2012-09-26 18:18:47 +00:00
|
|
|
while ($lines->[$$i] =~ m/\s{4}(\S+)( \((\S+) (\S+)\))*/) {
|
2012-09-27 16:49:26 +00:00
|
|
|
my %elt1;
|
|
|
|
$elt1{"Package"} = $1;
|
2012-09-26 18:18:47 +00:00
|
|
|
if (defined $2) {
|
2012-09-27 16:49:26 +00:00
|
|
|
$elt1{"CmpOp"} = $3;
|
|
|
|
$elt1{"Version"} = $4;
|
2012-09-26 18:18:47 +00:00
|
|
|
} else {
|
2012-09-27 16:49:26 +00:00
|
|
|
$elt1{"CmpOp"} = "";
|
|
|
|
$elt1{"Version"} = "";
|
2012-09-26 18:18:47 +00:00
|
|
|
}
|
2012-09-27 18:26:19 +00:00
|
|
|
push @or, \%elt1;
|
2008-11-02 08:23:09 -01:00
|
|
|
$$i++;
|
|
|
|
}
|
|
|
|
}
|
2012-09-27 18:26:19 +00:00
|
|
|
dump_or_list($out_type, \@or);
|
|
|
|
push @{$packages{$pkg}{$out_type}}, \@or;
|
2008-11-02 08:23:09 -01:00
|
|
|
} else {
|
|
|
|
msg(0, "ERROR: Unknown depends line : $lines->[$$i]\n");
|
|
|
|
foreach ($$i - 3 .. $$i + 3) {
|
|
|
|
msg(0, " ", $lines->[$_]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# Big matrix of tests. Check to see if the available version of a
|
|
|
|
# package matches what we're requesting in a dependency relationship
|
|
|
|
sub check_versions {
|
|
|
|
my $wanted = shift;
|
|
|
|
my $op = shift;
|
|
|
|
my $available = shift;
|
|
|
|
|
|
|
|
# Trivial check - if we don't care about versioning, anything will
|
|
|
|
# do!
|
|
|
|
if ($op eq "") {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ask the dpkg perl code to compare the version strings
|
|
|
|
my $comp = version_compare($available, $wanted);
|
|
|
|
|
|
|
|
if ($op eq "<=") {
|
|
|
|
if ($comp == -1 || $comp == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} elsif ($op eq ">=") {
|
|
|
|
if ($comp == 0 || $comp == 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} elsif ($op eq "<<") {
|
|
|
|
if ($comp == -1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} elsif ($op eq ">>") {
|
|
|
|
if ($comp == 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} elsif ($op eq "=") {
|
|
|
|
if ($comp == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
# Not sure this ("!") actually exists!
|
|
|
|
# Mentioned in apt sources, but not in debian policy
|
|
|
|
# No harm done by checking for it, though...
|
|
|
|
} elsif ($op eq "!") {
|
|
|
|
if ($comp == -1 || $comp == 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if a specific dependency package is installed already
|
|
|
|
sub dep_pkg_included {
|
|
|
|
my $p = shift;
|
|
|
|
my %d = %$p;
|
|
|
|
my $pn = $d{"Package"};
|
|
|
|
|
|
|
|
if ($included{$pn}) {
|
|
|
|
if (check_versions($d{"Version"}, $d{"CmpOp"}, $packages{$pn}{"Version"})) {
|
|
|
|
msg(1, " $pn is included already, acceptable version " . $packages{$pn}{"Version"} . "\n");
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
msg(1, " $pn is included already, but invalid version " . $packages{$pn}{"Version"} . "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check to see if a dependency is satisfied, either a direct
|
|
|
|
# dependency or any one of an OR array
|
2008-11-02 08:23:09 -01:00
|
|
|
sub dep_satisfied {
|
|
|
|
my $p = shift;
|
2012-09-26 18:18:47 +00:00
|
|
|
|
|
|
|
if ("ARRAY" eq ref $p) {
|
2008-11-02 08:23:09 -01:00
|
|
|
foreach (@{$p}) {
|
2012-09-26 18:18:47 +00:00
|
|
|
if (dep_pkg_included($_)) {
|
|
|
|
return 1;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
} elsif ("HASH" eq ref $p) {
|
|
|
|
return dep_pkg_included($p);
|
2008-11-02 08:23:09 -01:00
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
die "dep_satisfied: $p is neither a hash nor an array!\n";
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_ordepends {
|
|
|
|
my $i = shift;
|
|
|
|
my $lines = shift;
|
|
|
|
my @or = ();
|
2012-09-26 18:18:47 +00:00
|
|
|
my ($val, $dep, $last) = ('','',0);
|
|
|
|
my ($op, $version);
|
|
|
|
|
|
|
|
chomp $lines->[$$i];
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
while ($lines->[$$i]
|
2012-09-26 18:18:47 +00:00
|
|
|
=~ m/^\s([\s\|])((?:Pre)?Depends|Suggests|Recommends): (\S+)( \((\S+) (\S+)\))*/) {
|
2008-11-02 08:23:09 -01:00
|
|
|
$val = $3;
|
2012-09-26 18:18:47 +00:00
|
|
|
if (defined $4) {
|
|
|
|
$op = $5;
|
|
|
|
$version = $6;
|
|
|
|
} else {
|
|
|
|
$op = "";
|
|
|
|
$version = "";
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
$last = 1 if $1 ne '|'; #Stop when no more '|'
|
|
|
|
if ($val =~ m/^<.*>$/) {
|
|
|
|
$dep = read_virtualdepends ($i, $lines);
|
|
|
|
if (ref $dep) {
|
|
|
|
push @or, @{$dep};
|
|
|
|
} else {
|
|
|
|
push @or, $dep;
|
|
|
|
}
|
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
my %elt;
|
|
|
|
$elt{"Package"} = $val;
|
|
|
|
$elt{"CmpOp"} = $op;
|
|
|
|
$elt{"Version"} = $version;
|
|
|
|
push @or, \%elt;
|
|
|
|
$$i++;
|
|
|
|
# Hack for packages providing not a truly
|
2008-11-02 08:23:09 -01:00
|
|
|
# virtual package
|
2012-09-26 18:18:47 +00:00
|
|
|
while ($lines->[$$i] =~ m/^\s{4}(\S+)( \((\S+) (\S+)\))*/) {
|
2012-09-27 16:49:26 +00:00
|
|
|
my %elt1;
|
|
|
|
$elt1{"Package"} = $1;
|
2012-09-26 18:18:47 +00:00
|
|
|
if (defined $2) {
|
2012-09-27 16:49:26 +00:00
|
|
|
$elt1{"CmpOp"} = $3;
|
|
|
|
$elt1{"Version"} = $4;
|
2012-09-26 18:18:47 +00:00
|
|
|
} else {
|
2012-09-27 16:49:26 +00:00
|
|
|
$elt1{"CmpOp"} = "";
|
|
|
|
$elt1{"Version"} = "";
|
2012-09-26 18:18:47 +00:00
|
|
|
}
|
2012-09-27 16:49:26 +00:00
|
|
|
msg(1, " " . dump_depend(\%elt1) . "\n");
|
|
|
|
push @or, \%elt1;
|
2008-11-02 08:23:09 -01:00
|
|
|
$$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last if $last;
|
|
|
|
}
|
|
|
|
return \@or;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_virtualdepends {
|
|
|
|
my $i = shift;
|
|
|
|
my $lines = shift;
|
|
|
|
my $virtual;
|
|
|
|
my @or = ();
|
|
|
|
|
|
|
|
#Check for the lines with <>
|
|
|
|
if ($lines->[$$i]
|
|
|
|
=~ m/^\s[\s\|]((?:Pre)?Depends|Recommends|Suggests): <([^>]+)>/) {
|
|
|
|
$virtual = $2;
|
|
|
|
$$i++
|
|
|
|
}
|
|
|
|
# Now look at the alternatives on the following lines
|
2012-09-26 18:18:47 +00:00
|
|
|
while ($lines->[$$i] =~ m/^\s{4}(\S+)( \((\S+) (\S+)\))*/) {
|
|
|
|
my %elt;
|
|
|
|
$elt{"Package"} = $1;
|
|
|
|
if (defined $2) {
|
|
|
|
$elt{"CmpOp"} = $3;
|
|
|
|
$elt{"Version"} = $4;
|
|
|
|
} else {
|
|
|
|
$elt{"CmpOp"} = "";
|
|
|
|
$elt{"Version"} = "";
|
|
|
|
}
|
|
|
|
push @or, \%elt;
|
2008-11-02 08:23:09 -01:00
|
|
|
$$i++;
|
|
|
|
}
|
|
|
|
if (@or) {
|
|
|
|
return \@or;
|
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
my %elt;
|
|
|
|
$elt{"Package"} = $virtual;
|
|
|
|
$elt{"CmpOp"} = "";
|
|
|
|
$elt{"Version"} = "";
|
|
|
|
push @or, \%elt;
|
|
|
|
return \@or;
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_package {
|
|
|
|
my $p = shift;
|
|
|
|
my $add_rec = shift; # Do we look for recommends
|
|
|
|
my $add_sug = shift; # Do we look for suggests
|
2009-11-20 23:14:26 -01:00
|
|
|
my ($ok, $reasons);
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
msg(2, "+ Trying to add $p...\n");
|
|
|
|
if ($included{$p}) {
|
|
|
|
msg(2, " Already included ...\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get all dependencies (not yet included) of each package
|
|
|
|
my (@dep) = (get_missing ($p));
|
|
|
|
|
|
|
|
# Stop here if apt failed
|
|
|
|
if (not scalar(@dep)) {
|
|
|
|
msg(2, "Can't add $p ... dependency problem.\n");
|
|
|
|
return;
|
|
|
|
}
|
2009-11-20 23:14:26 -01:00
|
|
|
|
|
|
|
if ($packages{$p}{"Size"} > $max_pkg_size) {
|
|
|
|
msg(2, "Can't add $p ... too big!\n");
|
|
|
|
$excluded{$p} = 'toobig';
|
|
|
|
return;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(3, " \@dep before checklist = " . dump_depend(\@dep) . "\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
# Check if all packages are allowed (fail if one cannot)
|
2009-11-20 23:14:26 -01:00
|
|
|
($ok, $reasons) = check_list (\@dep, 1);
|
|
|
|
if (not $ok) {
|
|
|
|
msg(2, "Can't add $p ... one of the packages needed has " .
|
|
|
|
"been refused. Reasons: $reasons\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(3, " \@dep after checklist = " . dump_depend(\@dep) . "\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
if ($add_rec) {
|
2012-09-26 18:18:47 +00:00
|
|
|
#TODO: Look for recommends (not yet included !!)
|
|
|
|
add_recommends (\@dep, $p);
|
|
|
|
msg(3, " \@dep after add_recommends = " . dump_depend(\@dep) . "\n");
|
|
|
|
# Check again but doesn't fail if one of the package cannot be
|
|
|
|
# installed, just ignore it (it will be removed from @dep)
|
2009-11-20 23:14:26 -01:00
|
|
|
($ok, $reasons) = check_list (\@dep, 0);
|
|
|
|
if (not $ok) {
|
|
|
|
msg(0, "UNEXPECTED: It shouldn't fail here !\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(3, " \@dep after checklist2 = " . dump_depend(\@dep) . "\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2009-11-20 23:14:26 -01:00
|
|
|
|
2008-11-02 08:23:09 -01:00
|
|
|
if ($add_sug) {
|
|
|
|
#TODO: Look for suggests (not yet included !!)
|
2012-08-02 23:57:40 +00:00
|
|
|
add_suggests (\@dep, $p);
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(3, " \@dep after add_suggests = " . dump_depend(\@dep) . "\n");
|
2009-11-20 23:14:26 -01:00
|
|
|
# Check again but doesn't fail if one of the package cannot be
|
|
|
|
# installed, just ignore it (it will be removed from @dep)
|
|
|
|
($ok, $reasons) = check_list (\@dep, 0);
|
|
|
|
if (not $ok) {
|
|
|
|
msg(0, "UNEXPECTED: It shouldn't fail here !\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(3, " \@dep after checklist3 = " . dump_depend(\@dep) . "\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# All packages are ok, now list them out and add sizes
|
|
|
|
foreach my $t (@dep) {
|
|
|
|
my %t = %$t;
|
|
|
|
my $pkgname = $t{"Package"};
|
|
|
|
add_to_output($pkgname);
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub accepted {
|
|
|
|
my $p = shift;
|
|
|
|
return not $excluded{$p} if (exists $excluded{$p});
|
2012-09-26 18:18:47 +00:00
|
|
|
# Return false for a non-existent package ...
|
2008-11-02 08:23:09 -01:00
|
|
|
msg(1, "WARNING: $p cannot be accepted, it doesn't exist ...\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_suggests {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $deps_list = shift;
|
2012-08-02 23:57:40 +00:00
|
|
|
my $pkg = shift;
|
|
|
|
my @parents = ($pkg);
|
2008-11-02 08:23:09 -01:00
|
|
|
my $p; # = shift;
|
2012-09-26 18:18:47 +00:00
|
|
|
my @copy = @{$deps_list}; # A copy is needed since I'll modify the array
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
foreach $p (@copy) {
|
2012-09-26 18:18:47 +00:00
|
|
|
my %t = %$p;
|
|
|
|
my $pkgname = $t{"Package"};
|
|
|
|
add_missing($deps_list, $packages{$pkgname}{"Suggests"}, \%t, 1, \@parents);
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub add_recommends {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $deps_list = shift;
|
2012-08-02 23:57:40 +00:00
|
|
|
my $pkg = shift;
|
|
|
|
my @parents = ($pkg);
|
2008-11-02 08:23:09 -01:00
|
|
|
my $p; # = shift;
|
2012-09-26 18:18:47 +00:00
|
|
|
my @copy = @{$deps_list}; # A copy is needed since I'll modify the array
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
foreach $p (@copy) {
|
2012-09-26 18:18:47 +00:00
|
|
|
my %t = %$p;
|
|
|
|
my $pkgname = $t{"Package"};
|
|
|
|
add_missing($deps_list, $packages{$pkgname}{"Recommends"}, \%t, 1, \@parents);
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_missing {
|
|
|
|
my $p = shift;
|
2012-09-26 18:18:47 +00:00
|
|
|
my @deps_list = ();
|
2012-08-02 23:57:40 +00:00
|
|
|
my @parents = ();
|
2012-09-26 18:18:47 +00:00
|
|
|
my %t;
|
|
|
|
my $dep_text;
|
2008-11-02 08:23:09 -01:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
$t{"Package"} = $p;
|
|
|
|
$t{"CmpOp"} = "";
|
|
|
|
$t{"Version"} = "";
|
|
|
|
|
|
|
|
if (not add_missing (\@deps_list, $packages{$p}{"Depends"}, \%t, 0, \@parents)) {
|
2008-11-02 08:23:09 -01:00
|
|
|
return ();
|
|
|
|
}
|
2009-04-02 12:19:03 +00:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# Explicitly move the package itself to the end of the list,
|
|
|
|
# i.e. *after* all its dependencies
|
|
|
|
remove_entry(\%t, \@deps_list);
|
|
|
|
push @deps_list, \%t;
|
|
|
|
|
|
|
|
return (@deps_list);
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# Recursive function adding packages to our list
|
2008-11-02 08:23:09 -01:00
|
|
|
sub add_missing {
|
|
|
|
my $list = shift;
|
|
|
|
my $new = shift;
|
|
|
|
my $pkgin = shift;
|
|
|
|
my @backup = @{$list};
|
|
|
|
my $ok = 1;
|
2012-08-02 23:57:40 +00:00
|
|
|
my $soft_depend = shift;
|
|
|
|
my $parents = shift;
|
2012-09-26 18:18:47 +00:00
|
|
|
my $pkgname;
|
|
|
|
my (%pkgin);
|
|
|
|
|
|
|
|
if (ref $pkgin eq "HASH") {
|
|
|
|
%pkgin = %$pkgin;
|
|
|
|
} else {
|
|
|
|
die "add_missing passed a non-hash";
|
|
|
|
}
|
2012-08-02 23:57:40 +00:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
push(@{$parents}, $pkgin{"Package"});
|
2012-08-02 23:57:40 +00:00
|
|
|
#msg(3, " add_missing: parents atm @{$parents}\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
# Check all dependencies
|
2012-09-26 18:18:47 +00:00
|
|
|
foreach my $thisdep (@{$new}) {
|
|
|
|
my $textout = "";
|
|
|
|
$pkgname = $pkgin{"Package"};
|
|
|
|
|
|
|
|
# Print out status
|
|
|
|
if ("ARRAY" eq ref($thisdep)) {
|
2012-09-27 18:26:19 +00:00
|
|
|
if (scalar(@{$thisdep} > 1)) {
|
|
|
|
$textout = "(OR ";
|
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
foreach my $orpkg (@{$thisdep}) {
|
|
|
|
$textout .= dump_depend($orpkg) . " ";
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-27 18:26:19 +00:00
|
|
|
if (scalar(@{$thisdep} > 1)) {
|
|
|
|
$textout .= ")";
|
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
} elsif ("HASH" eq ref($thisdep)) {
|
|
|
|
$textout = dump_depend($thisdep);
|
2008-11-02 08:23:09 -01:00
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
die "add_missing: $thisdep should be an array or hash!\n";
|
|
|
|
}
|
|
|
|
msg(3, " $pkgname Dep: $textout soft_depend $soft_depend\n");
|
|
|
|
|
|
|
|
# Bail out early if we can!
|
|
|
|
if (dep_satisfied ($thisdep)) {
|
|
|
|
next;
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
|
|
|
|
# Still work to do...
|
2008-11-02 08:23:09 -01:00
|
|
|
# If it's an OR
|
2012-09-26 18:18:47 +00:00
|
|
|
if ("ARRAY" eq ref($thisdep)) {
|
2008-11-02 08:23:09 -01:00
|
|
|
my $or_ok = 0;
|
2012-09-26 18:18:47 +00:00
|
|
|
|
|
|
|
# First check all the OR packages up-front with no
|
|
|
|
# recursion. If *any* one of them is already installed, it
|
|
|
|
# will do.
|
|
|
|
foreach my $pkg (@{$thisdep}) {
|
|
|
|
my %t = %$pkg;
|
2015-07-23 17:39:43 +00:00
|
|
|
my $pkgname = lc $t{"Package"};
|
2012-09-26 18:18:47 +00:00
|
|
|
|
2015-07-23 17:39:43 +00:00
|
|
|
if (exists $packages{$pkgname} &&
|
|
|
|
($packages{$pkgname}{"Size"} > $max_pkg_size)) {
|
2015-07-21 17:46:06 +00:00
|
|
|
msg(2, " $pkgname is too big, mark it as excluded\n");
|
|
|
|
$excluded{$pkgname} = 'toobig';
|
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# Already installed?
|
|
|
|
if (dep_satisfied($pkg)) {
|
|
|
|
msg(3, " OR relationship already installed: " . dump_depend($pkg) . "\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
$or_ok = 1;
|
|
|
|
last;
|
2012-08-02 23:57:40 +00:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
|
|
|
|
# Pulled in already somewhere above us in the
|
|
|
|
# depth-first search? (yes, we have to cope with
|
|
|
|
# circular dependencies here...)
|
|
|
|
if (is_in ($t{"Package"}, $parents) &&
|
|
|
|
check_versions($t{"Version"}, $t{"CmpOp"}, $packages{$pkgname}{"Version"})) {
|
|
|
|
msg(3, " OR relationship already satisfied by parent " . dump_depend($pkg) . "\n");
|
|
|
|
$or_ok = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
msg(3, " " . dump_depend($pkg) . " not already installed\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# If we don't have any of the OR packages, then start
|
|
|
|
# again and try them in order. We always add the first
|
|
|
|
# package in the OR to allow APT to figure out which is
|
|
|
|
# the better one to install for any combination of
|
|
|
|
# packages that have similar alternative dependencies, but
|
|
|
|
# in different order. Having the first alternative
|
|
|
|
# available should be good enough for all cases we care
|
|
|
|
# about.
|
2012-08-02 23:57:40 +00:00
|
|
|
if (not $or_ok) {
|
|
|
|
msg(3, " OR relationship not already satisfied, looking at alternatives in order\n");
|
2012-09-26 18:18:47 +00:00
|
|
|
|
|
|
|
foreach my $pkg (@{$thisdep}) {
|
|
|
|
my %t = %$pkg;
|
|
|
|
my $pkgname = $t{"Package"};
|
|
|
|
if (not accepted($pkgname)) {
|
|
|
|
next;
|
2012-08-02 23:57:40 +00:00
|
|
|
}
|
|
|
|
# Check we don't already have the package
|
2012-09-26 18:18:47 +00:00
|
|
|
if (is_in_dep_list($pkg, $list)) {
|
2012-08-02 23:57:40 +00:00
|
|
|
$or_ok = 1;
|
|
|
|
last;
|
|
|
|
# Otherwise try to add it
|
2008-11-02 08:23:09 -01:00
|
|
|
} else {
|
2012-08-02 23:57:40 +00:00
|
|
|
# Stop after the first
|
|
|
|
# package that is
|
|
|
|
# added successfully
|
|
|
|
push (@{$list}, $pkg);
|
2012-09-26 18:18:47 +00:00
|
|
|
if (add_missing ($list, $packages{$pkgname}{"Depends"}, $pkg, $soft_depend, $parents)) {
|
2012-08-02 23:57:40 +00:00
|
|
|
$or_ok = 1;
|
|
|
|
remove_entry($pkg, $list);
|
|
|
|
push @{$list}, $pkg;
|
|
|
|
last;
|
|
|
|
} else {
|
|
|
|
pop @{$list};
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$ok &&= $or_ok;
|
|
|
|
if (not $ok) {
|
2012-09-26 18:18:47 +00:00
|
|
|
$pkgname = $pkgin{"Package"};
|
2012-08-02 23:57:40 +00:00
|
|
|
if ($soft_depend) {
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(1, " $pkgname failed, couldn't satisfy OR dep (but it's a soft dep, so ignoring...)\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
$ok = 1;
|
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(1, " $pkgname failed, couldn't satisfy OR dep\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
# Else it's a simple dependency
|
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
my %t = %{$thisdep};
|
|
|
|
my $pt = dump_depend(\%t);
|
|
|
|
msg(1, " Looking at adding $pt to satisfy dep\n");
|
|
|
|
|
|
|
|
if (not exists $packages{lc $t{"Package"}}) {
|
|
|
|
msg(1, " $pt doesn't exist...\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
if ($soft_depend) {
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(1, " soft dep: $pkgname ok, despite missing dep on $pt\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
$ok = 1;
|
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(1, " $pkgname failed, couldn't satisfy dep on $pt\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
$ok = 0;
|
|
|
|
last;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
if (dep_satisfied(\%t)) {
|
|
|
|
msg(1, " $pt already included\n");
|
|
|
|
next; # Already included, don't worry
|
|
|
|
}
|
|
|
|
if (is_in_dep_list(\%t, $list)) {
|
|
|
|
msg(1, " $pt already in dep list\n");
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
push @{$list}, \%t;
|
|
|
|
if (not add_missing ($list, $packages{$t{"Package"}}{"Depends"}, \%t, $soft_depend, $parents)) {
|
|
|
|
my $pkgname = $pkgin{"Package"};
|
|
|
|
msg(1, "couldn't add $pt ...\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
if ($soft_depend) {
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(1, "soft dep: $pkgname ok, despite missing dep on $pt\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
$ok = 1;
|
|
|
|
} else {
|
2012-09-26 18:18:47 +00:00
|
|
|
msg(1, "$pkgname failed, couldn't satisfy dep on $pt\n");
|
2012-08-02 23:57:40 +00:00
|
|
|
pop @{$list};
|
|
|
|
$ok = 0;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
remove_entry(\%t, $list);
|
|
|
|
push @{$list}, \%t;
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
# If a problem has come up, then restore the original list
|
|
|
|
if (not $ok) {
|
|
|
|
@{$list} = @backup;
|
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
if (not is_in_dep_list(\%pkgin, $list)) {
|
|
|
|
push @{$list}, \%pkgin;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
return $ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if $value is in @{$array}
|
|
|
|
sub is_in {
|
|
|
|
my $value = shift;
|
|
|
|
my $array = shift;
|
|
|
|
foreach my $key (@{$array}) {
|
|
|
|
return 1 if ($key eq $value);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
# Check if a package dependency is already in a dependency list
|
|
|
|
sub is_in_dep_list {
|
|
|
|
my $hash = shift;
|
|
|
|
my $array = shift;
|
|
|
|
my %t = %$hash;
|
|
|
|
|
|
|
|
foreach my $key (@{$array}) {
|
|
|
|
my %a = %$key;
|
|
|
|
if ($a{"Package"} eq $t{"Package"}) {
|
|
|
|
my $pn = $a{"Package"};
|
|
|
|
if (check_versions($t{"Version"}, $t{"CmpOp"}, $packages{$pn}{"Version"})) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-02 12:19:03 +00:00
|
|
|
# Remove an antry from @{$array}
|
|
|
|
sub remove_entry {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $tmp1 = shift;
|
|
|
|
my $array = shift;
|
|
|
|
my $entries = scalar(@{$array});
|
|
|
|
my $i;
|
|
|
|
my %t1 = %$tmp1;
|
2009-05-16 13:54:24 +00:00
|
|
|
|
2012-09-26 18:18:47 +00:00
|
|
|
for ($i=0; $i < $entries; $i++) {
|
|
|
|
my $tmp2 = @{$array}[$i];
|
|
|
|
my %t2 = %$tmp2;
|
|
|
|
if ($t1{"Package"} eq $t2{"Package"}) {
|
2009-04-02 12:19:03 +00:00
|
|
|
splice(@{$array}, $i, 1);
|
2012-09-26 18:18:47 +00:00
|
|
|
$i--;
|
|
|
|
$entries--;
|
|
|
|
}
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check a list of packages
|
|
|
|
sub check_list {
|
|
|
|
my $ref = shift;
|
|
|
|
my $fail = shift;
|
|
|
|
my $ok = 1;
|
|
|
|
my @to_remove = ();
|
2009-11-20 23:14:26 -01:00
|
|
|
my $reasons = "";
|
2012-09-26 18:18:47 +00:00
|
|
|
foreach my $thispkg (@{$ref}) {
|
|
|
|
my %t = %$thispkg;
|
|
|
|
my $pkgname = $t{"Package"};
|
|
|
|
if (not exists $excluded{$pkgname}) {
|
|
|
|
msg(1," $pkgname has been refused because it doesn't exist ...\n");
|
|
|
|
$ok = 0;
|
|
|
|
push @to_remove, $thispkg;
|
|
|
|
$reasons = $reasons . " noexist";
|
|
|
|
next;
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
if (not accepted($pkgname)) {
|
|
|
|
msg(1," $pkgname has been refused because of $excluded{$pkgname} ...\n");
|
|
|
|
$ok = 0;
|
|
|
|
push @to_remove, $thispkg;
|
|
|
|
$reasons = $reasons . " " . $excluded{$pkgname};
|
|
|
|
next;
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
2012-09-26 18:18:47 +00:00
|
|
|
if ($included{$pkgname}) {
|
|
|
|
msg(1, " $pkgname has already been included.\n");
|
|
|
|
push @to_remove, $thispkg;
|
|
|
|
$reasons = $reasons . " alreadyinc";
|
|
|
|
next;
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach my $removed (@to_remove) {
|
2012-09-26 18:18:47 +00:00
|
|
|
my %t = %$removed;
|
|
|
|
my $pkgname = $t{"Package"};
|
|
|
|
msg(2, " Removing $pkgname ... ($reasons )\n");
|
2008-11-02 08:23:09 -01:00
|
|
|
@{$ref} = grep { $_ ne $removed } @{$ref};
|
|
|
|
}
|
2009-11-20 23:14:26 -01:00
|
|
|
return ($fail ? $ok : 1, $reasons);
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Add packages to the output list
|
|
|
|
sub add_to_output {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $pkgname = shift;
|
|
|
|
my $size = $packages{$pkgname}{"Size"};
|
2008-11-02 08:23:09 -01:00
|
|
|
|
|
|
|
$output_size += $size;
|
2012-09-26 18:18:47 +00:00
|
|
|
$included{$pkgname} = 1;
|
|
|
|
push(@output, $pkgname);
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub yesno {
|
2012-09-26 18:18:47 +00:00
|
|
|
my $in = shift;
|
|
|
|
return $in ? "yes" : "no";
|
2008-11-02 08:23:09 -01:00
|
|
|
}
|