Properly resolve build depends to source packages and runtime depends to
binary packages. Dependencies on virtual packages are resolved to the first
provider now.
Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
# TODO: do_install_package etc. should deal with source packages rather
sub do_install_src($$) {
# than binary packages
sub do_install_package($$) {
my $feed = shift;
my $feed = shift;
my $pkg = shift;
my $src = shift;
my $path;
$pkg->{src} and $path = $pkg->{src}{makefile};
if($path) {
my $path = $src->{makefile};
if ($path) {
$path =~ s/\/Makefile$//;
$path =~ s/\/Makefile$//;
-d "./package/feeds" or mkdir "./package/feeds";
-d "./package/feeds" or mkdir "./package/feeds";
@ -418,6 +417,18 @@ sub do_install_target($) {
return 0;
return 0;
}
}
sub lookup_src($$) {
my $feed = shift;
my $src = shift;
foreach my $feed ($feed, @feeds) {
next unless $feed->[1];
next unless $feed_cache{$feed->[1]};
$feed_cache{$feed->[1]}->[1]->{$src} and return $feed;
}
return;
}
sub lookup_package($$) {
sub lookup_package($$) {
my $feed = shift;
my $feed = shift;
my $package = shift;
my $package = shift;
@ -425,7 +436,7 @@ sub lookup_package($$) {
foreach my $feed ($feed, @feeds) {
foreach my $feed ($feed, @feeds) {
next unless $feed->[1];
next unless $feed->[1];
next unless $feed_cache{$feed->[1]};
next unless $feed_cache{$feed->[1]};
$feed_cache{$feed->[1]}->[0]->{$package} and return $feed;
$feed_cache{$feed->[1]}->[3]->{$package} and return $feed;
}
}
return;
return;
}
}
@ -442,9 +453,9 @@ sub lookup_target($$) {
return;
return;
}
}
sub is_core_package($) {
sub is_core_src($) {
my $package = shift;
my $src = shift;
foreach my $file ("tmp/info/.packageinfo-$package", glob("tmp/info/.packageinfo-*_$package")) {
foreach my $file ("tmp/info/.packageinfo-$src", glob("tmp/info/.packageinfo-*_$src")) {
next unless index($file, "tmp/info/.packageinfo-feeds_");
next unless index($file, "tmp/info/.packageinfo-feeds_");
return 1 if -s $file;
return 1 if -s $file;
}
}
@ -455,6 +466,8 @@ sub install_target {
my $feed = shift;
my $feed = shift;
my $name = shift;
my $name = shift;
$installed_targets{$name} and return 0;
$feed = $feed_cache{$feed->[1]}->[2];
$feed = $feed_cache{$feed->[1]}->[2];
$feed or return 0;
$feed or return 0;
@ -465,85 +478,115 @@ sub install_target {
return do_install_target($target);
return do_install_target($target);
}
}
sub install_package {
sub install_src {
my $feed = shift;
my $feed = shift;
my $name = shift;
my $name = shift;
my $force = shift;
my $force = shift;
my $ret = 0;
my $ret = 0;
my $this_feed_target = lookup_target($feed, $name);
$feed = lookup_src($feed, $name);
$this_feed_target and do {
unless ($feed) {
$installed_targets{$name} and return 0;
install_target($this_feed_target, $name);
return 0;
};
$feed = lookup_package($feed, $name);
$feed or do {
$installed{$name} and return 0;
$installed{$name} and return 0;
# TODO: check if it's already installed within ./package directory
$feed_src->{$name} or warn "WARNING: No feed for source package '$name' found\n";
$feed_src->{$name} or is_core_package($name) or warn "WARNING: No feed for package '$name' found, maybe it's already part of the standard packages?\n";
return 0;
return 0;
};
}
# switch to the metadata for the selected feed
# switch to the metadata for the selected feed
my $cur = get_feed($feed->[1]);
get_feed($feed->[1]);
my $src = $feed_src->{$name} or return 1;
my $pkg = $cur->{$name} or return 1;
$pkg->{name} or do {
$installed{$name} and return 0;
# TODO: check if this is an alias package, maybe it's known by another name
warn "WARNING: Package '$name' is not available in feed $feed->[1].\n";
return 0;
};
my $src = $pkg->{src}{name};
my $type = $feed->[0];
$src or $src = $name;
# If it's a core package and we don't want to override, just return
# If it's a core package and we don't want to override, just return
!$force and is_core_package($src) and return 0;
my $override = 0;
if (is_core_src($name)) {
# previously installed packages set the runtime package
return 0 unless $force;
# newly installed packages set the source package to 1
$override = 1;
$installed{$src} and $installed{$src} == 1 and return 0;
}
# we'll trigger the override only with the 3 conditions below:
if ($installed{$name}) {
# - override is allowed by command line (-f)
# newly installed packages set the source package to 1
# - a package with the same src exists in the core packages list
return 0 if ($installed{$name} == 1);
# - the package previously installed is not from a feed
return 0 unless ($override);
my $override = 1 if ($force and is_core_package($src) and !$installed{$name}->{feed});
}
# check previously installed packages
$installed{$name} = 1;
$installed{$name} and !$override and return 0;
foreach my $pkg (@{$src->{packages}}) {
$installed{$src} = 1;
foreach my $vpkg (@{$pkg->{provides}}) {
$installed_pkg{$vpkg} = 1;
}
}
defined($override) and $override == 1
if ($override) {
and warn "Overriding core package '$src' with version from $feed->[1]\n"
warn "Overriding core package '$name' with version from $feed->[1]\n";
or warn "Installing package '$src' from $feed->[1]\n";
} else {
warn "Installing package '$name' from $feed->[1]\n";
}
do_install_package($feed, $pkg) == 0 or do {
do_install_src($feed, $src) == 0 or do {
warn "failed.\n";
warn "failed.\n";
return 1;
return 1;
};
};
# install all dependencies referenced from the source package
# install all dependencies referenced from the source package