metadata: always resolve dependencies through provides list

Instead of adding virtual packages to the normal package list, keep a
separate list for provides, make each package provide itself, and resolve
all dependencies through this list. This allows to use PROVIDES to replace
existing packages.

Fixes FS#837.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
This commit is contained in:
Matthias Schiffer 2018-01-08 12:17:30 +01:00
parent 565de8b8a8
commit 47d6b05ad3
No known key found for this signature in database
GPG key ID: 16EF3F64CB201D9C
3 changed files with 35 additions and 46 deletions

View file

@ -252,7 +252,6 @@ sub search_feed {
my $substr;
my $pkgmatch = 1;
next if $pkg->{vdepends};
foreach my $substr (@substr) {
my $match;
foreach my $key (qw(name title description src)) {
@ -306,7 +305,6 @@ sub list_feed {
get_feed($feed);
foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
my $pkg = $feed_package->{$name};
next if $pkg->{vdepends};
if($pkg->{name}) {
printf "\%-32s\t\%s\n", $pkg->{name}, $pkg->{title};
}
@ -534,6 +532,7 @@ sub install_package {
@{$feed_src->{$src}{"builddepends/host"}},
map { @{$_->{depends}} } @{$feed_src->{$src}{packages}}
) {
# TODO: handle virtual packages and PROVIDES
next if $dep =~ /@/;
$dep =~ s/^\+//;
$dep =~ s/^.+://;
@ -594,7 +593,6 @@ sub install {
get_feed($f->[1]);
foreach my $name (sort { lc($a) cmp lc($b) } keys %$feed_package) {
my $p = $feed_package->{$name};
next if $p->{vdepends};
if( $p->{name} ) {
install_package($feed, $p->{name}, exists($opts{f})) == 0 or $ret = 1;
get_feed($f->[1]);

View file

@ -2,9 +2,10 @@ package metadata;
use base 'Exporter';
use strict;
use warnings;
our @EXPORT = qw(%package %srcpackage %category %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
our @EXPORT = qw(%package %vpackage %srcpackage %category %features %overrides clear_packages parse_package_metadata parse_target_metadata get_multiline @ignore %usernames %groupnames);
our %package;
our %vpackage;
our %srcpackage;
our %category;
our %features;
@ -177,6 +178,7 @@ sub parse_target_metadata($) {
sub clear_packages() {
%package = ();
%vpackage = ();
%srcpackage = ();
%category = ();
%features = ();
@ -230,6 +232,9 @@ sub parse_package_metadata($) {
$pkg->{override} = $override;
$package{$1} = $pkg;
push @{$src->{packages}}, $pkg;
$vpackage{$1} or $vpackage{$1} = [];
unshift @{$vpackage{$1}}, $pkg;
};
/^Feature:\s*(.+?)\s*$/ and do {
undef $pkg;
@ -264,12 +269,8 @@ sub parse_package_metadata($) {
/^Provides: \s*(.+)\s*$/ and do {
my @vpkg = split /\s+/, $1;
foreach my $vpkg (@vpkg) {
$package{$vpkg} or $package{$vpkg} = {
name => $vpkg,
vdepends => [],
src => $src,
};
push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
$vpackage{$vpkg} or $vpackage{$vpkg} = [];
push @{$vpackage{$vpkg}}, $pkg;
}
};
/^Menu-Depends: \s*(.+)\s*$/ and $pkg->{mdepends} = [ split /\s+/, $1 ];

View file

@ -101,14 +101,16 @@ my %dep_check;
sub __find_package_dep($$) {
my $pkg = shift;
my $name = shift;
my $deps = ($pkg->{vdepends} or $pkg->{depends});
my $deps = $pkg->{depends};
return 0 unless defined $deps;
foreach my $dep (@{$deps}) {
next if $dep_check{$dep};
$dep_check{$dep} = 1;
return 1 if $dep eq $name;
return 1 if ($package{$dep} and (__find_package_dep($package{$dep},$name) == 1));
foreach my $vpkg (@{$deps}) {
foreach my $dep (@{$vpackage{$vpkg}}) {
next if $dep_check{$dep->{name}};
$dep_check{$dep->{name}} = 1;
return 1 if $dep->{name} eq $name;
return 1 if (__find_package_dep($dep, $name) == 1);
}
}
return 0;
}
@ -156,7 +158,6 @@ sub mconf_depends {
my $m = "depends on";
my $flags = "";
$depend =~ s/^([@\+]+)// and $flags = $1;
my $vdep;
my $condition = $parent_condition;
next if $condition eq $depend;
@ -173,23 +174,21 @@ sub mconf_depends {
}
$depend = $2;
}
next if $package{$depend} and $package{$depend}->{buildonly};
if ($flags =~ /\+/) {
if ($vdep = $package{$depend}->{vdepends}) {
my $vdep = $vpackage{$depend};
if ($vdep) {
my @vdeps;
$depend = undef;
foreach my $v (@$vdep) {
if ($package{$v} && $package{$v}->{variant_default}) {
$depend = $v;
next if $v->{buildonly};
if ($v->{variant_default}) {
unshift @vdeps, $v->{name};
} else {
push @vdeps, $v;
push @vdeps, $v->{name};
}
}
if (!$depend) {
$depend = shift @vdeps;
}
$depend = shift @vdeps;
if (@vdeps > 1) {
$condition = ($condition ? "$condition && " : '') . '!('.join("||", map { "PACKAGE_".$_ } @vdeps).')';
@ -209,8 +208,9 @@ sub mconf_depends {
$flags =~ /@/ or $depend = "PACKAGE_$depend";
} else {
if ($vdep = $package{$depend}->{vdepends}) {
$depend = join("||", map { "PACKAGE_".$_ } @$vdep);
my $vdep = $vpackage{$depend};
if ($vdep) {
$depend = join("||", map { "PACKAGE_".$_->{name} } @$vdep);
} else {
$flags =~ /@/ or $depend = "PACKAGE_$depend";
}
@ -419,29 +419,21 @@ sub gen_package_mk() {
$dep = $2;
}
my $pkg_dep = $package{$dep};
unless (defined $pkg_dep) {
my $vpkg_dep = $vpackage{$dep};
unless (defined $vpkg_dep) {
warn sprintf "WARNING: Makefile '%s' has a dependency on '%s', which does not exist\n",
$src->{makefile}, $dep;
next;
}
unless ($pkg_dep->{vdepends}) {
next if $srcname eq $pkg_dep->{src}{name};
# Filter out self-depends
my @vdeps = grep { $srcname ne $_->{src}{name} } @{$vpkg_dep};
my $depstr = "\$(curdir)/$pkg_dep->{src}{path}/compile";
my $depline = get_conditional_dep($condition, $depstr);
if ($depline) {
$deplines{''}{$depline}++;
foreach my $vdep (@vdeps) {
my $depstr = "\$(curdir)/$vdep->{src}{path}/compile";
if (@vdeps > 1) {
$depstr = "\$(if \$(CONFIG_PACKAGE_$vdep->{name}),$depstr)";
}
next;
}
foreach my $vdep (@{$pkg_dep->{vdepends}}) {
my $pkg_vdep = $package{$vdep};
next if $srcname eq $pkg_vdep->{src}{name};
my $depstr = "\$(if \$(CONFIG_PACKAGE_$vdep),\$(curdir)/$pkg_vdep->{src}{path}/compile)";
my $depline = get_conditional_dep($condition, $depstr);
if ($depline) {
$deplines{''}{$depline}++;
@ -449,8 +441,6 @@ sub gen_package_mk() {
}
}
next if defined $pkg->{vdepends};
my $config = '';
$config = "\$(CONFIG_PACKAGE_$pkg->{name})" unless $pkg->{buildonly};