common/hooks: add support for do-<phase> hooks as suggested by Gottox.

- New hooks for do-fetch and do-extract moved from xbps-src.
- Renamed some hooks to have XX as prefix.
This commit is contained in:
Juan RP 2014-03-05 11:02:37 +01:00
parent a62171bb16
commit aa83852d7b
13 changed files with 243 additions and 0 deletions

View File

@ -13,18 +13,40 @@ The following directories are used to set the order in which the hooks
should be processed by xbps-src:
* pre-fetch (before running fetch phase)
* do-fetch (running fetch phase)
* post-fetch (after running fetch phase)
* pre-extract (before running extract phase)
* do-extract (running extract phase)
* post-extract (after running extract phase)
* pre-configure (before running configure phase)
* do-configure (running configure phase)
* post-configure (after running configure phase)
* pre-build (before running build phase)
* do-build (running build phase)
* post-build (after running build phase)
* pre-install (before running install phase)
* do-install (running install phase)
* post-install (after running install phase)
* pre-pkg (before running pkg phase)
* do-pkg (running pkg phase)
* post-pkg (after running pkg phase)
NOTES
~~~~~
* Symlinks can be created (relative) to make a hook available in multiple phases.
* The phases do-fetch, do-extract, do-configure, do-build, and do-install can
be overwritten by the template file. That means if a template contains a
do_install function, the hooks defined for do-install won't be executed.
Note that this is only true for the do-* hooks.
* the pre_* function of the template will be run *after* the corresponding
pre-* hooks.
* the post_* function of the template will be run *before* the corresponding
post-* hooks.

View File

View File

View File

View File

@ -0,0 +1,119 @@
# This hook extracts $distfiles into $XBPS_BUILDDIR if $distfiles and $checksum
# variables are set.
hook() {
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
if [ -z "$distfiles" -a -z "$checksum" ]; then
mkdir -p $wrksrc
exit 0
fi
# Check that distfiles are there before anything else.
for f in ${distfiles}; do
curfile=$(basename $f)
if [ ! -f $srcdir/$curfile ]; then
msg_error "$pkgver: cannot find ${curfile}, use 'xbps-src fetch' first.\n"
fi
done
if [ -n "$create_wrksrc" ]; then
mkdir -p ${wrksrc} || msg_error "$pkgver: failed to create wrksrc.\n"
fi
msg_normal "$pkgver: extracting distfile(s), please wait...\n"
for f in ${distfiles}; do
curfile=$(basename $f)
for j in ${skip_extraction}; do
if [ "$curfile" = "$j" ]; then
found=1
break
fi
done
if [ -n "$found" ]; then
unset found
continue
fi
if $(echo $f|grep -q '.tar.lzma'); then
cursufx="txz"
elif $(echo $f|grep -q '.tar.xz'); then
cursufx="txz"
elif $(echo $f|grep -q '.txz'); then
cursufx="txz"
elif $(echo $f|grep -q '.tar.bz2'); then
cursufx="tbz"
elif $(echo $f|grep -q '.tbz'); then
cursufx="tbz"
elif $(echo $f|grep -q '.tar.gz'); then
cursufx="tgz"
elif $(echo $f|grep -q '.tgz'); then
cursufx="tgz"
elif $(echo $f|grep -q '.gz'); then
cursufx="gz"
elif $(echo $f|grep -q '.bz2'); then
cursufx="bz2"
elif $(echo $f|grep -q '.tar'); then
cursufx="tar"
elif $(echo $f|grep -q '.zip'); then
cursufx="zip"
else
msg_error "$pkgver: unknown distfile suffix for $curfile.\n"
fi
if [ -n "$create_wrksrc" ]; then
extractdir="$wrksrc"
else
extractdir="$XBPS_BUILDDIR"
fi
case ${cursufx} in
txz)
unxz -cf $srcdir/$curfile | tar xf - -C $extractdir
if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi
;;
tbz)
bunzip2 -cf $srcdir/$curfile | tar xf - -C $extractdir
if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi
;;
tgz)
gunzip -cf $srcdir/$curfile | tar xf - -C $extractdir
if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi
;;
gz|bz2)
cp -f $srcdir/$curfile $extractdir
if [ "$cursufx" = ".gz" ]; then
cd $extractdir && gunzip $curfile
else
cd $extractdir && bunzip2 $curfile
fi
;;
tar)
tar xf $srcdir/$curfile -C $extractdir
if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi
;;
zip)
if command -v unzip 2>&1 >/dev/null; then
unzip -q $srcdir/$curfile -d $extractdir
if [ $? -ne 0 ]; then
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
fi
else
msg_error "$pkgver: cannot find unzip bin for extraction.\n"
fi
;;
*)
msg_error "$pkgver: cannot guess $curfile extract suffix. ($cursufx)\n"
;;
esac
done
}

View File

View File

@ -0,0 +1,102 @@
# This hook downloads the distfiles specified in a template by
# the $distfiles variable and then verifies its sha256 checksum comparing
# its value with the one stored in the $checksum variable.
verify_sha256_cksum() {
local file="$1" origsum="$2" distfile="$3"
[ -z "$file" -o -z "$cksum" ] && return 1
msg_normal "$pkgver: verifying checksum for distfile '$file'... "
filesum=$(${XBPS_DIGEST_CMD} $distfile)
if [ "$origsum" != "$filesum" ]; then
echo
msg_red "SHA256 mismatch for '$file:'\n$filesum\n"
return 1
else
msg_normal_append "OK.\n"
fi
}
hook() {
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
if [ ! -d "$srcdir" ]; then
mkdir -p -m775 "$srcdir"
chgrp $(id -g) "$srcdir"
fi
cd $srcdir || msg_error "$pkgver: cannot change dir to $srcdir!\n"
for f in ${distfiles}; do
curfile=$(basename $f)
distfile="$srcdir/$curfile"
while true; do
flock -w 1 ${distfile}.part true
if [ $? -eq 0 ]; then
break
fi
msg_warn "$pkgver: ${distfile} is being already downloaded, waiting for 1s ...\n"
done
if [ -f "$distfile" ]; then
flock -n ${distfile}.part rm -f ${distfile}.part
for i in ${checksum}; do
if [ $dfcount -eq $ckcount -a -n "$i" ]; then
cksum=$i
found=yes
break
fi
ckcount=$(($ckcount + 1))
done
if [ -z $found ]; then
msg_error "$pkgver: cannot find checksum for $curfile.\n"
fi
verify_sha256_cksum $curfile $cksum $distfile
rval=$?
unset cksum found
ckcount=0
dfcount=$(($dfcount + 1))
continue
fi
msg_normal "$pkgver: fetching distfile '$curfile'...\n"
if [ -n "$distfiles" ]; then
localurl="$f"
else
localurl="$url/$curfile"
fi
flock ${distfile}.part $XBPS_FETCH_CMD $localurl
if [ $? -ne 0 ]; then
unset localurl
if [ ! -f $distfile ]; then
msg_error "$pkgver: couldn't fetch $curfile.\n"
else
msg_error "$pkgver: there was an error fetching $curfile.\n"
fi
else
unset localurl
#
# XXX duplicate code.
#
for i in ${checksum}; do
if [ $dfcount -eq $ckcount -a -n "$i" ]; then
cksum=$i
found=yes
break
fi
ckcount=$(($ckcount + 1))
done
if [ -z $found ]; then
msg_error "$pkgver: cannot find checksum for $curfile.\n"
fi
verify_sha256_cksum $curfile $cksum $distfile
rval=$?
unset cksum found
ckcount=0
fi
dfcount=$(($dfcount + 1))
done
}

View File

View File