#! /usr/bin/perl
# ex:ts=8 sw=4:
# $OpenBSD$
#
# Copyright (c) 2024 Marc Espie <espie@openbsd.org>
#
# 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 v5.36;
my $portsdir = $ENV{PORTSDIR} // '/usr/ports';
my $rc = 0;
sub read_order($file)
{
my @list;
open my $f, "<", $file or return;
while (<$f>) {
chomp;
if (m/^([A-Z0-9_]+(:?\-[a-zA-Z0-9_]*)?)\s*\=/) {
push(@list, $1);
} elsif (m/^\#\s*([A-Z0-9_]+(:?\-[a-zA-Z0-9_]*)?)\s*\=/) {
push(@list, $1);
}
}
for my $i (@list) {
$i =~ s/\-.*/\-\*/;
}
return \@list;
}
my $ref = read_order("${portsdir}/infrastructure/templates/Makefile.template");
if (!defined $ref) {
say STDERR "Couldn't read rreference template";
exit 2;
}
my $all = {};
for my $i (@$ref) {
$all->{$i} = 1;
}
for my $name (@ARGV) {
my $port = read_order($name);
if (!defined $port) {
say STDERR "$name: Couldn't read";
$rc = 2;
next;
}
my $old = {};
while (my $e = shift @$port) {
if (!$all->{$e}) {
if ($e =~ m/^GH\_(?:ACCOUNT|COMMIT|PROJECT|TAGNAME)$/) {
say STDERR "$name: $e older-style GH stuff";
next;
}
# Don't even care about that one
if ($e eq 'V') {
next;
}
# surprisingly, those are not mentioned
if ($e =~ m/^(?:REVISION|EPOCH|REVISION)(\-\*)?$/) {
next;
}
say STDERR "$name: $e unknown";
next;
}
if ($old->{$e}) {
say "$name: $e found too late";
$rc = 1;
next;
}
while ($e ne $ref->[0]) {
$old->{$ref->[0]} = 1;
shift @$ref;
if (@$ref == 0) {
say "$name: $e not found in the right location";
last;
$rc = 1;
}
}
}
}
exit $rc;
This smaller script tries to match Makefile variables against Makefile.template
and reports violation.
(manpage should be trivial)
(this does not handle include files yet, though I'm not quite sure how
to proceed about those)
I'm not 100% sure it's something we want, quick poll of landry and aja says
"no", but I remember in the past some people insisting about respecting
Makefile.template order.
Surprisingly, stuff like REVISION and EPOCH is not in Makefile.template.
No comments:
Post a Comment