summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-04-24 14:29:56 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-04-24 14:29:56 +0000
commitabbb6547776afe984e6708422d24279b74820091 (patch)
treeb77776ae020134ddfe34f8aa6bfaef091098eb07 /usr.sbin
parentffa8e1d0d92fec715a2701cf5ab52d52c6106910 (diff)
more tweaks so that it can be extended and used during ports builds
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/LibSpec.pm66
1 files changed, 53 insertions, 13 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/LibSpec.pm b/usr.sbin/pkg_add/OpenBSD/LibSpec.pm
index 3e1f26f533f..0b5e676cada 100644
--- a/usr.sbin/pkg_add/OpenBSD/LibSpec.pm
+++ b/usr.sbin/pkg_add/OpenBSD/LibSpec.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: LibSpec.pm,v 1.6 2010/04/24 09:29:31 espie Exp $
+# $OpenBSD: LibSpec.pm,v 1.7 2010/04/24 14:29:55 espie Exp $
#
# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
@@ -20,6 +20,7 @@ use warnings;
package OpenBSD::LibObject;
+
sub key
{
my $self = shift;
@@ -42,11 +43,16 @@ sub minor
return $self->{minor};
}
-sub is_valid
+sub version
{
- return 1;
+ my $self = shift;
+ return ".".$self->major.".".$self->minor;
}
+sub is_static { 0 }
+
+sub is_valid { 1 }
+
sub stem
{
my $self = shift;
@@ -75,13 +81,26 @@ sub lookup
return $r;
}
+sub findbest
+{
+ my ($spec, $repo, $base) = @_;
+ my $r = $spec->lookup($repo, $base);
+ my $best;
+ for my $candidate (@$r) {
+ if (!defined $best || $candidate->is_better($best)) {
+ $best = $candidate;
+ }
+ }
+ return $best;
+}
+
package OpenBSD::BadLib;
our @ISA=qw(OpenBSD::LibObject);
sub to_string
{
my $self = shift;
- return $$self;
+ return $self;
}
sub new
@@ -119,8 +138,6 @@ sub register
push @{$repo->{$lib->stem}}, $lib;
}
-
-
package OpenBSD::Library;
our @ISA = qw(OpenBSD::LibObject);
@@ -160,6 +177,21 @@ sub no_match_dispatch
return $spec->no_match_shared($library, $base);
}
+sub is_better
+{
+ my ($self, $other) = @_;
+ if ($other->is_static) {
+ return 1;
+ }
+ if ($self->major > $other->major) {
+ return 1;
+ }
+ if ($self->major == $other->major && $self->minor > $other->minor) {
+ return 1;
+ }
+ return 0;
+}
+
package OpenBSD::LibSpec;
our @ISA = qw(OpenBSD::LibObject);
@@ -226,16 +258,10 @@ sub no_match_major
return $spec->major != $library->major;
}
-sub no_match_shared
+sub no_match_name
{
my ($spec, $library, $base) = @_;
- if ($spec->no_match_major($library)) {
- return "bad major";
- }
- if ($spec->minor > $library->minor) {
- return "minor is too small";
- }
if (defined $spec->{dir}) {
if ("$base/$spec->{dir}" eq $library->{dir}) {
return undef;
@@ -250,6 +276,20 @@ sub no_match_shared
return "bad directory";
}
+sub no_match_shared
+{
+ my ($spec, $library, $base) = @_;
+
+ if ($spec->no_match_major($library)) {
+ return "bad major";
+ }
+ if ($spec->major == $library->major &&
+ $spec->minor > $library->minor) {
+ return "minor is too small";
+ }
+ return $spec->no_match_name($library, $base);
+}
+
# classic double dispatch pattern
sub no_match
{