use new infra for progressmeters. Add caches to compute conflicts more

efficiently.
This commit is contained in:
espie 2010-06-10 23:08:14 +00:00
parent 8b82b5525d
commit bdc6afed31

View File

@ -1,6 +1,6 @@
#!/usr/bin/perl
# $OpenBSD: find-all-conflicts,v 1.17 2010/06/09 13:59:37 espie Exp $
# $OpenBSD: find-all-conflicts,v 1.18 2010/06/10 23:08:14 espie Exp $
# Copyright (c) 2000-2005
# Marc Espie. All rights reserved.
# Redistribution and use in source and binary forms, with or without
@ -35,7 +35,7 @@ use OpenBSD::PackageLocator;
use OpenBSD::PackageInfo;
use OpenBSD::PackingList;
use OpenBSD::Getopt;
use OpenBSD::State;
use OpenBSD::AddCreateDelete;
use OpenBSD::PkgCfl;
package OpenBSD::PackingElement;
@ -52,7 +52,7 @@ sub register
{
my ($self, $all_conflict, $all_deps, $pkgname) = @_;
my $file= File::Spec->canonpath($self->fullname());
my $file = File::Spec->canonpath($self->fullname);
# build one single list for each pkgnames combination
if (exists $all_conflict->{$file}) {
$pkg_list->{$all_conflict->{$file}}->{$pkgname} ||=
@ -85,25 +85,40 @@ package main;
my $cache = {};
my $cache2 = {};
my $cache3 = {};
my $cache4 = {};
sub direct_conflict
{
my ($conflicts, $pkg, $pkg2) = @_;
return $cache3->{$pkg}{$pkg2} //= $conflicts->{$pkg}->conflicts_with($pkg2);
}
sub has_a_conflict
{
my ($conflicts, $deps, $pkg, $pkg2) = @_;
return $cache4->{$pkg}{$pkg2} //= find_a_conflict($conflicts, $deps, $pkg, $pkg2);
}
sub find_a_conflict
{
my ($conflicts, $deps, $pkg, $pkg2) = @_;
return 0 if $pkg eq $pkg2;
if (defined $conflicts->{$pkg} && $conflicts->{$pkg}->conflicts_with($pkg2)) {
if (defined $conflicts->{$pkg} && direct_conflict($conflicts, $pkg, $pkg2)) {
return 1;
}
if (defined $deps->{$pkg}) {
for my $dep (@{$deps->{$pkg}}) {
if (find_a_conflict($conflicts, $deps, $dep, $pkg2)) {
if (has_a_conflict($conflicts, $deps, $dep, $pkg2)) {
return 1;
}
}
}
if (defined $deps->{$pkg2}) {
for my $dep (@{$deps->{$pkg2}}) {
if (find_a_conflict($conflicts, $deps, $pkg, $dep)) {
if (has_a_conflict($conflicts, $deps, $pkg, $dep)) {
return 1;
}
}
@ -120,8 +135,8 @@ sub compute_true_conflicts
my $keepit = 0;
for my $pkg2 (@$l) {
next if $pkg eq $pkg2;
if (!(find_a_conflict($conflicts, $deps, $pkg, $pkg2) ||
find_a_conflict($conflicts, $deps, $pkg2, $pkg))) {
if (!(has_a_conflict($conflicts, $deps, $pkg, $pkg2) ||
has_a_conflict($conflicts, $deps, $pkg2, $pkg))) {
$keepit = 1;
last;
}
@ -135,12 +150,15 @@ sub compute_true_conflicts
sub compute_problems
{
my ($h, $conflicts, $deps) = @_;
my ($ui, $h, $conflicts, $deps) = @_;
my $c = {};
my $c2 = {};
my $total = scalar(keys %$h);
my $i =0;
while (my ($key, $l) = each %$h) {
$ui->progress->show(++$i, $total);
if (!defined $c->{$l}) {
my %s = map {($_, 1)} @$l;
$c->{$l} = [sort keys %s];
@ -171,32 +189,30 @@ our ($opt_d, $opt_p, $opt_v);
sub handle_plist
{
my ($filename, $plist) = @_;
my ($ui, $filename, $plist) = @_;
if (!defined $plist) {
print STDERR "Error reading $filename\n";
$ui->errsay("Error reading #1", $filename);
return;
}
print "$filename -> ", $plist->pkgname(), "\n" if $opt_v;
$plist->forget();
$conflicts->{$plist->pkgname()} =
$ui->say("#1 -> #2", $filename, $plist->pkgname) if $ui->verbose;
$plist->forget;
$conflicts->{$plist->pkgname} =
OpenBSD::PkgCfl->make_conflict_list($plist);
$plist->register($filehash, $dephash, $plist->pkgname());
$plist->register($filehash, $dephash, $plist->pkgname);
}
sub handle_file
{
my $filename = shift;
my ($ui, $filename) = @_;
my $plist = OpenBSD::PackingList->fromfile($filename);
handle_plist($filename, $plist);
handle_plist($ui, $filename, $plist);
}
sub handle_portsdir
{
my $dir = shift;
my ($ui, $dir) = @_;
my $make = $ENV{MAKE} || 'make';
print STDERR "$dir\n";
open(my $input, "cd $dir && $make print-plist-all |");
my $done = 0;
while (!$done) {
@ -211,46 +227,54 @@ sub handle_portsdir
$done = 1;
});
if (defined $plist && $plist->pkgname()) {
handle_plist($dir, $plist);
handle_plist($ui, $dir, $plist);
$ui->progress->working(10);
}
}
}
my $ui = OpenBSD::State->new('find-all-conflicts');
$ui->usage_is('[-v] [-d plist_dir] [-p ports_dir] [pkgname ...]');
$ui->do_options(sub { getopts('d:p:v'); });
my $ui = OpenBSD::AddCreateDelete::State->new('find-all-conflicts');
OpenBSD::AddCreateDelete->handle_options('d:p:', $ui,
'[-v] [-d plist_dir] [-p ports_dir] [pkgname ...]');
print "Scanning\n" if $opt_v;
print "--------\n" if $opt_v;
$ui->progress->set_header("Scanning");
$opt_d = $ui->opt('d');
$opt_p = $ui->opt('p');
if ($opt_d) {
opendir(my $dir, $opt_d);
while (my $pkgname = readdir($dir)) {
next if $pkgname eq '.' or $pkgname eq '..';
handle_file("$opt_d/$pkgname");
}
my @l = readdir $dir;
closedir($dir);
my $total = scalar(@l);
my $i = 0;
for my $pkgname (@l) {
$ui->progress->show(++$i, $total);
next if $pkgname eq '.' or $pkgname eq '..';
handle_file($ui, "$opt_d/$pkgname");
}
} elsif ($opt_p) {
handle_portsdir($opt_p);
handle_portsdir($ui, $opt_p);
} elsif (@ARGV==0) {
@ARGV=(<*.tgz>);
}
my $i = 0;
for my $pkgname (@ARGV) {
print STDERR "$pkgname\n";
$ui->progress->show(++$i, scalar(@ARGV));
my $true_package = OpenBSD::PackageLocator->find($pkgname);
next unless $true_package;
my $dir = $true_package->info();
$true_package->close();
handle_file($dir.CONTENTS);
my $dir = $true_package->info;
$true_package->close;
handle_file($ui, $dir.CONTENTS);
rmtree($dir);
}
print "File problems:\n";
print "-------------\n";
compute_problems($filehash, $conflicts, $dephash);
$ui->progress->next;
$ui->progress->set_header("File problems");
compute_problems($ui, $filehash, $conflicts, $dephash);
for my $cfl (sort keys %$cache2) {
print "$cfl\n";
$ui->say("#1", $cfl);
for my $f (sort @{$cache2->{$cfl}}) {
print "\t$f\n";
$ui->say("\t#1", $f);
}
}