summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2006-11-11 16:13:44 +0000
committerMarc Espie <espie@cvs.openbsd.org>2006-11-11 16:13:44 +0000
commita63f5d6fcee098fee9301e73adab44fce551fc9e (patch)
treec37c3d4ede29ea77e205f6e8b1389d3d31d91d59 /usr.sbin/pkg_add
parent3d6cff53379ada68d18f4ea43295e76eb1828c1b (diff)
-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.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/pkg_mklocatedb47
1 files changed, 39 insertions, 8 deletions
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));
}
}