From a63f5d6fcee098fee9301e73adab44fce551fc9e Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Sat, 11 Nov 2006 16:13:44 +0000 Subject: -P option: prepend pkgpath instead of pkgname. -p option: use the continuation code from OpenBSD::PackingList in a sneaky way, so that we can read all packing-list contents in one go from a make print-plist-contents in /usr/ports. Allows building a located database from the ports tree without needing to build any packages. --- usr.sbin/pkg_add/pkg_mklocatedb | 47 ++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'usr.sbin/pkg_add/pkg_mklocatedb') diff --git a/usr.sbin/pkg_add/pkg_mklocatedb b/usr.sbin/pkg_add/pkg_mklocatedb index f554266399a..d2c95b97a95 100644 --- a/usr.sbin/pkg_add/pkg_mklocatedb +++ b/usr.sbin/pkg_add/pkg_mklocatedb @@ -33,12 +33,22 @@ sub print_name package main; -set_usage('pkg_mklocatedb -nq [-r release] [-s src] [-x X11src] [pkg-name [...]]'); +set_usage('pkg_mklocatedb [-nPq] [-r release] [-p portstree ] [-s src] [-x X11src] [pkg-name [...]]'); -our ($opt_n, $opt_q, $opt_s, $opt_x, $opt_r); +our ($opt_n, $opt_q, $opt_s, $opt_x, $opt_r, $opt_p, $opt_P); + +sub info +{ + my $plist = shift; + if ($opt_P) { + return $plist->{extrainfo}->{subdir}; + } else { + return $plist->pkgname(); + } +} try { - getopts('nqs:x:r:'); + getopts('nqs:x:r:p:P'); } catchall { Usage($_); }; @@ -102,20 +112,41 @@ if ($opt_r) { } closedir($dir); } - - -if (@ARGV==0) { +if ($opt_p) { + my $make = $ENV{MAKE} || 'make'; + open my $in, "cd $opt_p && $make print-plist-all |"; + my $done = 0; + while (!$done) { + my $plist = OpenBSD::PackingList->read($in, + sub { + my ($fh, $cont) = @_; + local $_; + while (<$fh>) { + return if m/^\=\=\=\> /o; + next unless m/^\@(?:cwd|name|info|man|file|lib|shell|comment\s+subdir\=)\b/o || !m/^\@/o; + &$cont($_); + } + $done = 1; + }); + if (defined $plist && defined $plist->pkgname()) { + $plist->visit('print_name', $fh, info($plist)); + } + } + close($in); +} + +elsif (@ARGV==0) { for my $pkgname (installed_packages()) { print STDERR "$pkgname\n" unless $opt_q; my $plist = OpenBSD::PackingList->from_installation($pkgname); - $plist->visit('print_name', $fh, $plist->pkgname()); + $plist->visit('print_name', $fh, info($plist)); } } else { for my $pkgname (@ARGV) { print STDERR "$pkgname\n" unless $opt_q; my $plist = OpenBSD::PackageLocator->grabPlist($pkgname); next unless $plist; - $plist->visit('print_name', $fh, $plist->pkgname()); + $plist->visit('print_name', $fh, info($plist)); } } -- cgit v1.2.3