common/hooks: use file for managing provides

python packages use this to automatically generate provides for each
module installed by the package.
This commit is contained in:
classabbyamp 2024-12-03 15:38:14 -05:00 committed by Andrew J. Hesford
parent a4b74b62a1
commit 232221efaf
2 changed files with 32 additions and 1 deletions

View file

@ -0,0 +1,29 @@
# vim: set ts=4 sw=4 et:
#
# This hook executes the following tasks:
# - Generates provides file with provides entries for xbps-create(1)
generate_python_provides() {
local py3_bin="${XBPS_MASTERDIR}/usr/bin/python3"
if [ -z "$nopyprovides" ] && [ -d "${PKGDESTDIR}/${py3_sitelib}" ] && [ -x "${py3_bin}" ]; then
PYTHONPATH="${XBPS_MASTERDIR}/${py3_sitelib}-bootstrap" "${py3_bin}" \
"${XBPS_COMMONDIR}"/scripts/parse-py-metadata.py \
-S "${PKGDESTDIR}/${py3_sitelib}" -v "${pkgver}" provides
fi
}
hook() {
local -a _provides=()
# include explicit values from the template
read -r -a _provides <<< "$provides"
# get the canonical python package names for each python module
mapfile -t _provides -O "${#_provides[@]}" < <( generate_python_provides )
if [ "${#_provides[@]}" -gt 0 ]; then
echo " ${_provides[*]}"
echo "${_provides[*]}" > "${XBPS_STATEDIR}/${pkgname}-provides"
fi
}