Browse Source

Add PKGBASE and FLAVOR checks

In a discussion with members of the port managers team (tcberner, rene) the issue of conflicting package base names came up.

I have offered to create portlint checks for 2 possible Makefile issues:

1) Conflicting use of ${PKGBASE} of an existing port.

2) Multiple flavors resulting in the same ${PKGBASE}.

The attached patch adds checks for both possible issues:

1) Check for the existence of the new PKGBASE in the INDEX file (if present) and warn if it is used for a different ORIGIN.

2) Generate PKGBASE for all FLAVORS and check for duplicates.

Submitted by:	se
PR:		263807
Joe Clarke 1 year ago
parent
commit
be8ccacedf
1 changed files with 39 additions and 1 deletions
  1. 39 1
      portlint.pl

+ 39 - 1
portlint.pl

@@ -1364,6 +1364,7 @@ sub checkmakefile {
 	my(@mman, @pman);
 	my(@aopt, @mopt, @opt);
 	my($pkg_version, $versiondir, $versionfile) = ('', '', '');
+	my $indexfile = '';
 	my $useindex = 0;
 	my %deprecated = ();
 	my @deplist = ();
@@ -3013,10 +3014,11 @@ DIST_SUBDIR EXTRACT_ONLY
 
 	$versiondir = $ENV{VERSIONDIR} // '/var/db/chkversion';
 
+	$indexfile = "$portsdir/$makevar{INDEXFILE}";
 	$versionfile = "$versiondir/VERSIONS";
 	$useindex = !-r "$versionfile";
 
-	$versionfile = "$portsdir/$makevar{INDEXFILE}"
+	$versionfile = $indexfile
 		if $useindex;
 
 	if (-r "$versionfile") {
@@ -3054,6 +3056,42 @@ DIST_SUBDIR EXTRACT_ONLY
 		close VERSIONS;
 	}
 
+	# use INDEX (if present) to check for PKGBASE collisions
+	if (-r "$indexfile") {
+	    open INDEX, "<$portsdir/$makevar{INDEXFILE}";
+	    while (<INDEX>) {
+			my($origin, $pkgbase) = ('', '');
+			chomp;
+			next if /^(#|$)/;
+			($pkgbase, $origin) = split /\|/;
+			$pkgbase =~ s,-[^-]+$,,;
+			$origin =~ s,^.*/([^/]+/[^/]+)/?$,$1,;
+			if ($pkgbase eq $makevar{PKGBASE} and $origin ne $makevar{PKGORIGIN}) {
+		    	&perror("FATAL", $file, -1, "The package base name \"$makevar{PKGBASE}\" is already in use by the \"$origin\" port. ".
+			    	"Choose another PORTNAME or use a PKGNAMEPREFIX or PKGNAMESUFFIX.");
+			}
+	    }
+	    close INDEX;
+	}
+
+	# verify that all flavors have distinct names
+	if ($makevar{FLAVORS}) {
+	    my %PKGFLAVOR;
+	    my @FLAVORS = split(/ /, $makevar{FLAVORS});
+	    my $makeenv_save = $makeenv;
+	    for my $flavor (@FLAVORS) {
+			$makeenv = $makeenv_save . " FLAVOR=$flavor";
+			my $pkgbase = &get_makevar("PKGBASE");
+			if ($PKGFLAVOR{$pkgbase}) {
+		    	&perror("FATAL", $file, -1, "The flavors \"$PKGFLAVOR{$pkgbase}\" and \"$flavor\" both generate a package named \"$pkgbase\". ".
+			    	"Make the package names unique, e.g., with different PKGNAMEPREFIX or PKGNAMESUFFIX values for each flavor.");
+			} else {
+		    	$PKGFLAVOR{$pkgbase} = $flavor;
+			}
+	    }
+	    my $makeenv = $makeenv_save;
+	}
+
 	# if DISTFILES have only single item, it is better to avoid DISTFILES
 	# and to use combination of DISTNAME and EXTRACT_SUFX (unless USE_GITHUB
 	# or USE_GITLAB is set to nodefault in which case it is fine).