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
|
|
|
|
|
2014-03-12 16:43:37 +01:00
|
|
|
case $curfile in
|
|
|
|
*.tar.lzma) cursufx="txz";;
|
2014-03-14 11:04:51 +01:00
|
|
|
*.tar.lz) cursufx="tlz";;
|
|
|
|
*.tlz) cursufx="tlz";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*.tar.xz) cursufx="txz";;
|
|
|
|
*.txz) cursufx="txz";;
|
|
|
|
*.tar.bz2) cursufx="tbz";;
|
|
|
|
*.tbz) cursufx="tbz";;
|
|
|
|
*.tar.gz) cursufx="tgz";;
|
|
|
|
*.tgz) cursufx="tgz";;
|
|
|
|
*.gz) cursufx="gz";;
|
2020-02-11 22:29:57 +01:00
|
|
|
*.xz) cursufx="xz";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*.bz2) cursufx="bz2";;
|
|
|
|
*.tar) cursufx="tar";;
|
|
|
|
*.zip) cursufx="zip";;
|
2014-05-08 18:44:54 +02:00
|
|
|
*.rpm) cursufx="rpm";;
|
2022-11-09 04:36:31 +01:00
|
|
|
*.deb) cursufx="deb";;
|
2015-10-23 19:43:43 +02:00
|
|
|
*.patch) cursufx="txt";;
|
|
|
|
*.diff) cursufx="txt";;
|
|
|
|
*.txt) cursufx="txt";;
|
2020-02-11 22:52:33 +01:00
|
|
|
*.sh) cursufx="txt";;
|
2016-01-11 11:02:44 +01:00
|
|
|
*.7z) cursufx="7z";;
|
2018-10-26 21:39:18 +02:00
|
|
|
*.gem) cursufx="gem";;
|
2018-10-31 22:11:01 +01:00
|
|
|
*.crate) cursufx="crate";;
|
2014-03-12 16:43:37 +01:00
|
|
|
*) msg_error "$pkgver: unknown distfile suffix for $curfile.\n";;
|
|
|
|
esac
|
2014-03-05 11:02:37 +01:00
|
|
|
|
|
|
|
case ${cursufx} in
|
xbps-src: base-chroot-v2 (reduce artifacts/deps)
This patchset contains multiple changes to xbps-src and
its required package "base-chroot" for building packages
via chroot.
- moved xbps.d(5) conf files to `etc/xbps.d`.
- renamed xbps.d(5) repository files to `etc/xbps.d/repos-{local,remote}*`.
- do not set `--repository` to any xbps command that supports it,
xbps-src now simply populates `rootdir/etc/xbps.d` with correct
settings (taking care of CHROOT_READY/IN_CHROOT).
- Unless `-C` is set (to preserve builddir/destdir/autodeps), when
entering to the chroot (if CHROOT_READY is set), xbps-src will
clean up the masterdir and then perform a system update to always
use a constant set of packages for that exact date.
- Improved some normal/error msgs.
- Includes support for `xbps>=0.58`.
- common/hooks: switch to bsdtar.
- base-chroot:
- base-chroot-musl is gone, now unified for glibc/musl.
- deps removed: gettext, mpfr, readline, texinfo, which, xz.
- deps changed: tar -> bsdtar.
Effectively this reduces dependencies in `base-chroot`, makes
it unified for musl and glibc, switches xbps-src to use `bsdtar`
rather than GNU `tar` and `xz`, gets rid of useless host dependencies
like GNU gettext, texinfo, etc.
I've been testing these changes for 1 month or so already,
I was able to build from scratch `base-system` for both native
and multiple targets, i.e `./xbps-src -a target -Nt pkg base-system`
2020-01-01 11:15:35 +01:00
|
|
|
tar|txz|tbz|tlz|tgz|crate)
|
2020-09-02 19:04:41 +02:00
|
|
|
$TAR_CMD -x --no-same-permissions --no-same-owner -f $srcdir/$curfile -C "$extractdir"
|
2014-03-05 11:02:37 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
|
|
|
;;
|
2020-02-11 22:29:57 +01:00
|
|
|
gz|bz2|xz)
|
2020-09-02 19:04:41 +02:00
|
|
|
cp -f $srcdir/$curfile "$extractdir"
|
|
|
|
cd "$extractdir"
|
2020-02-11 22:29:57 +01:00
|
|
|
case ${cursufx} in
|
|
|
|
gz)
|
2022-11-09 04:36:31 +01:00
|
|
|
gunzip -f $curfile
|
2020-02-11 22:29:57 +01:00
|
|
|
;;
|
|
|
|
bz2)
|
|
|
|
bunzip2 -f $curfile
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
unxz -f $curfile
|
|
|
|
;;
|
|
|
|
esac
|
2014-03-05 11:02:37 +01:00
|
|
|
;;
|
|
|
|
zip)
|
2014-05-08 18:44:54 +02:00
|
|
|
if command -v unzip &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
unzip -o -q $srcdir/$curfile -d "$extractdir"
|
2014-03-05 11:02:37 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2020-01-19 20:06:55 +01:00
|
|
|
elif command -v bsdtar &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
bsdtar -xf $srcdir/$curfile -C "$extractdir"
|
2020-01-19 20:06:55 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2014-03-05 11:02:37 +01:00
|
|
|
else
|
2020-01-19 20:06:55 +01:00
|
|
|
msg_error "$pkgver: cannot find unzip or bsdtar bin for extraction.\n"
|
2014-03-05 11:02:37 +01:00
|
|
|
fi
|
|
|
|
;;
|
2014-05-08 18:44:54 +02:00
|
|
|
rpm)
|
2022-11-09 13:36:30 +01:00
|
|
|
if ! command -v bsdtar &>/dev/null; then
|
|
|
|
msg_error "$pkgver: cannot find bsdtar for extraction.\n"
|
|
|
|
fi
|
|
|
|
bsdtar -x --no-same-permissions --no-same-owner -f $srcdir/$curfile -C "$extractdir"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
2014-05-08 18:44:54 +02:00
|
|
|
fi
|
|
|
|
;;
|
2022-11-09 04:36:31 +01:00
|
|
|
deb)
|
|
|
|
if command -v bsdtar &>/dev/null; then
|
|
|
|
bsdtar -x -O -f "$srcdir/$curfile" "data.tar.*" |
|
|
|
|
bsdtar -C "$extractdir" -x --no-same-permissions --no-same-owner
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
msg_error "$pkgver: cannot find bsdtar for extraction.\n"
|
|
|
|
fi
|
|
|
|
;;
|
2015-10-23 19:43:43 +02:00
|
|
|
txt)
|
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
|
|
|
cp -f $srcdir/$curfile "$extractdir"
|
2015-10-23 19:43:43 +02:00
|
|
|
;;
|
2016-01-11 11:02:44 +01:00
|
|
|
7z)
|
|
|
|
if command -v 7z &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
7z x $srcdir/$curfile -o"$extractdir"
|
2016-01-11 11:02:44 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2020-01-19 20:06:55 +01:00
|
|
|
elif command -v bsdtar &>/dev/null; then
|
2020-09-02 19:04:41 +02:00
|
|
|
bsdtar -xf $srcdir/$curfile -C "$extractdir"
|
2020-01-19 20:06:55 +01:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
2016-01-11 11:02:44 +01:00
|
|
|
else
|
2020-01-19 20:06:55 +01:00
|
|
|
msg_error "$pkgver: cannot find 7z or bsdtar bin for extraction.\n"
|
2016-01-11 11:02:44 +01:00
|
|
|
fi
|
|
|
|
;;
|
2018-10-26 21:39:18 +02:00
|
|
|
gem)
|
2021-09-18 16:02:51 +02:00
|
|
|
innerdir="$extractdir/${wrksrc##*/}"
|
|
|
|
mkdir -p "$innerdir"
|
|
|
|
$TAR_CMD -xOf $srcdir/$curfile data.tar.gz |
|
|
|
|
$TAR_CMD -xz -C "$innerdir" -f -
|
2018-10-26 21:39:18 +02:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
msg_error "$pkgver: extracting $curfile into $XBPS_BUILDDIR.\n"
|
|
|
|
fi
|
|
|
|
;;
|
2014-03-05 11:02:37 +01:00
|
|
|
*)
|
|
|
|
msg_error "$pkgver: cannot guess $curfile extract suffix. ($cursufx)\n"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
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
|
|
|
|
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"
|
|
|
|
elif [ "$num_dirs" -gt 1 ] || [ -n "$create_wrksrc" ]; then
|
|
|
|
# rename the tmpdir to wrksrc
|
|
|
|
mv "$extractdir" "$wrksrc"
|
|
|
|
else
|
|
|
|
mkdir -p "$wrksrc"
|
|
|
|
fi ||
|
|
|
|
msg_error "$pkgver: failed to move sources to $wrksrc\n"
|
2014-03-05 11:02:37 +01:00
|
|
|
}
|