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 [configure|build|test|runtime]... [suggests] 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"
38 configure|build|
test|runtime
)
39 PHASES
="$PHASES,.$1" && shift ;;
44 [[ -z "$PHASES" ]] && PHASES
=".configure,.build,.test,.runtime"
46 RELATION
=".requires,.recommends"
47 [[ "$1" == "suggests" ]] && RELATION
=".$1" && shift
49 (($# == 0)) && usage
"PERL_VERSION missing"
52 PERL
=/usr
/perl
5/$PERLVER/bin
/perl
53 [[ -x "$PERL" ]] || usage
"Perl $PERLVER not found"
54 PERL_ARCH
=$
($PERL -e 'use Config; print $Config{archname}')
56 (($# != 0)) && usage
"Too many arguments"
58 PERL_VERSION_CONVERT
="$(dirname $0)/perl-version-convert"
59 [[ ! -x "$PERL_VERSION_CONVERT" ]] && printf "ERROR: perl-version-convert not found" && exit 1
61 CACHEDIR
="$WS_MACH/perl-meta-deps-cache"
63 # Remove old entries from the cache
64 find "$CACHEDIR" -type f
-mtime +7 -exec rm -f {} \
;
67 /usr
/bin
/jq
-r '.prereqs|'"$PHASES"'|'"$RELATION"'|to_entries?|.[]|.key+" "+(.value|tostring)' |
while read PREREQ VERSION
; do
68 # Convert perl version number to pkg(5) compatible form
69 VER
=$
("$PERL_VERSION_CONVERT" "$PREREQ" "$VERSION")
70 [[ "$VER" != "0" ]] && VER
="@$VER" || VER
=
72 CACHEFILE
="$CACHEDIR/$PREREQ-$PERLVER"
74 # Resolve the dependency if not in cache already
75 if [[ ! -e "$CACHEFILE" ||
("$RELATION" != ".suggests" && ! -s "$CACHEFILE") ]] ; then
76 # We must replace '::' by '-' otherwise 'pkgdepend resolve' fails
77 MANIFEST
="$BUILD_DIR/META-${PREREQ//::/-}-$PERLVER"
80 if [[ "$PREREQ" == "perl" ]] ; then
81 # "perl" is special case
82 cat <<#EOF > "$MANIFEST"
83 depend fmri
=__TBD
type=require pkg.debug.depend.
file=$PREREQ \\
84 pkg.debug.depend.path
=usr
/perl
5/$PERLVER/bin
87 cat <<#EOF > "$MANIFEST"
88 depend fmri
=__TBD
type=require pkg.debug.depend.
file=${PREREQ//:://}.pm
\\
89 pkg.debug.depend.path
=usr
/perl
5/$PERLVER/lib
\\
90 pkg.debug.depend.path
=usr
/perl
5/$PERLVER/lib
/$PERL_ARCH \\
91 pkg.debug.depend.path
=usr
/perl
5/vendor_perl
/$PERLVER \\
92 pkg.debug.depend.path
=usr
/perl
5/vendor_perl
/$PERLVER/$PERL_ARCH
97 if /usr
/bin
/pkgdepend resolve
"$MANIFEST" ; then
98 # Remove version number and cache the result
99 cat "$MANIFEST.res" |
sed -e 's/@[^ ]*//g' -e 's/-'$PLV'/-$(PLV)/g' > "$CACHEFILE"
101 if [[ "$RELATION" != ".suggests" ]] ; then
102 printf "ERROR: Prerequisite %s not found\n" "$PREREQ" >&2
105 # Cache negative result
106 [[ ! -e "$CACHEFILE" ]] && > "$CACHEFILE"
110 # Use cached result, add required version number and drop runtime/perl
111 cat "$CACHEFILE" |
sed -e 's/\(fmri=[^ ]*\)/\1'$VER'/g' -e '/fmri=pkg:\/runtime\/perl-\$(PLV)/d'
112 done |
/usr
/bin
/pkgfmt
-u |
uniq |
(
118 # Copy verbatim lines without "fmri=pkg:" (e.g. unresolved lines)
119 [[ "${LINE//*fmri=pkg:*/FMRI}" != "FMRI" ]] && printf "%s\n" "$LINE" && continue
121 LINE_H
=${LINE%%fmri=*}
122 LINE_T
=${LINE#*fmri=}
125 [[ "$FMRI" == "$LINE_T" ]] && LINE_T
=
128 [[ "$FMRI" == "$VER" ]] && VER
=
129 [[ -n "$VER" ]] && VER
="@$VER"
132 if [[ "$PREV_LINE_H" != "$LINE_H" ||
"$PREV_FMRI" != "$FMRI" ||
"$PREV_LINE_T" != "$LINE_T" ]] ; then
133 [[ -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"
134 PREV_LINE_H
="$LINE_H"
137 PREV_LINE_T
="$LINE_T"
141 # Select higher version
145 [[ -z "$VER1" ]] && PREV_VER
="$VER" && break
146 [[ -z "$VER2" ]] && break
148 V1
=${VER1%%.*} ; [[ "$V1" == "$VER1" ]] && VER1
="$VER1."
149 V2
=${VER2%%.*} ; [[ "$V2" == "$VER2" ]] && VER2
="$VER2."
151 ((V1
< V2
)) && PREV_VER
="$VER" && break
158 [[ -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"