commit | author | age
|
dc1665
|
1 |
#! /usr/bin/ksh |
MT |
2 |
# |
|
3 |
# |
|
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 |
|
7 |
# 1.0 of the CDDL. |
|
8 |
# |
|
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. |
|
12 |
# |
|
13 |
|
|
14 |
# |
|
15 |
# Copyright 2022 Marcel Telka |
|
16 |
# |
|
17 |
|
|
18 |
|
|
19 |
METACPANAPI=https://fastapi.metacpan.org/v1 |
|
20 |
CURL="/usr/bin/curl -s" |
|
21 |
|
|
22 |
|
|
23 |
function usage |
|
24 |
{ |
|
25 |
[[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1" |
b8bb9c
|
26 |
printf "Usage: perl-integrate-module [-l VERSION] [-o OBSOLETE].. [-u] MODULE\n" >&2 |
dc1665
|
27 |
[[ -n "$1" ]] && exit 1 |
MT |
28 |
exit 0 |
|
29 |
} |
|
30 |
|
|
31 |
|
|
32 |
VERSION= |
|
33 |
OBSOLETE= |
b8bb9c
|
34 |
UPGRADE_ONLY=0 |
MT |
35 |
while getopts ":hl:o:u" OPT ; do |
dc1665
|
36 |
case "$OPT" in |
MT |
37 |
"?"|"h") usage ;; |
|
38 |
"l") VERSION="$OPTARG" ;; |
|
39 |
"o") OBSOLETE="$OBSOLETE $OPTARG" ;; |
b8bb9c
|
40 |
"u") UPGRADE_ONLY=1 ;; |
dc1665
|
41 |
esac |
MT |
42 |
done |
|
43 |
shift $((OPTIND - 1)) |
|
44 |
|
|
45 |
(($# == 0)) && usage |
|
46 |
(($# > 1)) && usage "Too many arguments" |
|
47 |
|
|
48 |
MODULE="$1" |
|
49 |
|
|
50 |
|
|
51 |
WS_TOP=$(git rev-parse --show-toplevel 2>/dev/null) |
|
52 |
[[ -z "$WS_TOP" ]] && usage "The script must be run in git repo" |
|
53 |
|
|
54 |
DIR="$WS_TOP/components/perl" |
|
55 |
[[ -d "$DIR" ]] || usage "Directory $DIR not found" |
|
56 |
|
|
57 |
|
|
58 |
# Get data from metacpan |
|
59 |
METACPAN_MODULE=$($CURL "$METACPANAPI/module/$MODULE") |
|
60 |
if (($? != 0)) || [[ -z "$METACPAN_MODULE" ]] ; then |
|
61 |
printf "FATAL: Failed to get data from metacpan\n" >&2 |
|
62 |
exit 1 |
|
63 |
fi |
|
64 |
|
|
65 |
# Detect distribution for module |
|
66 |
DISTRIBUTION=$(printf "%s" "$METACPAN_MODULE" | /usr/bin/jq -r '.distribution') |
|
67 |
if (($? != 0)) || [[ -z "$DISTRIBUTION" || "$DISTRIBUTION" == "null" ]] ; then |
|
68 |
printf "FATAL: Failed to get distribution for module %s from metacpan\n" "$MODULE" >&2 |
|
69 |
exit 1 |
|
70 |
fi |
|
71 |
if [[ "$DISTRIBUTION" != "${MODULE//::/-}" ]] then |
|
72 |
printf "WARNING: Module %s does not match distribution %s\n" "$MODULE" "$DISTRIBUTION" |
|
73 |
printf "WARNING: Continue with module %s instead of %s\n" "${DISTRIBUTION//-/::}" "$MODULE" |
|
74 |
MODULE="${DISTRIBUTION//-/::}" |
|
75 |
fi |
|
76 |
|
|
77 |
# Find the latest version if not provided by user |
|
78 |
if [[ -z "$VERSION" ]] ; then |
|
79 |
VERSION=$(printf "%s" "$METACPAN_MODULE" | /usr/bin/jq -r '.version') |
|
80 |
if (($? != 0)) || [[ -z "$VERSION" || "$VERSION" == "null" ]] ; then |
|
81 |
printf "FATAL: Failed to get version for module %s from metacpan\n" "$MODULE" >&2 |
|
82 |
exit 1 |
|
83 |
fi |
|
84 |
fi |
|
85 |
|
|
86 |
# Get module author |
|
87 |
AUTHOR=$(printf "%s" "$METACPAN_MODULE" | /usr/bin/jq -r '.author') |
|
88 |
if (($? != 0)) || [[ -z "$AUTHOR" || "$AUTHOR" == "null" ]] ; then |
|
89 |
printf "FATAL: Failed to get author for module %s from metacpan\n" "$MODULE" >&2 |
|
90 |
exit 1 |
|
91 |
fi |
|
92 |
|
|
93 |
|
|
94 |
# Prepare the directory |
|
95 |
DIR="$DIR/$DISTRIBUTION" |
|
96 |
mkdir -p "$DIR" |
|
97 |
cd "$DIR" |
|
98 |
git restore --staged . > /dev/null 2>&1 |
|
99 |
git checkout . > /dev/null 2>&1 |
|
100 |
|
|
101 |
# Is this new module, or just a reboot? |
|
102 |
NEW=1 |
|
103 |
REBUILD=0 |
|
104 |
PREV_VER= |
|
105 |
PREV_REV=0 |
|
106 |
if git ls-files --error-unmatch Makefile > /dev/null 2>&1 ; then |
|
107 |
NEW=0 |
|
108 |
REBUILD=1 |
5994e2
|
109 |
PREV_VER=$(gmake print-value-COMPONENT_VERSION 2>/dev/null) |
MT |
110 |
PREV_REV=$(gmake print-value-COMPONENT_REVISION 2>/dev/null) |
b8bb9c
|
111 |
|
MT |
112 |
# If we were asked to do version upgrade, but we do not have new |
|
113 |
# version, then we are done. |
|
114 |
((UPGRADE_ONLY)) && [[ "$PREV_VER" == "$VERSION" ]] && exit 0 |
|
115 |
|
dc1665
|
116 |
gmake clobber > /dev/null 2>&1 |
MT |
117 |
fi |
|
118 |
|
299a09
|
119 |
# Remove everything from git (except known patches, history, and perl-integrate-module.conf) |
MT |
120 |
touch perl-integrate-module.conf |
|
121 |
grep "^%patch%" perl-integrate-module.conf | while read TAG PATCH ; do rm -f "patches/$PATCH" ; done |
97c70b
|
122 |
rm -f history perl-integrate-module.conf |
42c0cd
|
123 |
find . -type f | while read f ; do git rm "$f" > /dev/null 2>&1 ; done |
MT |
124 |
rm -rf "$DIR" |
dc1665
|
125 |
git checkout history > /dev/null 2>&1 |
97c70b
|
126 |
git checkout perl-integrate-module.conf > /dev/null 2>&1 |
MT |
127 |
touch perl-integrate-module.conf |
299a09
|
128 |
grep "^%patch%" perl-integrate-module.conf | while read TAG PATCH ; do |
MT |
129 |
git checkout "patches/$PATCH" > /dev/null 2>&1 |
|
130 |
[[ -f "patches/$PATCH" ]] || printf "ERROR: Patch %s not found\n" "$PATCH" >&2 |
|
131 |
done |
dc1665
|
132 |
|
MT |
133 |
|
|
134 |
# Makefile template |
97c70b
|
135 |
( |
MT |
136 |
cat $WS_TOP/transforms/copyright-template | sed -e '/^$/,$d' |
|
137 |
cat <<EOF |
dc1665
|
138 |
|
MT |
139 |
# |
|
140 |
# This file was automatically generated using the following command: |
|
141 |
# \$WS_TOOLS/perl-integrate-module $MODULE |
|
142 |
# |
|
143 |
|
|
144 |
BUILD_STYLE = makemaker |
97c70b
|
145 |
EOF |
56e9a5
|
146 |
gsed -e '0,/^%include-1%/d' -e '/^%/,$d' < perl-integrate-module.conf |
97c70b
|
147 |
cat <<EOF |
dc1665
|
148 |
|
MT |
149 |
include ../../../make-rules/shared-macros.mk |
|
150 |
|
|
151 |
COMPONENT_PERL_MODULE = $MODULE |
|
152 |
HUMAN_VERSION = $VERSION |
|
153 |
COMPONENT_REVISION = $((PREV_REV + 1)) |
|
154 |
COMPONENT_SUMMARY = $MODULE - TODO |
|
155 |
COMPONENT_CPAN_AUTHOR = $AUTHOR |
|
156 |
COMPONENT_ARCHIVE_HASH = \\ |
|
157 |
sha256:TODO |
|
158 |
COMPONENT_LICENSE = license:TODO |
|
159 |
COMPONENT_LICENSE_FILE = licfile:TODO |
|
160 |
EOF |
56e9a5
|
161 |
cat perl-integrate-module.conf | gsed -e '0,/^%include-2%/d' -e '/^%/,$d' | gsed -e '1s/^./\n&/' |
97c70b
|
162 |
printf "\ninclude \$(WS_MAKE_RULES)/common.mk\n" |
56e9a5
|
163 |
cat perl-integrate-module.conf | gsed -e '0,/^%include-3%/d' -e '/^%/,$d' | gsed -e '1s/^./\n&/' |
97c70b
|
164 |
printf "\n" |
MT |
165 |
) > Makefile |
|
166 |
|
dc1665
|
167 |
# Remove COMPONENT_REVISION if not needed |
MT |
168 |
COMPONENT_VERSION=$(gmake print-value-COMPONENT_VERSION) |
|
169 |
[[ "$PREV_VER" != "$COMPONENT_VERSION" ]] && REBUILD=0 && sed -i -e '/^COMPONENT_REVISION/d' Makefile |
|
170 |
|
|
171 |
# Calculate sham256 sum for source package |
|
172 |
gmake fetch > /dev/null 2>&1 |
|
173 |
USERLAND_ARCHIVES=$(gmake print-value-USERLAND_ARCHIVES) |
|
174 |
COMPONENT_ARCHIVE=$(gmake print-value-COMPONENT_ARCHIVE) |
|
175 |
SHA256=$(digest -a sha256 "$USERLAND_ARCHIVES/$COMPONENT_ARCHIVE") |
|
176 |
sed -i -e 's/sha256:TODO/sha256:'"$SHA256"'/g' Makefile |
|
177 |
|
|
178 |
# Unpack sources |
e08134
|
179 |
! gmake prep > /dev/null 2>&1 && printf "FATAL: 'gmake prep' failed!\n" >&2 && exit 1 |
dc1665
|
180 |
SOURCE_DIR=$DISTRIBUTION-$VERSION |
MT |
181 |
|
|
182 |
# Switch to modulebuild if needed |
|
183 |
[[ ! -f "$SOURCE_DIR/Makefile.PL" && -f "$SOURCE_DIR/Build.PL" ]] && sed -i -e 's/makemaker/modulebuild/g' Makefile |
|
184 |
|
78dea9
|
185 |
# Get abstract. Either from metacpan, or directly from sources. |
dc1665
|
186 |
ABSTRACT=$(printf "%s" "$METACPAN_MODULE" | /usr/bin/jq -r '.abstract') |
MT |
187 |
if (($? != 0)) || [[ -z "$ABSTRACT" || "$ABSTRACT" == "null" ]] ; then |
|
188 |
printf "WARNING: Failed to get abstract for module %s from metacpan\n" "$MODULE" >&2 |
|
189 |
ABSTRACT="TODO" |
|
190 |
fi |
|
191 |
if [[ "$ABSTRACT" == "TODO" ]] ; then |
|
192 |
if [[ ! -f "$SOURCE_DIR/META.json" ]] ; then |
|
193 |
printf "WARNING: META.json missing\n" >&2 |
|
194 |
else |
|
195 |
ABSTRACT=$(cat "$SOURCE_DIR/META.json" | /usr/bin/jq -r '.abstract') |
|
196 |
if (($? != 0)) || [[ -z "$ABSTRACT" || "$ABSTRACT" == "null" ]] ; then |
|
197 |
printf "WARNING: Failed to get abstract from META.json\n" >&2 |
78dea9
|
198 |
ABSTRACT="TODO" |
MT |
199 |
fi |
|
200 |
fi |
|
201 |
fi |
|
202 |
if [[ "$ABSTRACT" == "TODO" ]] ; then |
|
203 |
if [[ ! -f "$SOURCE_DIR/META.yml" ]] ; then |
|
204 |
printf "WARNING: META.yml missing\n" >&2 |
|
205 |
else |
|
206 |
ABSTRACT=$(cat "$SOURCE_DIR/META.yml" | python -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' | /usr/bin/jq -r '.abstract') |
|
207 |
if (($? != 0)) || [[ -z "$ABSTRACT" || "$ABSTRACT" == "null" ]] ; then |
|
208 |
printf "WARNING: Failed to get abstract from META.yml\n" >&2 |
dc1665
|
209 |
ABSTRACT="TODO" |
MT |
210 |
fi |
|
211 |
fi |
|
212 |
fi |
|
213 |
# Abstract needs to be sanitized |
|
214 |
ABSTRACT="${ABSTRACT//\`/\\\\\`}" |
|
215 |
ABSTRACT="${ABSTRACT//\"/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"}" |
|
216 |
ABSTRACT="${ABSTRACT//\//\/}" |
|
217 |
ABSTRACT="${ABSTRACT//\$/\\\\\$\$}" |
|
218 |
sed -i -e 's/\(COMPONENT_SUMMARY.*\)TODO$/\1'"$ABSTRACT"'/g' Makefile |
|
219 |
|
|
220 |
|
|
221 |
# Try to detect license type(s) |
|
222 |
function detect_license |
|
223 |
{ |
|
224 |
typeset -n L="$1" |
|
225 |
typeset F="$2" |
|
226 |
typeset D |
|
227 |
|
7f8fc8
|
228 |
if grep -A 1 "Apache License" "$F" | grep -q "Version 2\.0, January 2004" ; then |
dc1665
|
229 |
D="Apache-2.0" |
MT |
230 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
|
231 |
fi |
|
232 |
|
83d536
|
233 |
if grep -q -i "Artistic License" "$F" ; then |
MT |
234 |
if ! grep -q -i "Artistic License.*2" "$F" ; then |
|
235 |
D="Artistic-1.0-TODO" |
|
236 |
grep -q "7\. C subroutines" "$F" && grep -q "10\. THIS PACKAGE IS PROVIDED" "$F" && D="Artistic-1.0-Perl" |
|
237 |
grep -q "7\. C or perl subroutines" "$F" && grep -q "10\. THIS PACKAGE IS PROVIDED" "$F" && D="Artistic-1.0-cl8" |
|
238 |
grep -q "7\. C or perl subroutines" "$F" && grep -q "9\. THIS PACKAGE IS PROVIDED" "$F" && D="Artistic-1.0" |
|
239 |
else |
|
240 |
D="Artistic-2.0" |
|
241 |
fi |
dc1665
|
242 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
MT |
243 |
fi |
|
244 |
|
2a72f0
|
245 |
if grep -A 1 "GNU GENERAL PUBLIC LICENSE" "$F" | grep -q "Version 1, February 1989" ; then |
7f8fc8
|
246 |
D="GPL-1.0-only" |
dc1665
|
247 |
grep -A 2 "GNU General Public License as published by the" "$F" | grep -q "or (at your option) any" && D="GPL-1.0-or-later" |
MT |
248 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
|
249 |
fi |
|
250 |
|
7f8fc8
|
251 |
if grep -i -A 1 "GENERAL PUBLIC LICENSE" "$F" | grep -q "Version 2, June 1991" ; then |
MT |
252 |
D="GPL-2.0-only" |
|
253 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
|
254 |
fi |
|
255 |
|
|
256 |
if grep -A 1 "GNU LIBRARY GENERAL PUBLIC LICENSE" "$F" | grep -q "Version 2, June 1991" ; then |
|
257 |
D="LGPL-2.0-only" |
|
258 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
|
259 |
fi |
|
260 |
|
|
261 |
if grep -A 1 "GNU Lesser General Public License" "$F" | grep -q "Version 2\.1, February 1999" ; then |
|
262 |
D="LGPL-2.1-only" |
|
263 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
|
264 |
fi |
|
265 |
|
|
266 |
if grep -q "The MIT License" "$F" ; then |
dc1665
|
267 |
D="MIT-TODO" |
MT |
268 |
grep -q "The above copyright notice and this permission notice" "$F" && D="MIT" |
|
269 |
[[ -n "$L" ]] && L="$L OR " ; L="$L$D" |
|
270 |
fi |
|
271 |
} |
|
272 |
|
|
273 |
LICENSE= |
|
274 |
LICFILE= |
bed736
|
275 |
COPYRIGHT= |
7f8fc8
|
276 |
for f in LICENSE LICENCE COPYING COPYRIGHT ; do |
dc1665
|
277 |
[[ -f "$SOURCE_DIR/$f" ]] || continue |
MT |
278 |
LICFILE="$SOURCE_DIR/$f" |
|
279 |
|
|
280 |
detect_license LICENSE "$LICFILE" |
|
281 |
|
|
282 |
if [[ -n "$LICENSE" ]] ; then |
|
283 |
sed -i -e 's|licfile:TODO|'"$f"'|g' Makefile |
|
284 |
break |
|
285 |
fi |
|
286 |
|
|
287 |
printf "WARNING: Failed to detect license type in %s file\n" "$f" >&2 |
bed736
|
288 |
|
MT |
289 |
# Since the license file does not contain any known license we will use |
|
290 |
# its content as Copyright notice only |
|
291 |
COPYRIGHT=$(<"$LICFILE") |
dc1665
|
292 |
done |
MT |
293 |
if [[ -z "$LICFILE" ]] ; then |
|
294 |
printf "WARNING: No license file found\n" >&2 |
|
295 |
fi |
|
296 |
|
|
297 |
if [[ -z "$LICENSE" ]] ; then |
|
298 |
# Since the distibution does not provide own license file (or we failed |
|
299 |
# to find it) we will use default Perl license with added Copyright |
|
300 |
# notice from this distribution |
|
301 |
|
|
302 |
sed -i -e '/^COMPONENT_LICENSE_FILE/d' Makefile |
|
303 |
|
bed736
|
304 |
# Try to find Copyright notice if we do not have one yet |
MT |
305 |
[[ -z "$COPYRIGHT" ]] && for f in README README.md ; do |
dc1665
|
306 |
f="$SOURCE_DIR/$f" |
MT |
307 |
[[ -f "$f" ]] || continue |
|
308 |
|
9c22f5
|
309 |
COPYRIGHT=$(gsed -e '0,/^# LICENSE/d' -e '/^#/,$d' -e '/./,$!d' "$f" 2>/dev/null) |
dc1665
|
310 |
[[ -n "$COPYRIGHT" ]] && break |
9c22f5
|
311 |
COPYRIGHT=$(gsed -e '0,/^# COPYRIGHT/d' -e '/^#/,$d' -e '/./,$!d' "$f" 2>/dev/null) |
dc1665
|
312 |
[[ -n "$COPYRIGHT" ]] && break |
4b4e4b
|
313 |
COPYRIGHT=$(gsed -e '0,/LICENSE/d' -e '/^REPOSITORY/,$d' -e '/^SEE/,$d' -e '/./,$!d' "$f" 2>/dev/null) |
dc1665
|
314 |
[[ -n "$COPYRIGHT" ]] && break |
9c22f5
|
315 |
COPYRIGHT=$(gsed -e '0,/COPYING/d' -e '/^BUGS/,$d' -e '/^SEE/,$d' -e '/./,$!d' "$f" 2>/dev/null) |
MT |
316 |
[[ -n "$COPYRIGHT" ]] && break |
7f8fc8
|
317 |
COPYRIGHT=$(gsed -e '0,/COPYRIGHT/d' -e '/^AUTHOR/,$d' -e '/^SEE/,$d' -e '/./,$!d' "$f" 2>/dev/null) |
4b4e4b
|
318 |
[[ -n "$COPYRIGHT" ]] && break |
MT |
319 |
COPYRIGHT=$(gsed -e '0,/^## Copyright/d' -e '/./,$!d' "$f" 2>/dev/null) |
dc1665
|
320 |
[[ -n "$COPYRIGHT" ]] && break |
MT |
321 |
done |
|
322 |
if [[ -z "$COPYRIGHT" ]] ; then |
|
323 |
printf "WARNING: No copyright notice found at standard locations\n" >&2 |
dbf244
|
324 |
for f in $(find "$SOURCE_DIR" -type f -name "*.pm" | LC_ALL=C sort | while read f ; do egrep -q "^=head1 (LICENSE|LICENCE|COPYRIGHT)" "$f" && echo "$f" ; done) ; do |
dc1665
|
325 |
COPYRIGHT=$(sed -e '1,/^=head1 LICENSE/d' -e '/^=/,$d' "$f" 2>/dev/null) |
MT |
326 |
if [[ -n "$COPYRIGHT" ]] ; then |
|
327 |
printf "WARNING: Using copyright notice from %s\n" "$f" |
|
328 |
break |
|
329 |
fi |
dbf244
|
330 |
COPYRIGHT=$(sed -e '1,/^=head1 LICENCE/d' -e '/^=/,$d' "$f" 2>/dev/null) |
MT |
331 |
if [[ -n "$COPYRIGHT" ]] ; then |
|
332 |
printf "WARNING: Using copyright notice from %s\n" "$f" |
|
333 |
break |
|
334 |
fi |
dc1665
|
335 |
COPYRIGHT=$(sed -e '1,/^=head1 COPYRIGHT/d' -e '/^=/,$d' "$f" 2>/dev/null) |
MT |
336 |
if [[ -n "$COPYRIGHT" ]] ; then |
|
337 |
printf "WARNING: Using copyright notice from %s\n" "$f" |
|
338 |
break |
|
339 |
fi |
|
340 |
done |
|
341 |
fi |
|
342 |
if [[ -z "$COPYRIGHT" ]] ; then |
|
343 |
printf "WARNING: No copyright notice found\n" >&2 |
|
344 |
> "$DISTRIBUTION.license" |
|
345 |
else |
4b4e4b
|
346 |
(printf "%s\n\n" "$COPYRIGHT" | dos2unix -ascii |
dc1665
|
347 |
i=75 ; while ((i)) ; do printf "=" ; i=$((i-1)) ; done |
MT |
348 |
printf "\n\n") > "$DISTRIBUTION.license" |
|
349 |
fi |
|
350 |
|
2a72f0
|
351 |
USE_DEFAULT_PERL_LICENSE=1 |
dc1665
|
352 |
|
2a72f0
|
353 |
# Execute hook-no-license snippet |
56e9a5
|
354 |
gsed -e '0,/^%hook-no-license%/d' -e '/^%/,$d' < perl-integrate-module.conf > perl-integrate-module.snippet |
2a72f0
|
355 |
. ./perl-integrate-module.snippet |
MT |
356 |
rm -f perl-integrate-module.snippet |
dc1665
|
357 |
|
2a72f0
|
358 |
|
MT |
359 |
if ((USE_DEFAULT_PERL_LICENSE)) ; then |
|
360 |
# Confirm the package is distributed under the same terms as Perl itself |
|
361 |
D=1 |
|
362 |
((D)) && (printf "%s\n" "$COPYRIGHT" | grep -q -i "under the same terms as Perl itself") && D=0 |
7f8fc8
|
363 |
((D)) && grep -q "license *=> *'http://dev\.perl\.org/licenses/'" "$SOURCE_DIR/Makefile.PL" 2>/dev/null && D=0 |
2a72f0
|
364 |
((D)) && grep -q "LICENSE *=> *'perl'" "$SOURCE_DIR/Makefile.PL" 2>/dev/null && D=0 |
78dea9
|
365 |
((D)) && [[ -f "$SOURCE_DIR/META.json" && "$(/usr/bin/jq -r '.license[]' < "$SOURCE_DIR/META.json" 2>/dev/null)" == "perl_5" ]] && D=0 |
MT |
366 |
((D)) && [[ -f "$SOURCE_DIR/META.yml" && "$(cat "$SOURCE_DIR/META.yml" \ |
|
367 |
| python -c 'import sys, yaml, json; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' \ |
|
368 |
| /usr/bin/jq -r '.license[]' 2>/dev/null)" == "perl_5" ]] && D=0 |
2a72f0
|
369 |
|
MT |
370 |
((D)) && printf "ERROR: Heuristics failed to detect license type, using default Perl license\n" >&2 |
|
371 |
|
|
372 |
# Make a copy of license so we can use it during publish |
|
373 |
cat "$WS_TOP/tools/perl-license" | grep -v "^#" >> "$DISTRIBUTION.license" |
|
374 |
fi |
dc1665
|
375 |
git add "$DISTRIBUTION.license" |
MT |
376 |
|
7f8fc8
|
377 |
[[ -z "$LICENSE" ]] && detect_license LICENSE "$DISTRIBUTION.license" |
2a72f0
|
378 |
[[ -z "$LICENSE" ]] && LICENSE="TODO" |
dc1665
|
379 |
fi |
MT |
380 |
|
|
381 |
# Store the detected license into the Makefile |
|
382 |
sed -i -e 's/license:TODO/'"$LICENSE"'/g' Makefile |
|
383 |
|
|
384 |
|
|
385 |
# Create manifests |
|
386 |
if ! gmake sample-manifest > /dev/null 2>&1 ; then |
c638b3
|
387 |
printf "ERROR: 'gmake sample-manifest' failed!\n" >&2 |
dc1665
|
388 |
else |
MT |
389 |
cat manifests/sample-manifest.p5m \ |
|
390 |
| sed -e 's/^#.*Copyright.*<contributor>.*$/# This file was automatically generated using perl-integrate-module/g' \ |
|
391 |
> "$DISTRIBUTION-PERLVER.p5m" |
56e9a5
|
392 |
|
MT |
393 |
# Execute hook-manifest snippet |
|
394 |
gsed -e '0,/^%hook-manifest%/d' -e '/^%/,$d' < perl-integrate-module.conf > perl-integrate-module.snippet |
|
395 |
. ./perl-integrate-module.snippet |
|
396 |
rm -f perl-integrate-module.snippet |
|
397 |
|
dc1665
|
398 |
git add manifests/sample-manifest.p5m "$DISTRIBUTION-PERLVER.p5m" |
MT |
399 |
fi |
|
400 |
|
|
401 |
|
56e9a5
|
402 |
# perl-integrate-module.conf is no longer needed |
MT |
403 |
rm -f perl-integrate-module.conf |
|
404 |
git checkout perl-integrate-module.conf > /dev/null 2>&1 |
|
405 |
|
|
406 |
|
dc1665
|
407 |
# Generate REQUIRED_PACKAGES |
c638b3
|
408 |
gmake REQUIRED_PACKAGES > /dev/null 2>&1 || printf "ERROR: 'gmake REQUIRED_PACKAGES' failed!\n" >&2 |
dc1665
|
409 |
git add Makefile |
MT |
410 |
|
|
411 |
|
4a6306
|
412 |
# Check for Makefile completeness |
MT |
413 |
grep -q "TODO" Makefile && printf "ERROR: Makefile is not complete (TODO found)\n" |
|
414 |
|
|
415 |
|
dc1665
|
416 |
# Make sure the build environment is setup properly and we do have all |
MT |
417 |
# requirements installed. Otherwise we cannot continue. |
|
418 |
! gmake env-check > /dev/null 2>&1 && printf "FATAL: 'gmake env-check' failed!\n" >&2 && exit 1 |
|
419 |
|
|
420 |
|
4a6306
|
421 |
PERL_VERSIONS=$(gmake print-value-PERL_VERSIONS) |
MT |
422 |
|
|
423 |
|
|
424 |
# Run tests and create results master file(s) |
|
425 |
COMPONENT_TEST_MASTER_PREV= |
|
426 |
for v in $PERL_VERSIONS ; do |
|
427 |
COMPONENT_TEST_MASTER=$(gmake PERL_VERSION=$v print-value-COMPONENT_TEST_MASTER) |
|
428 |
COMPONENT_TEST_SNAPSHOT=$(gmake PERL_VERSION=$v print-value-COMPONENT_TEST_SNAPSHOT) |
|
429 |
mkdir -p $(dirname "$COMPONENT_TEST_MASTER") |
|
430 |
touch "$COMPONENT_TEST_MASTER" |
|
431 |
gmake PERL_VERSIONS=$v test > /dev/null 2>&1 |
|
432 |
TEST_RET=$? |
|
433 |
# If there is no snapshot produced the component likely does not support tests |
|
434 |
if [[ ! -f "$COMPONENT_TEST_SNAPSHOT" ]] ; then |
|
435 |
printf "WARNING: test unsupported for %s\n" "$v" >&2 |
|
436 |
rm -f "$COMPONENT_TEST_MASTER" |
|
437 |
rmdir $(dirname "$COMPONENT_TEST_MASTER") |
|
438 |
continue |
|
439 |
fi |
|
440 |
if [[ "$COMPONENT_TEST_MASTER_PREV" != "$COMPONENT_TEST_MASTER" ]] ; then |
|
441 |
[[ -s "$COMPONENT_TEST_SNAPSHOT" ]] || printf "WARNING: 'gmake test' produced empty results for %s\n" "$v" >&2 |
|
442 |
cp -p "$COMPONENT_TEST_SNAPSHOT" "$COMPONENT_TEST_MASTER" |
|
443 |
git add "$COMPONENT_TEST_MASTER" |
|
444 |
COMPONENT_TEST_MASTER_PREV="$COMPONENT_TEST_MASTER" |
|
445 |
gmake PERL_VERSIONS=$v test > /dev/null 2>&1 |
|
446 |
TEST_RET=$? |
|
447 |
fi |
|
448 |
((TEST_RET != 0)) && printf "ERROR: 'gmake test' failed for %s!\n" "$v" >&2 |
|
449 |
done |
dc1665
|
450 |
|
MT |
451 |
|
|
452 |
# Publish packages and create pkg5 file |
b8bb9c
|
453 |
if ! gmake publish > /dev/null 2>&1 ; then |
MT |
454 |
printf "ERROR: 'gmake publish' failed!\n" >&2 |
|
455 |
else |
|
456 |
git add pkg5 |
|
457 |
fi |
dc1665
|
458 |
|
MT |
459 |
|
|
460 |
# Handle history |
|
461 |
COMPONENT_FMRI=$(gmake print-value-COMPONENT_FMRI) |
|
462 |
PERL_VERSIONS_OBSOLETING=$(gmake print-value-PERL_VERSIONS_OBSOLETING) |
|
463 |
OV= |
|
464 |
for o in $(echo $OBSOLETE $PERL_VERSIONS_OBSOLETING | LC_ALL=C sort -u) ; do |
|
465 |
PLV=${o//.} |
|
466 |
FMRI=$(pkg list -avH "$COMPONENT_FMRI-$PLV" 2>/dev/null | egrep -v '(o|r)$' | sed -e 's|^.*\('"$COMPONENT_FMRI"'\)|\1|g' -e 's/:[^:]*$//g' -e 's/\(-[^-]*\)$/,5.11\1/g') |
|
467 |
[[ -n "$FMRI" ]] || continue |
|
468 |
FMRI_H=${FMRI%.*} |
|
469 |
FMRI_T=${FMRI##*.} |
|
470 |
if [[ "$FMRI_H" == "$FMRI" ]] ; then |
c638b3
|
471 |
printf "WARNING: Wrong fmri format: %s\n" "$FMRI" |
dc1665
|
472 |
continue |
MT |
473 |
fi |
|
474 |
FMRI_T=$((FMRI_T + 1)) |
|
475 |
printf "%s.%s\n" "$FMRI_H" "$FMRI_T" >> history |
|
476 |
|
|
477 |
[[ -n "$OV" ]] && OV="$OV and " |
|
478 |
OV="$OV$o" |
|
479 |
done |
|
480 |
if [[ -f history ]] ; then |
|
481 |
LC_ALL=C sort -u history > history.new |
|
482 |
mv history.new history |
|
483 |
git add history |
|
484 |
fi |
|
485 |
|
|
486 |
|
|
487 |
# Construct the commit message |
|
488 |
MSG= |
|
489 |
if ((NEW)) ; then |
|
490 |
MSG="Add $MODULE perl module" |
|
491 |
else |
|
492 |
((REBUILD)) || MSG="update to $VERSION" |
|
493 |
|
|
494 |
NV= |
|
495 |
for v in $PERL_VERSIONS ; do |
|
496 |
PLV=${v//.} |
|
497 |
pkg list -avH "$COMPONENT_FMRI-$PLV" 2>/dev/null | egrep -q -v '(o|r)$' && continue |
|
498 |
[[ -n "$NV" ]] && NV="$NV and " |
|
499 |
NV="$NV$v" |
|
500 |
done |
|
501 |
|
|
502 |
REBUILDMSG= |
|
503 |
[[ -n "$NV" ]] && REBUILDMSG="rebuild for perl $NV" |
|
504 |
if [[ -n "$OV" ]] ; then |
|
505 |
[[ -n "$REBUILDMSG" ]] && REBUILDMSG="$REBUILDMSG and" || REBUILDMSG="rebuild" |
789ea6
|
506 |
REBUILDMSG="$REBUILDMSG to get packages for perl $OV obsoleted" |
dc1665
|
507 |
fi |
MT |
508 |
|
|
509 |
if [[ -n "$REBUILDMSG" ]] ; then |
|
510 |
[[ -n "$MSG" ]] && MSG="$MSG; " |
|
511 |
MSG="$MSG$REBUILDMSG" |
|
512 |
fi |
|
513 |
[[ -z "$MSG" ]] && MSG="rebuild" |
|
514 |
|
|
515 |
MSG="perl/$DISTRIBUTION: $MSG" |
|
516 |
fi |
|
517 |
|
|
518 |
# Commit the results |
c638b3
|
519 |
git commit -m "$MSG" > /dev/null 2>&1 || printf "ERROR: 'git commit' failed!\n" >&2 |