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
# than binary packages
sub do_install_package($$) {
sub do_install_src($$) {
my $feed = shift;
my $pkg = shift;
my $path;
$pkg->{src} and $path = $pkg->{src}{makefile};
my $src = shift;
if($path) {
my $path = $src->{makefile};
if ($path) {
$path =~ s/\/Makefile$//;
-d "./package/feeds" or mkdir "./package/feeds";
@ -418,6 +417,18 @@ sub do_install_target($) {
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($$) {
my $feed = shift;
my $package = shift;
@ -425,7 +436,7 @@ sub lookup_package($$) {
foreach my $feed ($feed, @feeds) {
next unless $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;
}
@ -442,9 +453,9 @@ sub lookup_target($$) {
return;
}
sub is_core_package($) {
my $package = shift;
foreach my $file ("tmp/info/.packageinfo-$package", glob("tmp/info/.packageinfo-*_$package")) {
sub is_core_src($) {
my $src = shift;
foreach my $file ("tmp/info/.packageinfo-$src", glob("tmp/info/.packageinfo-*_$src")) {
next unless index($file, "tmp/info/.packageinfo-feeds_");
return 1 if -s $file;
}
@ -455,6 +466,8 @@ sub install_target {
my $feed = shift;
my $name = shift;
$installed_targets{$name} and return 0;
$feed = $feed_cache{$feed->[1]}->[2];
$feed or return 0;
@ -465,85 +478,115 @@ sub install_target {
return do_install_target($target);
}
sub install_package {
sub install_src {
my $feed = shift;
my $name = shift;
my $force = shift;
my $ret = 0;
my $this_feed_target = lookup_target($feed, $name);
$this_feed_target and do {
$installed_targets{$name} and return 0;
install_target($this_feed_target, $name);
return 0;
};
$feed = lookup_package($feed, $name);
$feed or do {
$feed = lookup_src($feed, $name);
unless ($feed) {
$installed{$name} and return 0;
# TODO: check if it's already installed within ./package directory
$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";
$feed_src->{$name} or warn "WARNING: No feed for source package '$name' found\n";
return 0;
};
}
# switch to the metadata for the selected feed
my $cur = get_feed($feed->[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;
get_feed($feed->[1]);
my $src = $feed_src->{$name} or return 1;
# 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)) {
return 0 unless $force;
$override = 1;
}
# previously installed packages set the runtime package
if ($installed{$name}) {
# newly installed packages set the source package to 1
$installed{$src} and $installed{$src} == 1 and return 0;
# we'll trigger the override only with the 3 conditions below:
# - override is allowed by command line (-f)
# - a package with the same src exists in the core packages list
# - the package previously installed is not from a feed
my $override = 1 if ($force and is_core_package($src) and !$installed{$name}->{feed});
return 0 if ($installed{$name} == 1);
return 0 unless ($override);
}
# check previously installed packages
$installed{$name} and !$override and return 0;
$installed{$src} = 1;
$installed{$name} = 1;
foreach my $pkg (@{$src->{packages}}) {
foreach my $vpkg (@{$pkg->{provides}}) {
$installed_pkg{$vpkg} = 1;
}
}
defined($override) and $override == 1
and warn "Overriding core package '$src' with version from $feed->[1]\n"
or warn "Installing package '$src' from $feed->[1]\n";
if ($override) {
warn "Overriding core package '$name' with version 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";
return 1;
};
# install all dependencies referenced from the source package