From 8f1b0ee62a3589b6b0bfd4f886ae9f6bfd9ea76a Mon Sep 17 00:00:00 2001
From: Marcel Telka <marcel@telka.sk>
Date: Fri, 21 Jul 2023 14:07:40 +0200
Subject: [PATCH] makemaker.mk: add suggested test requirements

---
 make-rules/makemaker.mk |    1 +
 tools/perl-meta-deps    |   21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/make-rules/makemaker.mk b/make-rules/makemaker.mk
index 7d8a3fa..6e9be8e 100644
--- a/make-rules/makemaker.mk
+++ b/make-rules/makemaker.mk
@@ -230,6 +230,7 @@
 	$(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) runtime $(PERL_VERSION) < $< > $@
 $(BUILD_DIR)/%/.depend-test:	$(BUILD_DIR)/%/MYMETA.json
 	$(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test $(PERL_VERSION) < $< > $@
+	$(WS_TOOLS)/perl-meta-deps $(WS_MACH) $(BUILD_DIR) test runtime suggests $(PERL_VERSION) < $< >> $@
 
 $(BUILD_DIR)/META.depend-build.res:	$(BUILD_$(MK_BITS):%.built=%.depend-build)
 	$(CAT) $^ | $(SORT) -u > $@
diff --git a/tools/perl-meta-deps b/tools/perl-meta-deps
index 0738401..aa8e418 100755
--- a/tools/perl-meta-deps
+++ b/tools/perl-meta-deps
@@ -18,7 +18,7 @@
 function usage
 {
 	[[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1"
-	printf "Usage: perl-meta-deps WS_MACH BUILD_DIR [configure|build|test|runtime]... PERL_VERSION\n" >&2
+	printf "Usage: perl-meta-deps WS_MACH BUILD_DIR [configure|build|test|runtime]... [suggests] PERL_VERSION\n" >&2
 	[[ -n "$1" ]] && exit 1
 	exit 0
 }
@@ -43,6 +43,9 @@
 PHASES=${PHASES/#,}
 [[ -z "$PHASES" ]] && PHASES=".configure,.build,.test,.runtime"
 
+RELATION=".requires,.recommends"
+[[ "$1" == "suggests" ]] && RELATION=".$1" && shift
+
 (($# == 0)) && usage "PERL_VERSION missing"
 PERLVER=$1 && shift
 PLV=${PERLVER//.}
@@ -61,7 +64,7 @@
 find "$CACHEDIR" -type f -mtime +7 -exec rm -f {} \;
 
 
-/usr/bin/jq -r '.prereqs|'"$PHASES"'|.requires,.recommends|to_entries?|.[]|.key+" "+(.value|tostring)' | while read PREREQ VERSION ; do
+/usr/bin/jq -r '.prereqs|'"$PHASES"'|'"$RELATION"'|to_entries?|.[]|.key+" "+(.value|tostring)' | while read PREREQ VERSION ; do
 	# Convert perl version number to pkg(5) compatible form
 	VER=$("$PERL_VERSION_CONVERT" "$PREREQ" "$VERSION")
 	[[ "$VER" != "0" ]] && VER="@$VER" || VER=
@@ -69,7 +72,7 @@
 	CACHEFILE="$CACHEDIR/$PREREQ-$PERLVER"
 
 	# Resolve the dependency if not in cache already
-	if [[ ! -s "$CACHEFILE" ]] ; then
+	if [[ ! -e "$CACHEFILE" || ("$RELATION" != ".suggests" && ! -s "$CACHEFILE") ]] ; then
 		# We must replace '::' by '-' otherwise 'pkgdepend resolve' fails
 		MANIFEST="$BUILD_DIR/META-${PREREQ//::/-}-$PERLVER"
 
@@ -95,13 +98,17 @@
 			# Remove version number and cache the result
 			cat "$MANIFEST.res" | sed -e 's/@[^ ]*//g' -e 's/-'$PLV'/-$(PLV)/g' > "$CACHEFILE"
 		else
-			printf "ERROR: Prerequisite %s not found\n" "$PREREQ" >&2
-			cat "$MANIFEST"
+			if [[ "$RELATION" != ".suggests" ]] ; then
+				printf "ERROR: Prerequisite %s not found\n" "$PREREQ" >&2
+				cat "$MANIFEST"
+			fi
+			# Cache negative result
+			[[ ! -e "$CACHEFILE" ]] && > "$CACHEFILE"
 		fi
 	fi
 
-	# Use cached result (if any), add required version number and drop runtime/perl
-	[[ -f "$CACHEFILE" ]] && cat "$CACHEFILE" | sed -e 's/\(fmri=[^ ]*\)/\1'$VER'/g' -e '/fmri=pkg:\/runtime\/perl-\$(PLV)/d'
+	# Use cached result, add required version number and drop runtime/perl
+	cat "$CACHEFILE" | sed -e 's/\(fmri=[^ ]*\)/\1'$VER'/g' -e '/fmri=pkg:\/runtime\/perl-\$(PLV)/d'
 done | /usr/bin/pkgfmt -u | uniq | (
 	PREV_LINE_H=
 	PREV_FMRI=

--
Gitblit v1.9.3