metadata: always resolve dependencies through provides list
authorMatthias Schiffer <mschiffer@universe-factory.net>
Mon, 8 Jan 2018 11:17:30 +0000 (12:17 +0100)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Sat, 13 Jan 2018 18:54:44 +0000 (19:54 +0100)
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>
scripts/feeds
scripts/metadata.pm
scripts/package-metadata.pl

index 4595c824a4b7c4836fdb1b67472dc476101e3d45..f5d764a175bd84abe978ec6a494d3567a0ddfaf5 100755 (executable)
@@ -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]);
index 5d829ebbcdd63ebb1a7c9da15cb7792f787af7b1..7c82cec809d2c75869e6b18eb20774e0e9feec36 100644 (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 ];
index c8ae27a730c5e75df65bda99c34c50c6d95a58c4..2dc29ea6ff3f0baae5464b527630f02fe1a76b00 100755 (executable)
@@ -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};