2016-04-27 20:16:59 +02:00
|
|
|
# vim: set ts=4 sw=4 et:
|
|
|
|
#
|
2014-02-12 17:26:40 +01:00
|
|
|
# This hook executes the following tasks:
|
2016-04-27 20:16:59 +02:00
|
|
|
# - Generates rdeps file with run-time dependencies for xbps-create(1)
|
|
|
|
# - Generates shlib-requires file for xbps-create(1)
|
2014-02-12 17:26:40 +01:00
|
|
|
|
|
|
|
add_rundep() {
|
2019-07-10 19:48:54 +02:00
|
|
|
local dep="$1" i= rpkgdep= _depname= found=
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
_depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
|
|
|
|
if [ -z "${_depname}" ]; then
|
|
|
|
_depname="$($XBPS_UHELPER_CMD getpkgname ${dep} 2>/dev/null)"
|
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
for i in ${run_depends}; do
|
|
|
|
rpkgdep="$($XBPS_UHELPER_CMD getpkgdepname $i 2>/dev/null)"
|
|
|
|
if [ -z "$rpkgdep" ]; then
|
|
|
|
rpkgdep="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
|
|
|
|
fi
|
|
|
|
if [ "${rpkgdep}" != "${_depname}" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
$XBPS_UHELPER_CMD cmpver "$i" "$dep"
|
|
|
|
rval=$?
|
|
|
|
if [ $rval -eq 255 ]; then
|
|
|
|
run_depends="${run_depends/${i}/${dep}}"
|
|
|
|
fi
|
|
|
|
found=1
|
|
|
|
done
|
|
|
|
if [ -z "$found" ]; then
|
|
|
|
run_depends+=" ${dep}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
store_pkgdestdir_rundeps() {
|
|
|
|
if [ -n "$run_depends" ]; then
|
|
|
|
for f in ${run_depends}; do
|
|
|
|
_curdep="$(echo "$f" | sed -e 's,\(.*\)?.*,\1,')"
|
|
|
|
if [ -z "$($XBPS_UHELPER_CMD getpkgdepname ${_curdep} 2>/dev/null)" -a \
|
|
|
|
-z "$($XBPS_UHELPER_CMD getpkgname ${_curdep} 2>/dev/null)" ]; then
|
|
|
|
_curdep="${_curdep}>=0"
|
|
|
|
fi
|
2024-03-12 20:38:34 +01:00
|
|
|
printf "%s " "${_curdep}"
|
|
|
|
done > "${PKGDESTDIR}/rdeps"
|
2016-04-27 20:16:59 +02:00
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hook() {
|
2022-11-09 09:09:12 +01:00
|
|
|
local depsftmp f lf j mapshlibs sorequires _curdep elfmagic broken_shlibs verify_deps
|
2023-08-09 08:19:01 +02:00
|
|
|
local _shlib_dir="${XBPS_STATEDIR}/shlib-provides"
|
2016-04-27 20:16:59 +02:00
|
|
|
|
|
|
|
# Disable trap on ERR, xbps-uhelper cmd might return error... but not something
|
|
|
|
# to be worried about because if there are broken shlibs this hook returns
|
|
|
|
# error via msg_error().
|
|
|
|
trap - ERR
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
mapshlibs=$XBPS_COMMONDIR/shlibs
|
2014-02-12 18:03:21 +01:00
|
|
|
|
2021-01-20 12:55:11 +01:00
|
|
|
if [ -n "$noverifyrdeps" ]; then
|
2016-04-27 20:16:59 +02:00
|
|
|
store_pkgdestdir_rundeps
|
|
|
|
return 0
|
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2019-06-17 17:38:07 +02:00
|
|
|
depsftmp=$(mktemp) || exit 1
|
2016-04-27 20:16:59 +02:00
|
|
|
find ${PKGDESTDIR} -type f -perm -u+w > $depsftmp 2>/dev/null
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2022-11-09 09:09:12 +01:00
|
|
|
for f in ${shlib_requires}; do
|
|
|
|
verify_deps+=" ${f}"
|
|
|
|
done
|
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
exec 3<&0 # save stdin
|
|
|
|
exec < $depsftmp
|
2023-08-31 14:17:24 +02:00
|
|
|
while read -r f; do
|
2019-02-16 15:09:44 +01:00
|
|
|
lf=${f#${PKGDESTDIR}}
|
2019-07-10 19:48:54 +02:00
|
|
|
if [ "${skiprdeps/${lf}/}" != "${skiprdeps}" ]; then
|
|
|
|
msg_normal "Skipping dependency scan for ${lf}\n"
|
|
|
|
continue
|
|
|
|
fi
|
2021-06-08 16:43:00 +02:00
|
|
|
read -n4 elfmagic < "$f"
|
|
|
|
if [ "$elfmagic" = $'\177ELF' ]; then
|
|
|
|
for nlib in $($OBJDUMP -p "$f"|awk '/NEEDED/{print $2}'); do
|
|
|
|
[ -z "$verify_deps" ] && verify_deps="$nlib" && continue
|
|
|
|
found=0
|
|
|
|
for j in ${verify_deps}; do
|
|
|
|
[[ $j == $nlib ]] && found=1 && break
|
2016-04-27 20:16:59 +02:00
|
|
|
done
|
2021-06-08 16:43:00 +02:00
|
|
|
[[ $found -eq 0 ]] && verify_deps="$verify_deps $nlib"
|
|
|
|
done
|
|
|
|
fi
|
2016-04-27 20:16:59 +02:00
|
|
|
done
|
|
|
|
exec 0<&3 # restore stdin
|
|
|
|
rm -f $depsftmp
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
#
|
|
|
|
# Add required run time packages by using required shlibs resolved
|
2019-07-10 19:48:54 +02:00
|
|
|
# above, the mapping is done thru the common/shlibs file.
|
2016-04-27 20:16:59 +02:00
|
|
|
#
|
|
|
|
for f in ${verify_deps}; do
|
2023-08-09 08:19:01 +02:00
|
|
|
unset _rdep _pkgname _rdepver
|
|
|
|
|
2024-05-16 20:01:59 +02:00
|
|
|
local _findargs="-name"
|
|
|
|
# if SONAME is a path, find should use -wholename
|
|
|
|
if [[ "$f" = */* ]]; then
|
|
|
|
_findargs="-wholename"
|
|
|
|
fi
|
|
|
|
if [ "$(find "${PKGDESTDIR}" $_findargs "$f")" ]; then
|
2016-04-27 20:16:59 +02:00
|
|
|
# Ignore libs by current pkg
|
2023-08-09 08:19:01 +02:00
|
|
|
echo " SONAME: $f <-> $pkgname (ignored)"
|
|
|
|
continue
|
|
|
|
# If this library is provided by a subpkg of sourcepkg, use that subpkg
|
|
|
|
elif _pkgname="$(cd "$_shlib_dir" && grep -F -l -x "$f" *.soname 2>/dev/null)"; then
|
|
|
|
# If that library has SONAME, add it to shlibs-requires, too.
|
|
|
|
_pkgname=${_pkgname%.soname}
|
|
|
|
_sdep="${_pkgname}-${version}_${revision}"
|
|
|
|
sorequires+="${f} "
|
|
|
|
elif _pkgname="$(cd "$_shlib_dir" && grep -F -l -x "$f" *.nosoname 2>/dev/null)"; then
|
|
|
|
_pkgname=${_pkgname%.nosoname}
|
|
|
|
_sdep="${_pkgname}-${version}_${revision}"
|
|
|
|
else
|
|
|
|
_rdep="$(awk -v sl="$f" '$1 == sl { print $2; exit; }' "$mapshlibs")"
|
|
|
|
|
|
|
|
if [ -z "$_rdep" ]; then
|
2016-04-27 20:16:59 +02:00
|
|
|
msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n"
|
2022-11-30 17:11:30 +01:00
|
|
|
broken_shlibs=1
|
2023-08-09 08:19:01 +02:00
|
|
|
continue
|
2016-04-27 20:16:59 +02:00
|
|
|
fi
|
2023-08-09 08:19:01 +02:00
|
|
|
_pkgname=$($XBPS_UHELPER_CMD getpkgname "${_rdep}" 2>/dev/null)
|
|
|
|
_rdepver=$($XBPS_UHELPER_CMD getpkgversion "${_rdep}" 2>/dev/null)
|
|
|
|
if [ -z "${_pkgname}" -o -z "${_rdepver}" ]; then
|
|
|
|
msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n"
|
|
|
|
broken_shlibs=1
|
|
|
|
continue
|
2016-04-27 20:16:59 +02:00
|
|
|
fi
|
2023-08-09 08:19:01 +02:00
|
|
|
_sdep="${_pkgname}>=${_rdepver}"
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2023-08-09 08:19:01 +02:00
|
|
|
# By this point, SONAME can't be found in current pkg
|
2022-05-13 22:13:57 +02:00
|
|
|
sorequires+="${f} "
|
2016-04-27 20:16:59 +02:00
|
|
|
fi
|
2023-08-09 08:19:01 +02:00
|
|
|
echo " SONAME: $f <-> ${_sdep}"
|
2016-04-27 20:16:59 +02:00
|
|
|
add_rundep "${_sdep}"
|
|
|
|
done
|
|
|
|
#
|
|
|
|
# If pkg uses any unknown SONAME error out.
|
|
|
|
#
|
2022-11-30 17:11:30 +01:00
|
|
|
if [ -n "$broken_shlibs" -a -z "$allow_unknown_shlibs" ]; then
|
2016-04-27 20:16:59 +02:00
|
|
|
msg_error "$pkgver: cannot guess required shlibs, aborting!\n"
|
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
store_pkgdestdir_rundeps
|
2014-02-12 17:26:40 +01:00
|
|
|
|
2016-04-27 20:16:59 +02:00
|
|
|
if [ -n "${sorequires}" ]; then
|
2022-05-13 22:13:57 +02:00
|
|
|
echo "${sorequires}" | xargs -n1 | sort | xargs > ${PKGDESTDIR}/shlib-requires
|
2016-04-27 20:16:59 +02:00
|
|
|
fi
|
2014-02-12 17:26:40 +01:00
|
|
|
}
|