prt-auf: fix the sorting by soft dependencies

This commit is contained in:
John McQuah 2023-03-25 10:11:42 -04:00
parent 8d43e3cd4d
commit c225a44932

View File

@ -109,11 +109,12 @@ if (($action =~ /^(listinst|listorphans|dependent)/) and
} elsif ($action =~ /^(current|isinst|dup|diff|quickdiff)$/) {
my $format = "%20s %15s %20s\n"; my $ind = shift(@results);
if ($action eq "diff") { printf $format, "Port", "Installed", "Available in Repo"; }
foreach my $diffline (@results) {
if ($action =~ /^(current|isinst)$/) { print "$diffline\n"; next; }
my ($diffN, $diffI, $diffR) = split(/ /, $diffline);
foreach (@results) {
if ($action =~ /^(current|isinst)$/) { print "$_\n"; next; }
my ($diffN, $diffI, $diffR) = split / /;
next if (($osearch{filter}) and ($diffN !~ /$osearch{filter}/));
next if (($LOCKED{$diffN}) and ($odepends{all}==0));
$diffR = ($LOCKED{$diffN}) ? "LOCKED" : $diffR;
printf "$format", $diffN, $diffI, $diffR if ($action eq "diff");
printf "%s ", $diffN if ($action eq "quickdiff");
}
@ -381,8 +382,6 @@ sub fill_hashes_from_cache {
$deps = <$cf>; $ignored=<$cf>; $softDeps = <$cf>;
chomp($deps, $softDeps, $DESC{$p}, $V_REPO{$p});
$DEPENDS{$p} = $deps; $SOFTDEPS{$p} = $softDeps;
$DEPENDS{$p} =~ s/, / /g; $DEPENDS{$p} =~ s/,/ /g;
$SOFTDEPS{$p} =~ s/, / /g; $SOFTDEPS{$p} =~ s/,/ /g;
for (my $i=8; $i<13; $i++) { $ignored = <$cf>; }
}
close ($cf);
@ -394,19 +393,17 @@ sub fill_hashes_from_pkgfiles {
if (! $V_REPO{$p}) { # only populate hashes with the first port found
my ($rver, $rrel, $rdesc, $rdeps, $rsoftdeps) = get_pkgfile_fields($pp);
$V_REPO{$p} = ($rver) ? $rver : "0";
$V_REPO{$p} .= ($rrel) ? "-$rrel" : "-1";
$DEPENDS{$p} = ($rdeps) ? $rdeps : "";
$SOFTDEPS{$p} = ($rsoftdeps) ? $rsoftdeps : "";
$DEPENDS{$p} =~ s/, / /g; $DEPENDS{$p} =~ s/,/ /g;
$SOFTDEPS{$p} =~ s/, / /g; $SOFTDEPS{$p} =~ s/,/ /g;
$DESC{$p} = ($rdesc) ? $rdesc : "";
$V_REPO{$p} = $rver;
$V_REPO{$p} .= "-$rrel";
$DEPENDS{$p} = $rdeps;
$SOFTDEPS{$p} = $rsoftdeps;
$DESC{$p} = $rdesc;
}
}
}
sub get_pkgfile_fields {
my ($descrip, $url, $maintainer, $Version, $Release)=('','','',0,0);
my ($descrip, $url, $maintainer, $Version, $Release)=('','','',0,1);
my ($readme, $preInstall, $postInstall, $Dependencies, $SoftDeps)=("no","no","no",'','');
my $portpath = shift; my $Name = (split /\//, $portpath)[-1];
my $pkgfile = "$portpath/Pkgfile";
@ -429,6 +426,11 @@ sub get_pkgfile_fields {
else {}
} close(PF);
if (($Version =~ m/\$\(.*\)/) or ($Version =~ m/`.*`/)) {
open(ECHO,"-|","bash -c \'source $pkgfile; echo \$version\'");
while(<ECHO>) { chomp; $Version = $_; }
}
$Dependencies =~ s/, / /g; $Dependencies =~ s/,/ /g;
$SoftDeps =~ s/, / /g; $SoftDeps =~ s/,/ /g;
if (shift) {
@ -662,23 +664,22 @@ sub port_diff { # find differences between the pkgdb and the repo
}
sub deporder { # returns a sorted list of packages required.
my $type=shift; my @seeds=@_; our @treewalk=(); our @missing;
our %numPred; our %children; my @result;
# determine the minimal set of targets needed to satisfy all dependencies
foreach my $t (@seeds) {
($V_REPO{$t}) ? recurse_deptree($t) : push (@missing, $t);
($V_REPO{$t}) ? recurse_deptree(0,$t) : push (@missing, $t);
}
sub recurse_deptree {
my $s=shift; my %curdeps; my @optionals;
my $greedy=shift; my $s=shift; my %curdeps; my @optionals;
if ((! $numPred{$s}) and ($greedy==0)) { $numPred{$s} = 0; }
# cycle detection
( grep /^$s$/, @treewalk ) ? return : push(@treewalk, $s);
if (! $numPred{$s}) { $numPred{$s} = 0; }
%curdeps = map { $_ => 0 } split /[ ,]/, $DEPENDS{$s};
# if the user toggles --softdeps, consider only the
# optional dependencies that are already installed
@ -692,11 +693,11 @@ sub deporder { # returns a sorted list of packages required.
if ($subit) {
$children{$s} .= " $subit ";
$numPred{$subit} += 1;
recurse_deptree($subit);
recurse_deptree($curdeps{$sd},$subit);
} else {
$children{$s} .= " $sd ";
$numPred{$sd} += 1;
recurse_deptree($sd);
recurse_deptree($curdeps{$sd},$sd);
}
}
pop (@treewalk);
@ -746,7 +747,7 @@ sub up_inst { # returns scalar references to five arrays
}
# exempt any locked ports from being updated
@targets = grep {(! $LOCKED{$_})} @targets;
@targets = grep {(! $LOCKED{$_})} @targets if ($opkg{nolock}==0);
# first determine the directories from which pkgmk must be called,
# the package that will appear after a successful build,
@ -785,26 +786,26 @@ sub up_inst { # returns scalar references to five arrays
next BUILDLOG;
}
if ($mkcmd{$t} ne "") {
push (@ok_readme, $t) if (-f $pdirs{$t}."/README");
if ((-f "$pdirs{$t}/pre-install") and ($opkg{runscripts} eq "yes")) {
system("sh","$pdirs{$t}/pre-install");
( $?>>8 == 0 ) ? $ok_pre{$t} = 1 : delete $ok_pre{$t};
}
chdir $pdirs{$t}; system("$mkcmd{$t}"); $status=( $?>>8 == 0 );
if ($logfile{$t}) {
( $status ) ? $ok{$t} = 1 : $not_ok{$t} = 1;
} else {
(! log_failure($logfile{$t})) ? $ok{$t} = 1 : $not_ok{$t} = 1;
} else {
( $status ) ? $ok{$t} = 1 : $not_ok{$t} = 1;
}
if ( $ok{$t} ) {
$addcmd{$t} =~ s/ -u / / if (! $V_INST{$t});
system("$addcmd{$t}");
if ( $?>>8 == 0 ) { $ok{$t} = 1;
push (@ok_readme, $t) if (-f $pdirs{$t}."/README");
} else {
$not_ok{$t} = 1; $ok{$t} = 0;
$not_ok{$t} = 1; delete $ok{$t};
}
unlink($logfile{$t}) if ( ($ok{$t}==1) and
($logfile{$t}) and ($olog{rm_on_success} eq "yes") );
unlink($logfile{$t}) if (($logfile{$t}) and
($olog{rm_on_success} eq "yes") );
}
if (($ok{$t}) and (-f "$pdirs{$t}/post-install")
and ($opkg{runscripts} eq "yes")) {
@ -812,7 +813,7 @@ sub up_inst { # returns scalar references to five arrays
( $?>>8 == 0 ) ? $ok_post{$t}=1 : delete $ok_post{$t};
}
}
last if (($opkg{group} eq "yes") and ($not_ok{$t}) and ($not_ok{$t}==1));
last if (($opkg{group} eq "yes") and ($not_ok{$t}));
}
sub log_failure {