4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
15 # Copyright 2022 Marcel Telka
20 [[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1"
21 printf "Usage: perl-meta-deps WS_MACH BUILD_DIR [runtime] PERL_VERSION\n" >&2
22 [[ -n "$1" ]] && exit 1
30 [[ -d "$WS_MACH" ]] && shift || usage
"WS_MACH does not exist"
33 [[ -d "$BUILD_DIR" ]] && shift || usage
"BUILD_DIR does not exist"
35 PHASES
=".configure,.build,.test,.runtime"
36 [[ "$1" == "runtime" ]] && PHASES
=".runtime" && shift
38 (($# == 0)) && usage
"PERL_VERSION missing"
41 PERL
=/usr
/perl
5/$PERLVER/bin
/perl
42 [[ -x "$PERL" ]] || usage
"perl $PERLVER not found"
43 PERL_ARCH
=$
($PERL -e 'use Config; print $Config{archname}')
45 (($# != 0)) && usage
"Too many arguments"
47 PERL_VERSION_CONVERT
="$(dirname $0)/perl-version-convert"
48 [[ ! -x "$PERL_VERSION_CONVERT" ]] && printf "ERROR: perl-version-convert not found" && exit 1
50 CACHEDIR
="$WS_MACH/perl-meta-deps-cache"
52 # Remove old entries from the cache
53 find "$CACHEDIR" -type f
-mtime +7 -exec rm -f {} \
;
56 printf "\n# Automatically generated dependencies based on distribution metadata\n"
58 /usr
/bin
/jq
-r '.prereqs|'"$PHASES"'|.requires|to_entries?|.[]|.key+" "+(.value|tostring)' |
while read PREREQ VERSION
; do
59 # Convert perl version number to pkg(5) compatible form
60 VER
=$
("$PERL_VERSION_CONVERT" "$PREREQ" "$VERSION")
61 [[ "$VER" != "0" ]] && VER
="@$VER" || VER
=
63 # Resolve the dependency if not in cache already
64 if [[ ! -s "$CACHEDIR/$PREREQ" ]] ; then
65 # We must replace '::' by '-' otherwise 'pkgdepend resolve' fails
66 MANIFEST
="$BUILD_DIR/META-${PREREQ//::/-}"
69 if [[ "$PREREQ" == "perl" ]] ; then
70 # "perl" is special case
71 cat <<#EOF > "$MANIFEST"
72 depend fmri
=__TBD
type=require pkg.debug.depend.
file=$PREREQ \\
73 pkg.debug.depend.path
=usr
/perl
5/$PERLVER/bin
76 cat <<#EOF > "$MANIFEST"
77 depend fmri
=__TBD
type=require pkg.debug.depend.
file=${PREREQ//:://}.pm
\\
78 pkg.debug.depend.path
=usr
/perl
5/$PERLVER/lib
\\
79 pkg.debug.depend.path
=usr
/perl
5/$PERLVER/lib
/$PERL_ARCH \\
80 pkg.debug.depend.path
=usr
/perl
5/vendor_perl
/$PERLVER \\
81 pkg.debug.depend.path
=usr
/perl
5/vendor_perl
/$PERLVER/$PERL_ARCH
86 if /usr
/bin
/pkgdepend resolve
"$MANIFEST" ; then
87 # Remove version number and cache the result
88 cat "$MANIFEST.res" |
sed -e 's/@[^ ]*//g' -e 's/-'$PLV'/-$(PLV)/g' > "$CACHEDIR/$PREREQ"
90 printf "ERROR: Prerequisite %s not found\n" "$PREREQ" >&2
95 # Use cached result (if any) and add required version number
96 [[ -f "$CACHEDIR/$PREREQ" ]] && cat "$CACHEDIR/$PREREQ" |
sed -e 's/\(fmri=[^ ]*\)/\1'$VER'/g'
97 done |
/usr
/bin
/pkgfmt
-u |
uniq |
(
103 # Copy verbatim lines without "fmri="
104 [[ "${LINE//*fmri=*/FMRI}" != "FMRI" ]] && printf "%s\n" "$LINE" && continue
106 LINE_H
=${LINE%%fmri=*}
107 LINE_T
=${LINE#*fmri=}
110 [[ "$FMRI" == "$LINE_T" ]] && LINE_T
=
113 [[ "$FMRI" == "$VER" ]] && VER
=
114 [[ -n "$VER" ]] && VER
="@$VER"
117 # There is no connection between module version and
118 # runtime/perl version for modules bundled with runtime/perl
119 [[ "$FMRI" == 'fmri=pkg:/runtime/perl-$(PLV)' ]] && VER
=
121 if [[ "$PREV_LINE_H" != "$LINE_H" ||
"$PREV_FMRI" != "$FMRI" ||
"$PREV_LINE_T" != "$LINE_T" ]] ; then
122 [[ -n "$PREV_LINE_H$PREV_FMRI$PREV_VER$PREV_LINE_T" ]] && printf "%s%s%s%s\n" "$PREV_LINE_H" "$PREV_FMRI" "$PREV_VER" "$PREV_LINE_T"
123 PREV_LINE_H
="$LINE_H"
126 PREV_LINE_T
="$LINE_T"
130 # Select higher version
134 [[ -z "$VER1" ]] && PREV_VER
="$VER" && break
135 [[ -z "$VER2" ]] && break
137 V1
=${VER1%%.*} ; [[ "$V1" == "$VER1" ]] && VER1
="$VER1."
138 V2
=${VER2%%.*} ; [[ "$V2" == "$VER2" ]] && VER2
="$VER2."
140 ((V1
< V2
)) && PREV_VER
="$VER" && break
147 [[ -n "$PREV_LINE_H$PREV_FMRI$PREV_VER$PREV_LINE_T" ]] && printf "%s%s%s%s\n" "$PREV_LINE_H" "$PREV_FMRI" "$PREV_VER" "$PREV_LINE_T"