2014-03-05 11:02:37 +01:00
|
|
|
# This hook extracts $distfiles into $XBPS_BUILDDIR if $distfiles and $checksum
|
|
|
|
# variables are set.
|
|
|
|
|
|
|
|
hook() {
|
|
|
|
local srcdir="$XBPS_SRCDISTDIR/$pkgname-$version"
|
2022-11-09 04:36:31 +01:00
|
|
|
local f j curfile found extractdir innerdir innerfile num_dirs
|
2020-01-05 08:20:26 +01:00
|
|
|
local TAR_CMD
|
2014-03-05 11:02:37 +01:00
|
|
|
|
|
|
|
if [ -z "$distfiles" -a -z "$checksum" ]; then
|
2020-09-02 19:04:41 +02:00
|
|
|
mkdir -p "$wrksrc"
|
2014-03-12 10:32:50 +01:00
|
|
|
return 0
|
2014-03-05 11:02:37 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that distfiles are there before anything else.
|
|
|
|
for f in ${distfiles}; do
|
2019-04-13 13:43:07 +02:00
|
|
|
curfile="${f#*>}"
|
|
|
|
curfile="${curfile##*/}"
|
2014-03-05 11:02:37 +01:00
|
|
|
if [ ! -f $srcdir/$curfile ]; then
|
|
|
|
msg_error "$pkgver: cannot find ${curfile}, use 'xbps-src fetch' first.\n"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-01-05 08:24:52 +01:00
|
|
|
# Disable trap on ERR; the code is smart enough to report errors and abort.
|
|
|
|
trap - ERR
|
|
|
|
|
2020-01-05 08:20:26 +01:00
|
|
|
TAR_CMD="$(command -v bsdtar)"
|
|
|
|
[ -z "$TAR_CMD" ] && TAR_CMD="$(command -v tar)"
|
|
|
|
[ -z "$TAR_CMD" ] && msg_error "xbps-src: no suitable tar cmd (bsdtar, tar)\n"
|
|
|
|
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
extractdir=$(mktemp -d "$XBPS_BUILDDIR/.extractdir-XXXXXXX") ||
|
|
|
|
msg_error "Cannot create temporary dir for do-extract\n"
|
|
|
|
|
2014-03-05 11:02:37 +01:00
|
|
|
msg_normal "$pkgver: extracting distfile(s), please wait...\n"
|
|
|
|
|
|
|
|
for f in ${distfiles}; do
|
2019-04-13 13:43:07 +02:00
|
|
|
curfile="${f#*>}"
|
|
|
|
curfile="${curfile##*/}"
|
2014-03-05 11:02:37 +01:00
|
|
|
for j in ${skip_extraction}; do
|
|
|
|
if [ "$curfile" = "$j" ]; then
|
|
|
|
found=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "$found" ]; then
|
|
|
|
unset found
|
|
|
|
continue
|
|
|
|
fi
|
2023-07-11 18:02:44 +02:00
|
|
|
vsrcextract --no-strip-components -C "$extractdir" "$curfile"
|
2014-03-05 11:02:37 +01:00
|
|
|
done
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
|
2023-01-05 03:13:55 +01:00
|
|
|
cd "$extractdir"
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
# find "$extractdir" -mindepth 1 -maxdepth 1 -printf '1\n' | wc -l
|
|
|
|
# However, it requires GNU's find
|
|
|
|
num_dirs=0
|
2023-01-05 03:13:55 +01:00
|
|
|
for f in * .*; do
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
if [ -e "$f" ] || [ -L "$f" ]; then
|
|
|
|
case "$f" in
|
2023-01-05 03:13:55 +01:00
|
|
|
. | ..) ;;
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
*)
|
|
|
|
innerdir="$f"
|
|
|
|
num_dirs=$(( num_dirs + 1 ))
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
2022-11-09 12:54:00 +01:00
|
|
|
# Special case for num_dirs = 2, and it contains metadata
|
|
|
|
if [ "$num_dirs" != 2 ] || [ "$create_wrksrc" ]; then
|
|
|
|
:
|
|
|
|
elif grep -q 'xmlns="http://pear[.]php[.]net/dtd/package' package.xml 2>/dev/null
|
|
|
|
then
|
|
|
|
# PHP modules' metadata
|
|
|
|
rm -f package.xml
|
|
|
|
for f in */; do innerdir="$f"; done
|
|
|
|
num_dirs=1
|
|
|
|
else
|
|
|
|
for f in *; do
|
|
|
|
# AppleDouble encoded Macintosh file
|
|
|
|
if [ -e "$f" ] && [ -e "._$f" ]; then
|
|
|
|
rm -f "._$f"
|
|
|
|
num_dirs=1
|
|
|
|
innerdir="$f"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
rm -rf "$wrksrc"
|
2023-01-05 03:13:55 +01:00
|
|
|
innerdir="$extractdir/$innerdir"
|
|
|
|
cd "$XBPS_BUILDDIR"
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
if [ "$num_dirs" = 1 ] && [ -d "$innerdir" ] && [ -z "$create_wrksrc" ]; then
|
|
|
|
# rename the subdirectory (top-level of distfiles) to $wrksrc
|
|
|
|
mv "$innerdir" "$wrksrc" &&
|
|
|
|
rmdir "$extractdir"
|
|
|
|
else
|
2023-02-27 05:41:57 +01:00
|
|
|
mv "$extractdir" "$wrksrc"
|
hooks: do-extract: extract to temp dir then rename
Extracting to temporary directory then renaming to real $wrksrc,
will make the do-extract steps works atomicity. Either $wrksrc is there
and complete, or it's not there.
Accidentally, this change has a side effect, we can no longer care about
the name of top-level components of a tarball, since we will rename the
top level directory in question to $wrksrc. IOW, we don't need to set
$wrksrc any longer. The side effect of above side effect: we can starting
to build multiple packages that have same top-level's name without clean
from now on.
In another hand, we only rename the inner directory if the extracted
file hierarchy has single top-level directory, we will use the
renamed-temporary directory as the $wrksrc, $create_wrksrc variable is
no longer relevant, and do-clean will always work probably instead of
leaving some trash behind like before.
2021-09-18 16:35:34 +02:00
|
|
|
fi ||
|
|
|
|
msg_error "$pkgver: failed to move sources to $wrksrc\n"
|
2014-03-05 11:02:37 +01:00
|
|
|
}
|