From: espie Date: Tue, 6 Feb 2018 15:17:26 +0000 (+0000) Subject: refactor the "Signature" code for later X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=883f3189fd1653d7d2f404f5b89c6b800293e6a5;p=openbsd refactor the "Signature" code for later - all stuff being elements end up as version elements - store them directly in the hash, so that we can properly impose behavior depending on VersionElement (adding stuff to LibObject/PackageName was slightly icky) --- diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 4ce7be14e39..4fe2cfbc5f1 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.249 2018/01/24 16:52:44 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.250 2018/02/06 15:17:26 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie # @@ -352,9 +352,13 @@ sub category return ref(shift); } +# all the stuff that ends up in signatures +package OpenBSD::PackingElement::VersionElement; +our @ISA=qw(OpenBSD::PackingElement::Meta); + # all dependency information package OpenBSD::PackingElement::Depend; -our @ISA=qw(OpenBSD::PackingElement::Meta); +our @ISA=qw(OpenBSD::PackingElement::VersionElement); # Abstract class for all file-like elements package OpenBSD::PackingElement::FileBase; @@ -1022,7 +1026,7 @@ sub write_no_sig() } package OpenBSD::PackingElement::Version; -our @ISA=qw(OpenBSD::PackingElement::Unique); +our @ISA=qw(OpenBSD::PackingElement::Unique OpenBSD::PackingElement::VersionElement); sub keyword() { "version" } __PACKAGE__->register_with_factory; @@ -1091,7 +1095,7 @@ OpenBSD::Auto::cache(spec, }); package OpeNBSD::PackingElement::Libset; -our @ISA=qw(OpenBSD::PackingElement::Depend); +our @ISA=qw(OpenBSD::PackingElement::Meta); sub category() { "libset" } sub keyword() { "libset" } diff --git a/usr.sbin/pkg_add/OpenBSD/Signature.pm b/usr.sbin/pkg_add/OpenBSD/Signature.pm index 302298f18e0..f3a73e58d55 100644 --- a/usr.sbin/pkg_add/OpenBSD/Signature.pm +++ b/usr.sbin/pkg_add/OpenBSD/Signature.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Signature.pm,v 1.19 2017/09/18 13:01:10 espie Exp $ +# $OpenBSD: Signature.pm,v 1.20 2018/02/06 15:17:26 espie Exp $ # # Copyright (c) 2010 Marc Espie # @@ -18,56 +18,79 @@ use strict; use warnings; -package OpenBSD::PackageName::Name; -sub long_string +package OpenBSD::PackingElement; +sub signature {} + +package OpenBSD::PackingElement::VersionElement; +sub signature { - my $self = shift; - return '@'.$self->to_string; + my ($self, $hash) = @_; + $hash->{$self->signature_key} = $self; } sub always { - return 0; + return 1; } -package OpenBSD::LibObject; -sub long_string +package OpenBSD::PackingElement::Dependency; +sub signature_key { my $self = shift; - return $self->to_string; + return $self->{pkgpath}; } -sub always +sub sigspec { - return 1; + my $self = shift; + return OpenBSD::PackageName->from_string($self->{def}); } -package OpenBSD::PackingElement; -sub signature {} +sub long_string +{ + my $self = shift; + return '@'.$self->sigspec->to_string; +} -package OpenBSD::PackingElement::Dependency; -sub signature +sub compare { - my ($self, $hash) = @_; - $hash->{$self->{pkgpath}} = OpenBSD::PackageName->from_string($self->{def}); + my ($a, $b) = @_; + return $a->sigspec->compare($b->sigspec); } -package OpenBSD::PackingElement::Wantlib; -sub signature +sub always { - my ($self, $hash) = @_; + return 0; +} +package OpenBSD::PackingElement::Wantlib; +sub signature_key +{ + my $self = shift; my $spec = $self->spec; if ($spec->is_valid) { - $hash->{$spec->key} = $spec; + return $spec->key; + } else { + return "???"; } } -package OpenBSD::PackingElement::Version; +sub compare +{ + my ($a, $b) = @_; + return $a->spec->compare($b->spec); +} -sub signature +sub long_string { - my ($self, $hash) = @_; - $hash->{VERSION} = $self; + my $self = shift; + return $self->spec->to_string; +} + + +package OpenBSD::PackingElement::Version; +sub signature_key +{ + return 'VERSION'; } sub long_string