new tool to help porters: pkg_check-version

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

new tool to help porters: pkg_check-version

Marc Espie-2
(there are two diffs, the man page for src, and the tool itself)


This is supposed to live in /usr/ports/infrastructure/bin

Index: pkg_check-version
===================================================================
RCS file: pkg_check-version
diff -N pkg_check-version
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ pkg_check-version 27 Feb 2021 10:12:21 -0000
@@ -0,0 +1,139 @@
+#! /usr/bin/perl
+
+# ex:ts=8 sw=4:
+# $OpenBSD$
+#
+# Copyright (c) 2021 Marc Espie <[hidden email]>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+use strict;
+use warnings;
+
+package OpenBSD::VersionCheck::State;
+our @ISA = qw(OpenBSD::State);
+
+use OpenBSD::State;
+
+sub handle_options
+{
+ my $state = shift;
+
+ $state->SUPER::handle_options('Hv', '[Hv] pkg-name ...');
+ if (@ARGV == 0) {
+ $state->usage;
+ }
+}
+
+package OpenBSD::PackageName::dewey;
+sub human_print
+{
+ my ($self, $state) = @_;
+ $state->say("\tversion (split): #1", join(' ', @{$self->{deweys}}));
+ if ($self->{suffix} eq '') {
+ $state->say("\tno suffix");
+ } else {
+ $state->say("\twith suffix: #1 #2", $self->{suffix},
+    $self->{suffix_value});
+ }
+}
+
+package OpenBSD::PackageName::version;
+sub human_print
+{
+ my ($self, $state) = @_;
+ $self->{dewey}->human_print($state);
+ if (defined $self->{p}) {
+ $state->say("\tREVISION: #1", $self->{p});
+ } else {
+ $state->say("\tno REVISION");
+ }
+ if (defined $self->{v}) {
+ $state->say("\tEPOCH: #1", $self->{v});
+ } else {
+ $state->say("\tno EPOCH");
+ }
+}
+
+package OpenBSD::PackageName::Name;
+sub human_print
+{
+ my ($self, $state) = @_;
+ $state->say("\tstem: #1", $self->{stem});
+ $self->{version}->human_print($state);
+ $state->say("\tflavors: #1",
+    join(' ', (sort keys %{$self->{flavors}})));
+}
+
+sub add_to_stems
+{
+ my ($self, $h) = @_;
+ push(@{$h->{$self->to_pattern}}, $self);
+}
+
+package OpenBSD::PackageName::Stem;
+sub human_print
+{
+ my ($self, $state) = @_;
+ $state->say("\tstem = #1", $self->{stem});
+}
+
+sub add_to_stems
+{
+ # nothing to do for "pure stems"
+}
+
+package OpenBSD::VersionCheck;
+
+use OpenBSD::PackageName;
+
+sub parse_and_run
+{
+ my $self = shift;
+ my $rc = 0;
+ my $state = OpenBSD::VersionCheck::State->new('pkg-check_version');
+ $state->handle_options;
+ my $by_stem = {};
+ for my $name (@ARGV) {
+ my $v = OpenBSD::PackageName->from_string($name);
+ if ($state->opt('H')) {
+ $state->say("#1:", $name);
+ $v->human_print($state);
+ }
+ my @issues = $v->has_issues;
+ if (@issues > 0) {
+ for my $s (@issues) {
+ $state->errsay("#1: #2", $name, $s);
+ $rc = 1;
+ }
+ } elsif ($state->opt('v')) {
+ $state->errsay("#1 has no issues", $name);
+ }
+ $v->add_to_stems($by_stem);
+ }
+ for my $stem (sort keys %$by_stem) {
+ my $list = $by_stem->{$stem};
+ if (@$list == 1 && !$state->opt('v')) {
+ next;
+ }
+ my $h = $state->opt('v') ?
+    "#1 sorts as (older to newer): #2" :
+    "#1 sorted: #2";
+ $state->say($h, $stem,
+    join(' ', map {$_->to_string}
+     sort {$a->compare($b)} @$list));
+ }
+ return $rc;
+}
+
+exit(__PACKAGE__->parse_and_run);





Index: Makefile
===================================================================
RCS file: /cvs/src/share/man/man1/Makefile,v
retrieving revision 1.17
diff -u -p -r1.17 Makefile
--- Makefile 12 Nov 2019 16:39:10 -0000 1.17
+++ Makefile 27 Feb 2021 10:11:59 -0000
@@ -7,8 +7,8 @@ MAN= clang-local.1 help.1 intro.1 gcc-lo
 MAN+= build-debug-info.1 check-lib-depends.1 clean-old-distfiles.1 \
  dpb-replay.1 dpb.1 \
  outdated-perl-ports.1 \
- pkg_check-problems.1 pkg_check-manpages.1 pkg_outdated.1 \
- pkg_subst.1 \
+ pkg_check-problems.1 pkg_check-manpages.1 pkg_check-version.1 \
+ pkg_outdated.1 pkg_subst.1 \
  port-getpkgpath-helper.1 port-resolve-lib-helper.1 \
  port-search-helper.1 \
  portbump.1 portcheck.1 portgen.1 \
Index: pkg_check-version.1
===================================================================
RCS file: pkg_check-version.1
diff -N pkg_check-version.1
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ pkg_check-version.1 27 Feb 2021 10:11:59 -0000
@@ -0,0 +1,55 @@
+.\" $OpenBSD$
+.\"
+.\" Copyright (c) 2021 Marc Espie <[hidden email]>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate$
+.Dt PKG_CHECK-VERSION 1
+.Os
+.Sh NAME
+.Nm pkg_check-version
+.Nd verify parsing and ordering of package names.
+.Sh SYNOPSIS
+.Nm
+.Op Fl Hv
+.Ar pkgname ...
+.Sh DESCRIPTION
+.Nm
+takes a list of
+.Ar pkgname
+and processes them.
+.Bl -bullet -compact
+.It
+each name is parsed and checked for issues.
+.It
+in addition, comparable names (same stem and same flavor) are sorted
+from older to newer version.
+.El
+.Pp
+Options are as follows:
+.Bl -tag -width Hv
+.It Fl H
+displays a human-readable version of each
+.Ar pkgname
+(full version parsing, including known suffixes, dewey numbers parsing,
+REVISION, EPOCH, flavor markers).
+.It Fl v
+verbose mode, which will explicitly state
+.Ar pkgname
+with no issues and sort one element lists.
+.El
+.Sh SEE ALSO
+.Xr packages-specs 7
+.Sh AUTHORS
+.An Marc Espie Aq Mt [hidden email]