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