From f5c4a03a048a60bca3d4bcfebbf6596fa5e52a54 Mon Sep 17 00:00:00 2001 From: espie Date: Mon, 8 Nov 2021 13:33:05 +0000 Subject: [PATCH] add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports infrastructure, so that pkg_create can catch some naming errors. --- usr.sbin/pkg_add/OpenBSD/PkgCreate.pm | 41 ++++++++++++++++++++++++++- usr.sbin/pkg_add/pkg_create.1 | 10 +++++-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm index 0890610154c..016baa27d1d 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: PkgCreate.pm,v 1.171 2021/01/26 12:13:21 espie Exp $ +# $OpenBSD: PkgCreate.pm,v 1.172 2021/11/08 13:33:05 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie # @@ -1623,6 +1623,42 @@ sub save_history return $l; } +sub validate_pkgname +{ + my ($self, $state, $pkgname) = @_; + + my $revision = $state->defines('REVISION_CHECK'); + my $epoch = $state->defines('EPOCH_CHECK'); + my $flavor_list = $state->defines('FLAVOR_LIST_CHECK'); + if ($revision eq '') { + $revision = -1; + } + if ($epoch eq '') { + $epoch = -1; + } + my $okay_flavors = {map {($_, 1)} split(/\s+/, $flavor_list) }; + my $v = OpenBSD::PackageName->from_string($pkgname); + my $errors = 0; + if ($v->{version}->p != $revision) { + $state->errsay("REVISION mismatch (REVISION=#1)", $revision); + $errors++; + } + if ($v->{version}->v != $epoch) { + $state->errsay("EPOCH mismatch (EPOCH=#1)", $epoch); + $errors++; + } + for my $f (keys %{$v->{flavors}}) { + if (!exists $okay_flavors->{$f}) { + $state->errsay("bad FLAVOR #1 (admissible flavorss #2)", + $f, $flavor_list); + $errors++; + } + } + if ($errors) { + $state->fatal("Can't continue"); + } +} + sub run_command { my ($self, $state) = @_; @@ -1676,6 +1712,9 @@ sub run_command if (!defined $plist->pkgname) { $state->fatal("can't write unnamed packing-list"); } + if (defined $state->defines('REVISION_CHECK')) { + $self->validate_pkgname($state, $plist->pkgname); + } if (defined $state->opt('q')) { if (defined $state->opt('Q')) { diff --git a/usr.sbin/pkg_add/pkg_create.1 b/usr.sbin/pkg_add/pkg_create.1 index 587c6abf800..2271ef8c089 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.120 2021/01/29 15:58:56 espie Exp $ +.\" $OpenBSD: pkg_create.1,v 1.121 2021/11/08 13:33:06 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: January 29 2021 $ +.Dd $Mdocdate: November 8 2021 $ .Dt PKG_CREATE 1 .Os .Sh NAME @@ -156,6 +156,12 @@ If defined, appended to the description. .It Cm USE_GROFF Set to 1 to have groff format manpages behind the scenes during package creation. +.It Cm REVISION_CHECK , EPOCH_CHECK , FLAVOR_LIST_CHECK +Set automatically by +.Xr bsd.port.mk 5 +to values that help +.Nm +catch a few errors in package naming. .El .It Fl d Oo Fl Oc Ns Ar desc Fetch long description for package from file -- 2.20.1