diff options
author | Juan RP <xtraeme@gmail.com> | 2014-10-14 17:12:34 +0000 |
---|---|---|
committer | Juan RP <xtraeme@gmail.com> | 2014-10-14 17:19:07 +0000 |
commit | 1cee26a59f66be780297997df838fcde37e47251 (patch) | |
tree | b05fcbf20f5cd5f0eb20f0d298905f05b1007771 /common/hooks/pre-pkg | |
parent | 240f11b8b40a61e03606aa12c430aa97e5b5c8c5 (diff) | |
download | void-packages-1cee26a59f66be780297997df838fcde37e47251.tar void-packages-1cee26a59f66be780297997df838fcde37e47251.tar.gz void-packages-1cee26a59f66be780297997df838fcde37e47251.tar.bz2 void-packages-1cee26a59f66be780297997df838fcde37e47251.tar.lz void-packages-1cee26a59f66be780297997df838fcde37e47251.tar.xz void-packages-1cee26a59f66be780297997df838fcde37e47251.tar.zst void-packages-1cee26a59f66be780297997df838fcde37e47251.zip |
xbps-src: hooks: reorganize some hooks.
The strip-and-debug-pkgs/generate-runtime-deps hooks have been moved
to the pre-pkg stage, and are run before prepare-32bit; this way dependencies
are collected correctly in all cases.
Diffstat (limited to 'common/hooks/pre-pkg')
-rw-r--r-- | common/hooks/pre-pkg/03-strip-and-debug-pkgs.sh | 146 | ||||
-rw-r--r-- | common/hooks/pre-pkg/04-generate-runtime-deps.sh | 170 | ||||
-rw-r--r-- | common/hooks/pre-pkg/05-prepare-32bit.sh (renamed from common/hooks/pre-pkg/02-prepare-32bit.sh) | 0 |
3 files changed, 316 insertions, 0 deletions
diff --git a/common/hooks/pre-pkg/03-strip-and-debug-pkgs.sh b/common/hooks/pre-pkg/03-strip-and-debug-pkgs.sh new file mode 100644 index 00000000000..0dc45a5a2db --- /dev/null +++ b/common/hooks/pre-pkg/03-strip-and-debug-pkgs.sh @@ -0,0 +1,146 @@ +# This hook executes the following tasks: +# - strips ELF binaries/libraries +# - generates -dbg pkgs +# - generates shlib-provides file for xbps-create(8) + +make_debug() { + local dname= fname= dbgfile= + + [ -z "$XBPS_DEBUG_PKGS" -o -n "$disable_debug" -o -n "$nonfree" ] && return 0 + + dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g") + fname="$(basename $1)" + dbgfile="${dname}/${fname}" + + mkdir -p "${PKGDESTDIR}/usr/lib/debug/${dname}" + $OBJCOPY --only-keep-debug --compress-debug-sections \ + "$1" "${PKGDESTDIR}/usr/lib/debug/${dbgfile}" + if [ $? -ne 0 ]; then + msg_red "${pkgver}: failed to create dbg file: ${dbgfile}\n" + return 1 + fi + chmod 644 "${PKGDESTDIR}/usr/lib/debug/${dbgfile}" +} + +attach_debug() { + local dname= fname= dbgfile= + + [ -z "$XBPS_DEBUG_PKGS" -o -n "$disable_debug" -o -n "$nonfree" ] && return 0 + + dname=$(echo "$(dirname $1)"|sed -e "s|${PKGDESTDIR}||g") + fname="$(basename $1)" + dbgfile="${dname}/${fname}" + + $OBJCOPY --add-gnu-debuglink="${PKGDESTDIR}/usr/lib/debug/${dbgfile}" "$1" + if [ $? -ne 0 ]; then + msg_red "${pkgver}: failed to attach dbg to ${dbgfile}\n" + return 1 + fi +} + +create_debug_pkg() { + local _pkgname= _destdir= + + [ -z "$XBPS_DEBUG_PKGS" -o -n "$disable_debug" -o -n "$nonfree" ] && return 0 + [ ! -d "${PKGDESTDIR}/usr/lib/debug" ] && return 0 + + _pkgname="${pkgname}-dbg-${version}" + _destdir="${XBPS_DESTDIR}/${XBPS_CROSS_TRIPLET}/${_pkgname}" + mkdir -p "${_destdir}/usr/lib" + mv ${PKGDESTDIR}/usr/lib/debug ${_destdir}/usr/lib + if [ $? -ne 0 ]; then + msg_red "$pkgver: failed to create debug pkg\n" + return 1 + fi + rmdir --ignore-fail-on-non-empty "${PKGDESTDIR}/usr/lib" 2>/dev/null + return 0 +} + +hook() { + local fname= x= f= _soname= + + if [ -n "$nostrip" -o -n "$noarch" ]; then + return 0 + fi + + find ${PKGDESTDIR} -type f | while read f; do + if [[ $f =~ ^/usr/lib/debug/ ]]; then + continue + fi + + fname=$(basename "$f") + for x in ${nostrip_files}; do + if [ "$x" = "$fname" ]; then + found=1 + break + fi + done + if [ -n "$found" ]; then + unset found + continue + fi + case "$(file -bi "$f")" in + application/x-executable*) + chmod +w "$f" + if echo "$(file $f)" | grep -q "statically linked"; then + # static binary + $STRIP "$f" + if [ $? -ne 0 ]; then + msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n" + return 1 + fi + echo " Stripped static executable: ${f#$PKGDESTDIR}" + else + make_debug "$f" + $STRIP "$f" + if [ $? -ne 0 ]; then + msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n" + return 1 + fi + echo " Stripped executable: ${f#$PKGDESTDIR}" + attach_debug "$f" + fi + ;; + application/x-sharedlib*) + chmod +w "$f" + # shared library + make_debug "$f" + $STRIP --strip-unneeded "$f" + if [ $? -ne 0 ]; then + msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n" + return 1 + fi + echo " Stripped library: ${f#$PKGDESTDIR}" + _soname=$(${OBJDUMP} -p "$f"|grep SONAME|awk '{print $2}') + pattern="^[[:alnum:]]+(.*)+\.so(\.[0-9]+)*$" + if [[ ${_soname} =~ $pattern ]]; then + if [ ! -e ${PKGDESTDIR}/usr/lib/${fname} ]; then + continue + fi + echo "${_soname}" >> ${PKGDESTDIR}/.shlib-provides + fi + attach_debug "$f" + ;; + application/x-archive*) + chmod +w "$f" + $STRIP --strip-debug "$f" + if [ $? -ne 0 ]; then + msg_red "$pkgver: failed to strip ${f#$PKGDESTDIR}\n" + return 1 + fi + echo " Stripped static library: ${f#$PKGDESTDIR}";; + esac + done + + for f in ${shlib_provides}; do + echo "$f" >> ${PKGDESTDIR}/.shlib-provides + done + if [ -s "$PKGDESTDIR/.shlib-provides" ]; then + cat $PKGDESTDIR/.shlib-provides | tr '\n' ' ' > $PKGDESTDIR/shlib-provides + echo >> $PKGDESTDIR/shlib-provides + rm -f $PKGDESTDIR/.shlib-provides + fi + + create_debug_pkg + return $? +} diff --git a/common/hooks/pre-pkg/04-generate-runtime-deps.sh b/common/hooks/pre-pkg/04-generate-runtime-deps.sh new file mode 100644 index 00000000000..9a6cc592e4c --- /dev/null +++ b/common/hooks/pre-pkg/04-generate-runtime-deps.sh @@ -0,0 +1,170 @@ +# This hook executes the following tasks: +# - Generates rdeps file with run-time dependencies for xbps-create(8) +# - Generates shlib-requires file for xbps-create(8) + +add_rundep() { + local dep="$1" i= rpkgdep= _depname= _rdeps= found= + + _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)" + if [ -z "${_depname}" ]; then + _depname="$($XBPS_UHELPER_CMD getpkgname ${dep} 2>/dev/null)" + fi + + 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 +} + +hook() { + local depsftmp f j tmplf mapshlibs sorequires + + # 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 + + mapshlibs=$XBPS_COMMONDIR/shlibs + tmplf=$XBPS_SRCPKGDIR/$pkgname/template + + if [ -n "$noarch" -o -n "$noverifyrdeps" ]; then + echo "$run_depends" > ${PKGDESTDIR}/rdeps + sed 's,virtual?,,g' -i ${PKGDESTDIR}/rdeps + return 0 + fi + + depsftmp=$(mktemp -t xbps_src_depstmp.XXXXXXXXXX) || return 1 + find ${PKGDESTDIR} -type f -perm -u+w > $depsftmp 2>/dev/null + + exec 3<&0 # save stdin + exec < $depsftmp + while read f; do + case "$(file -bi "$f")" in + application/x-executable*|application/x-sharedlib*) + for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do + if [ -z "$verify_deps" ]; then + verify_deps="$nlib" + continue + fi + for j in ${verify_deps}; do + [ "$j" != "$nlib" ] && continue + found_dup=1 + break + done + if [ -z "$found_dup" ]; then + verify_deps="$verify_deps $nlib" + fi + unset found_dup + done + ;; + esac + done + exec 0<&3 # restore stdin + rm -f $depsftmp + + # + # Add required run time packages by using required shlibs resolved + # above, the mapping is done thru the mapping_shlib_binpkg.txt file. + # + for f in ${verify_deps}; do + unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found + _f=$(echo "$f"|sed -E 's|\+|\\+|g') + rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')" + rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)" + if [ -z "$rdep" ]; then + # Ignore libs by current pkg + soname=$(find ${PKGDESTDIR} -name "$f") + if [ -z "$soname" ]; then + msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n" + broken=1 + else + echo " SONAME: $f <-> $pkgname (ignored)" + fi + continue + elif [ "$rdepcnt" -gt 1 ]; then + unset j found + # Check if shlib is provided by multiple pkgs. + for j in ${rdep}; do + _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j") + # if there's a SONAME matching pkgname, use it. + for x in ${pkgname} ${subpackages}; do + if [ "${_pkgname}" = "${x}" ]; then + found=1 + break + fi + done + if [ -n "$found" ]; then + _rdep=$j + break + fi + done + if [ -z "${_rdep}" ]; then + # otherwise pick up the first one. + for j in ${rdep}; do + [ -z "${_rdep}" ] && _rdep=$j + done + fi + else + _rdep=$rdep + fi + _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=1 + continue + fi + # Check if pkg is a subpkg of sourcepkg; if true, ignore version + # in common/shlibs. + _sdep="${_pkgname}>=${_rdepver}" + for _subpkg in ${subpackages}; do + if [ "${_subpkg}" = "${_pkgname}" ]; then + _sdep="${_pkgname}-${version}_${revision}" + break + fi + done + + if [ "${_pkgname}" != "${pkgname}" ]; then + echo " SONAME: $f <-> ${_sdep}" + sorequires+="${f} " + else + # Ignore libs by current pkg + echo " SONAME: $f <-> ${_rdep} (ignored)" + continue + fi + add_rundep "${_sdep}" + done + # + # If pkg uses any unknown SONAME error out. + # + if [ -n "$broken" -a -z "$allow_unknown_shlibs" ]; then + msg_error "$pkgver: cannot guess required shlibs, aborting!\n" + fi + + if [ -n "$run_depends" ]; then + echo "$run_depends" > ${PKGDESTDIR}/rdeps + fi + if [ -s ${PKGDESTDIR}/rdeps ]; then + sed 's,virtual?,,g' -i ${PKGDESTDIR}/rdeps + fi + for f in ${shlib_requires}; do + sorequires+="${f} " + done + if [ -n "${sorequires}" ]; then + echo "${sorequires}" > ${PKGDESTDIR}/shlib-requires + fi +} diff --git a/common/hooks/pre-pkg/02-prepare-32bit.sh b/common/hooks/pre-pkg/05-prepare-32bit.sh index 106a0f380d4..106a0f380d4 100644 --- a/common/hooks/pre-pkg/02-prepare-32bit.sh +++ b/common/hooks/pre-pkg/05-prepare-32bit.sh |