summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingElement.pm105
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackingList.pm24
-rw-r--r--usr.sbin/pkg_add/pkg_create.135
3 files changed, 150 insertions, 14 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
index f5461479943..3361ab88112 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingElement.pm,v 1.195 2011/03/19 16:56:05 schwarze Exp $
+# $OpenBSD: PackingElement.pm,v 1.196 2011/05/30 09:59:38 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -893,7 +893,10 @@ sub new
$cdrom =~ s/^\'(.*)\'$/$1/;
$ftp =~ s/^\"(.*)\"$/$1/;
$ftp =~ s/^\'(.*)\'$/$1/;
- bless { subdir => $subdir, cdrom => $cdrom, ftp => $ftp}, $class;
+ bless { subdir => $subdir,
+ path => OpenBSD::PkgPath->new($subdir),
+ cdrom => $cdrom,
+ ftp => $ftp}, $class;
}
sub may_quote
@@ -909,8 +912,10 @@ sub may_quote
sub stringize
{
my $self = shift;
- return "subdir=".$self->{subdir}." cdrom=".may_quote($self->{cdrom}).
- " ftp=".may_quote($self->{ftp});
+ return join(' ',
+ "subdir=".$self->{subdir},
+ "cdrom=".may_quote($self->{cdrom}),
+ "ftp=".may_quote($self->{ftp}));
}
package OpenBSD::PackingElement::Name;
@@ -1028,6 +1033,13 @@ sub keyword() { "pkgpath" }
__PACKAGE__->register_with_factory;
sub category() { "pkgpath" }
+sub new
+{
+ my ($class, $fullpkgpath) = @_;
+ bless {name => $fullpkgpath,
+ path => OpenBSD::PkgPath::WithOpts->new($fullpkgpath)}, $class;
+}
+
package OpenBSD::PackingElement::Incompatibility;
our @ISA=qw(OpenBSD::PackingElement::Meta);
@@ -1846,4 +1858,89 @@ for my $k (qw(src display mtree ignore_inst dirrm pkgcfl pkgdep newdepend
__PACKAGE__->register_old_keyword($k);
}
+package OpenBSD::PkgPath;
+sub new
+{
+ my ($class, $fullpkgpath) = @_;
+ my ($dir, @mandatory) = split(/\,/, $fullpkgpath);
+ return bless {dir => $dir,
+ mandatory => {map {($_, 1)} @mandatory},
+ }, $class;
+}
+
+sub trim
+{
+ my ($self, $has, $from, $to_rm) = @_;
+ for my $f (keys %$to_rm) {
+ if ($has->{$f}) {
+ delete $from->{$f};
+ } else {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+sub match2
+{
+ my ($self, $has, $h) = @_;
+ if (keys %$h) {
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+sub match
+{
+ my ($self, $other) = @_;
+ # make a copy of options
+ my %h = %{$other->{mandatory}};
+ if (!$self->trim($other->{mandatory}, \%h, $self->{mandatory})) {
+ return 0;
+ }
+ if ($self->match2($other->{mandatory}, \%h)) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+package OpenBSD::PkgPath::WithOpts;
+our @ISA = qw(OpenBSD::PkgPath);
+
+sub new
+{
+ my ($class, $fullpkgpath) = @_;
+ my @opts = ();
+ while ($fullpkgpath =~ s/\[\,(.*?)\]//) {
+ push(@opts, {map {($_, 1)} split(/\,/, $1) });
+ };
+ my $o = $class->SUPER::new($fullpkgpath);
+ if (@opts == 0) {
+ bless $o, "OpenBSD::PkgPath";
+ } else {
+ $o->{opts} = \@opts;
+ }
+ return $o;
+}
+
+sub match2
+{
+ my ($self, $has, $h) = @_;
+ if (!keys %$h) {
+ return 1;
+ }
+ for my $opts (@{$self->{opts}}) {
+ my %h2 = %$h;
+ if ($self->trim($has, \%h2, $opts)) {
+ $h = \%h2;
+ if (!keys %$h) {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
index 625bbbb91a7..48f0c59a38c 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackingList.pm,v 1.111 2010/12/24 09:04:14 espie Exp $
+# $OpenBSD: PackingList.pm,v 1.112 2011/05/30 09:59:38 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -49,9 +49,16 @@ package OpenBSD::PackingList::hashpath;
sub match
{
my ($h, $plist) = @_;
- return
- defined $plist->fullpkgpath &&
- $h->{$plist->fullpkgpath};
+ my $f = $plist->fullpkgpath;
+ if (!defined $f) {
+ return 0;
+ }
+ for my $i (values @{$h->{$f->{dir}}}) {
+ if ($i->match($f)) {
+ return 1;
+ }
+ }
+ return 0;
}
package OpenBSD::Composite;
@@ -443,7 +450,7 @@ sub fullpkgpath
{
my $self = shift;
if (defined $self->{extrainfo} && $self->{extrainfo}->{subdir} ne '') {
- return $self->{extrainfo}->{subdir};
+ return $self->{extrainfo}->{path};
} else {
return undef;
}
@@ -454,12 +461,13 @@ sub pkgpath
if (!defined $self->{_hashpath}) {
my $h = $self->{_hashpath} =
bless {}, "OpenBSD::PackingList::hashpath";
- if (defined $self->fullpkgpath) {
- $h->{$self->fullpkgpath} = 1;
+ my $f = $self->fullpkgpath;
+ if (defined $f) {
+ push(@{$h->{$f->{dir}}}, $f);
}
if (defined $self->{pkgpath}) {
for my $i (@{$self->{pkgpath}}) {
- $h->{$i->name} = 1;
+ push(@{$h->{$i->{path}->{dir}}}, $i->{path});
}
}
}
diff --git a/usr.sbin/pkg_add/pkg_create.1 b/usr.sbin/pkg_add/pkg_create.1
index 875a597507f..9aaf9434d5f 100644
--- a/usr.sbin/pkg_add/pkg_create.1
+++ b/usr.sbin/pkg_add/pkg_create.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkg_create.1,v 1.74 2011/03/19 09:39:39 jmc Exp $
+.\" $OpenBSD: pkg_create.1,v 1.75 2011/05/30 09:59:38 espie Exp $
.\"
.\" Documentation and design originally from FreeBSD. All the code has
.\" been rewritten since. We keep the documentation's notice:
@@ -21,7 +21,7 @@
.\" [jkh] Took John's changes back and made some additional extensions for
.\" better integration with FreeBSD's new ports collection.
.\"
-.Dd $Mdocdate: March 19 2011 $
+.Dd $Mdocdate: May 30 2011 $
.Dt PKG_CREATE 1
.Os
.Sh NAME
@@ -697,6 +697,37 @@ When ports get renamed, or flavors change, extra
annotations can help
.Nm pkg_add
get a sense of continuity.
+Note that these
+.Ar pkgpath
+can take extra optional components, to allow the matching of several
+flavors at once, and are order independent.
+For instance,
+.Bd -literal -offset indent
+@pkgpath some/dir,f1,f2
+.Pp
+.Ed
+and
+.Bd -literal -offset indent
+@pkgpath some/dir,f2,f2,f1
+.Ed
+.Pp
+are equivalent.
+.Bd -literal -offset indent
+@pkgpath some/dir,f1[,f2,f3][,f4]
+.Ed
+.Pp
+will match all pkgpaths to some/dir with flavor f1, and optionally f4, and
+optionally both f2 and f3, e.g.,
+.Ar some/dir,f1,f4 ,
+.Ar some/dir,f1,f2,f3 ,
+.Ar some/dir,f1,f2,f3,f4 ,
+.Ar some/dir,f1
+would match,
+but
+.Ar some/dir,f1,f5 ,
+.Ar some/dir,f2,f3 ,
+.Ar some/dir,f1,f2,f4
+would not.
.Pp
.It Cm @rcscript Ar filename
Script for the