summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2021-11-08 13:33:07 +0000
committerMarc Espie <espie@cvs.openbsd.org>2021-11-08 13:33:07 +0000
commit47230f3770db17f5c6e43d52fda5db27d65ef52e (patch)
tree7584d7e11885074dc3e92a95cf40d8b5901f874d /usr.sbin/pkg_add
parentd482088f347a4432cc683c633963b077cb063c2e (diff)
add extra support to pass REVISION, EPOCH, FLAVOR_LIST from the ports
infrastructure, so that pkg_create can catch some naming errors.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgCreate.pm41
-rw-r--r--usr.sbin/pkg_add/pkg_create.110
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 <espie@openbsd.org>
#
@@ -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