xbps-src: re-introduce etc/virtual.

The `etc/virtual` file declares the default package to be built for
virtual dependencies declared as "virtual?foo" in $depends.

Before this change, the run-time dependency was added as is to the final
binary package but no pkg providing this virtual pkg was built.

With this file we declare the *default* pkg to be built.

NOTE: "virtual?foo" is only applicable to *run* time dependencies, i.e
only those declared in $depends.
This commit is contained in:
Juan RP 2016-04-27 20:16:59 +02:00
parent 78c601e18e
commit d2bac19750
4 changed files with 248 additions and 173 deletions

View file

@ -118,6 +118,14 @@ Native and cross compiler/linker flags are set per architecture in `common/build
and `common/cross-profiles` respectively. Ideally those settings are good enough by default, and `common/cross-profiles` respectively. Ideally those settings are good enough by default,
and there's no need to set your own unless you know what you are doing. and there's no need to set your own unless you know what you are doing.
#### Virtual packages
The `etc/defaults.virtual` file contains the default replacements for virtual packages,
used as dependencies in the source packages tree.
If you want to customize those replacements, copy `etc/defaults.virtual` to `etc/virtual`
and edit it accordingly to your needs.
### Directory hierarchy ### Directory hierarchy
The following directory hierarchy is used with a default configuration file: The following directory hierarchy is used with a default configuration file:

View file

@ -1,170 +1,181 @@
# vim: set ts=4 sw=4 et:
#
# This hook executes the following tasks: # This hook executes the following tasks:
# - Generates rdeps file with run-time dependencies for xbps-create(8) # - Generates rdeps file with run-time dependencies for xbps-create(1)
# - Generates shlib-requires file for xbps-create(8) # - Generates shlib-requires file for xbps-create(1)
add_rundep() { add_rundep() {
local dep="$1" i= rpkgdep= _depname= _rdeps= found= local dep="$1" i= rpkgdep= _depname= _rdeps= found=
_depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)" _depname="$($XBPS_UHELPER_CMD getpkgdepname ${dep} 2>/dev/null)"
if [ -z "${_depname}" ]; then if [ -z "${_depname}" ]; then
_depname="$($XBPS_UHELPER_CMD getpkgname ${dep} 2>/dev/null)" _depname="$($XBPS_UHELPER_CMD getpkgname ${dep} 2>/dev/null)"
fi fi
for i in ${run_depends}; do for i in ${run_depends}; do
rpkgdep="$($XBPS_UHELPER_CMD getpkgdepname $i 2>/dev/null)" rpkgdep="$($XBPS_UHELPER_CMD getpkgdepname $i 2>/dev/null)"
if [ -z "$rpkgdep" ]; then if [ -z "$rpkgdep" ]; then
rpkgdep="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)" rpkgdep="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
fi fi
if [ "${rpkgdep}" != "${_depname}" ]; then if [ "${rpkgdep}" != "${_depname}" ]; then
continue continue
fi fi
$XBPS_UHELPER_CMD cmpver "$i" "$dep" $XBPS_UHELPER_CMD cmpver "$i" "$dep"
rval=$? rval=$?
if [ $rval -eq 255 ]; then if [ $rval -eq 255 ]; then
run_depends="${run_depends/${i}/${dep}}" run_depends="${run_depends/${i}/${dep}}"
fi fi
found=1 found=1
done done
if [ -z "$found" ]; then if [ -z "$found" ]; then
run_depends+=" ${dep}" run_depends+=" ${dep}"
fi fi
}
store_pkgdestdir_rundeps() {
if [ -n "$run_depends" ]; then
: > ${PKGDESTDIR}/rdeps
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
printf "${_curdep} " >> ${PKGDESTDIR}/rdeps
done
fi
} }
hook() { hook() {
local depsftmp f j tmplf mapshlibs sorequires local depsftmp f j tmplf mapshlibs sorequires _curdep
# Disable trap on ERR, xbps-uhelper cmd might return error... but not something # 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 # to be worried about because if there are broken shlibs this hook returns
# error via msg_error(). # error via msg_error().
trap - ERR trap - ERR
mapshlibs=$XBPS_COMMONDIR/shlibs mapshlibs=$XBPS_COMMONDIR/shlibs
tmplf=$XBPS_SRCPKGDIR/$pkgname/template tmplf=$XBPS_SRCPKGDIR/$pkgname/template
if [ -n "$noarch" -o -n "$noverifyrdeps" ]; then if [ -n "$noarch" -o -n "$noverifyrdeps" ]; then
echo "$run_depends" > ${PKGDESTDIR}/rdeps store_pkgdestdir_rundeps
sed 's,virtual?,,g' -i ${PKGDESTDIR}/rdeps return 0
return 0 fi
fi
depsftmp=$(mktemp -t xbps_src_depstmp.XXXXXXXXXX) || return 1 depsftmp=$(mktemp -t xbps_src_depstmp.XXXXXXXXXX) || return 1
find ${PKGDESTDIR} -type f -perm -u+w > $depsftmp 2>/dev/null find ${PKGDESTDIR} -type f -perm -u+w > $depsftmp 2>/dev/null
exec 3<&0 # save stdin exec 3<&0 # save stdin
exec < $depsftmp exec < $depsftmp
while read f; do while read f; do
case "$(file -bi "$f")" in case "$(file -bi "$f")" in
application/x-executable*|application/x-sharedlib*) application/x-executable*|application/x-sharedlib*)
for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do for nlib in $($OBJDUMP -p "$f"|grep NEEDED|awk '{print $2}'); do
if [ -z "$verify_deps" ]; then if [ -z "$verify_deps" ]; then
verify_deps="$nlib" verify_deps="$nlib"
continue continue
fi fi
for j in ${verify_deps}; do for j in ${verify_deps}; do
[ "$j" != "$nlib" ] && continue [ "$j" != "$nlib" ] && continue
found_dup=1 found_dup=1
break break
done done
if [ -z "$found_dup" ]; then if [ -z "$found_dup" ]; then
verify_deps="$verify_deps $nlib" verify_deps="$verify_deps $nlib"
fi fi
unset found_dup unset found_dup
done done
;; ;;
esac esac
done done
exec 0<&3 # restore stdin exec 0<&3 # restore stdin
rm -f $depsftmp rm -f $depsftmp
# #
# Add required run time packages by using required shlibs resolved # Add required run time packages by using required shlibs resolved
# above, the mapping is done thru the mapping_shlib_binpkg.txt file. # above, the mapping is done thru the mapping_shlib_binpkg.txt file.
# #
for f in ${verify_deps}; do for f in ${verify_deps}; do
unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found unset _f j rdep _rdep rdepcnt soname _pkgname _rdepver found
_f=$(echo "$f"|sed -E 's|\+|\\+|g') _f=$(echo "$f"|sed -E 's|\+|\\+|g')
rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')" rdep="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}')"
rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)" rdepcnt="$(grep -E "^${_f}[[:blank:]]+.*$" $mapshlibs|awk '{print $2}'|wc -l)"
if [ -z "$rdep" ]; then if [ -z "$rdep" ]; then
# Ignore libs by current pkg # Ignore libs by current pkg
soname=$(find ${PKGDESTDIR} -name "$f") soname=$(find ${PKGDESTDIR} -name "$f")
if [ -z "$soname" ]; then if [ -z "$soname" ]; then
msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n" msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n"
broken=1 broken=1
else else
echo " SONAME: $f <-> $pkgname (ignored)" echo " SONAME: $f <-> $pkgname (ignored)"
fi fi
continue continue
elif [ "$rdepcnt" -gt 1 ]; then elif [ "$rdepcnt" -gt 1 ]; then
unset j found unset j found
# Check if shlib is provided by multiple pkgs. # Check if shlib is provided by multiple pkgs.
for j in ${rdep}; do for j in ${rdep}; do
_pkgname=$($XBPS_UHELPER_CMD getpkgname "$j") _pkgname=$($XBPS_UHELPER_CMD getpkgname "$j")
# if there's a SONAME matching pkgname, use it. # if there's a SONAME matching pkgname, use it.
for x in ${pkgname} ${subpackages}; do for x in ${pkgname} ${subpackages}; do
if [ "${_pkgname}" = "${x}" ]; then if [ "${_pkgname}" = "${x}" ]; then
found=1 found=1
break break
fi fi
done done
if [ -n "$found" ]; then if [ -n "$found" ]; then
_rdep=$j _rdep=$j
break break
fi fi
done done
if [ -z "${_rdep}" ]; then if [ -z "${_rdep}" ]; then
# otherwise pick up the first one. # otherwise pick up the first one.
for j in ${rdep}; do for j in ${rdep}; do
[ -z "${_rdep}" ] && _rdep=$j [ -z "${_rdep}" ] && _rdep=$j
done done
fi fi
else else
_rdep=$rdep _rdep=$rdep
fi fi
_pkgname=$($XBPS_UHELPER_CMD getpkgname "${_rdep}" 2>/dev/null) _pkgname=$($XBPS_UHELPER_CMD getpkgname "${_rdep}" 2>/dev/null)
_rdepver=$($XBPS_UHELPER_CMD getpkgversion "${_rdep}" 2>/dev/null) _rdepver=$($XBPS_UHELPER_CMD getpkgversion "${_rdep}" 2>/dev/null)
if [ -z "${_pkgname}" -o -z "${_rdepver}" ]; then if [ -z "${_pkgname}" -o -z "${_rdepver}" ]; then
msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n" msg_red_nochroot " SONAME: $f <-> UNKNOWN PKG PLEASE FIX!\n"
broken=1 broken=1
continue continue
fi fi
# Check if pkg is a subpkg of sourcepkg; if true, ignore version # Check if pkg is a subpkg of sourcepkg; if true, ignore version
# in common/shlibs. # in common/shlibs.
_sdep="${_pkgname}>=${_rdepver}" _sdep="${_pkgname}>=${_rdepver}"
for _subpkg in ${subpackages}; do for _subpkg in ${subpackages}; do
if [ "${_subpkg}" = "${_pkgname}" ]; then if [ "${_subpkg}" = "${_pkgname}" ]; then
_sdep="${_pkgname}-${version}_${revision}" _sdep="${_pkgname}-${version}_${revision}"
break break
fi fi
done done
if [ "${_pkgname}" != "${pkgname}" ]; then if [ "${_pkgname}" != "${pkgname}" ]; then
echo " SONAME: $f <-> ${_sdep}" echo " SONAME: $f <-> ${_sdep}"
sorequires+="${f} " sorequires+="${f} "
else else
# Ignore libs by current pkg # Ignore libs by current pkg
echo " SONAME: $f <-> ${_rdep} (ignored)" echo " SONAME: $f <-> ${_rdep} (ignored)"
continue continue
fi fi
add_rundep "${_sdep}" add_rundep "${_sdep}"
done done
# #
# If pkg uses any unknown SONAME error out. # If pkg uses any unknown SONAME error out.
# #
if [ -n "$broken" -a -z "$allow_unknown_shlibs" ]; then if [ -n "$broken" -a -z "$allow_unknown_shlibs" ]; then
msg_error "$pkgver: cannot guess required shlibs, aborting!\n" msg_error "$pkgver: cannot guess required shlibs, aborting!\n"
fi fi
if [ -n "$run_depends" ]; then store_pkgdestdir_rundeps
echo "$run_depends" > ${PKGDESTDIR}/rdeps
fi for f in ${shlib_requires}; do
if [ -s ${PKGDESTDIR}/rdeps ]; then sorequires+="${f} "
sed 's,virtual?,,g' -i ${PKGDESTDIR}/rdeps done
fi if [ -n "${sorequires}" ]; then
for f in ${shlib_requires}; do echo "${sorequires}" > ${PKGDESTDIR}/shlib-requires
sorequires+="${f} " fi
done
if [ -n "${sorequires}" ]; then
echo "${sorequires}" > ${PKGDESTDIR}/shlib-requires
fi
} }

View file

@ -17,15 +17,30 @@ setup_pkg_depends() {
if [ -z "${_pkgdepname}" ]; then if [ -z "${_pkgdepname}" ]; then
_pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)" _pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_depname} 2>/dev/null)"
fi fi
if [ -z "${_pkgdepname}" ]; then if [ -s ${XBPS_DISTDIR}/etc/virtual ]; then
_pkgdep="${_depname}>=0" _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/virtual|cut -d ' ' -f2)
else elif [ -s ${XBPS_DISTDIR}/etc/defaults.virtual ]; then
_pkgdep="${_depname}" _replacement=$(egrep "^${_pkgdepname:-${_depname}}[[:blank:]]" ${XBPS_DISTDIR}/etc/defaults.virtual|cut -d ' ' -f2)
fi fi
if [ "${_rpkgname}" = "virtual" ]; then if [ "${_rpkgname}" = "virtual" ]; then
run_depends+=" virtual?${_pkgdep}" if [ -z "${_replacement}" ]; then
msg_error "$pkgver: failed to resolve virtual dependency for '$j' (missing from etc/virtual)\n"
fi
_pkgdepname="$($XBPS_UHELPER_CMD getpkgdepname ${_replacement} 2>/dev/null)"
if [ -z "${_pkgdepname}" ]; then
_pkgdepname="$($XBPS_UHELPER_CMD getpkgname ${_replacement} 2>/dev/null)"
fi
if [ -z "${_pkgdepname}" ]; then
_pkgdepname="${_replacement}>=0"
fi
run_depends+=" ${_depname}?${_pkgdepname}"
#echo "Adding dependency virtual: ${_depname}?${_pkgdepname}"
else else
if [ -z "${_pkgdepname}" ]; then
_pkgdep="${_depname}>=0"
else
_pkgdep="${_depname}"
fi
run_depends+=" ${_pkgdep}" run_depends+=" ${_pkgdep}"
fi fi
done done
@ -144,9 +159,9 @@ srcpkg_get_version() {
local pkg="$1" local pkg="$1"
# Run this in a sub-shell to avoid polluting our env. # Run this in a sub-shell to avoid polluting our env.
( (
unset XBPS_BINPKG_EXISTS unset XBPS_BINPKG_EXISTS
setup_pkg $pkg || exit $? setup_pkg $pkg || exit $?
echo "${version}_${revision}" echo "${version}_${revision}"
) || msg_error "$pkgver: failed to transform dependency $pkg\n" ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
} }
@ -154,9 +169,9 @@ srcpkg_get_pkgver() {
local pkg="$1" local pkg="$1"
# Run this in a sub-shell to avoid polluting our env. # Run this in a sub-shell to avoid polluting our env.
( (
unset XBPS_BINPKG_EXISTS unset XBPS_BINPKG_EXISTS
setup_pkg $pkg || exit $? setup_pkg $pkg || exit $?
echo "${sourcepkg}-${version}_${revision}" echo "${sourcepkg}-${version}_${revision}"
) || msg_error "$pkgver: failed to transform dependency $pkg\n" ) || msg_error "$pkgver: failed to transform dependency $pkg\n"
} }
@ -165,7 +180,7 @@ srcpkg_get_pkgver() {
# #
install_pkg_deps() { install_pkg_deps() {
local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5" local pkg="$1" targetpkg="$2" target="$3" cross="$4" cross_prepare="$5"
local rval _realpkg curpkgdepname pkgn iver local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
local i j found rundep repo local i j found rundep repo
local -a host_binpkg_deps binpkg_deps host_missing_deps missing_deps missing_rdeps local -a host_binpkg_deps binpkg_deps host_missing_deps missing_deps missing_rdeps
@ -259,10 +274,12 @@ install_pkg_deps() {
# #
for i in ${run_depends}; do for i in ${run_depends}; do
_realpkg="${i%\?*}" _realpkg="${i%\?*}"
if [ "${_realpkg}" = "virtual" ]; then _curpkg="${_realpkg}"
# ignore virtual dependencies _vpkg="${i#*\?}"
echo " [runtime] ${i#*\?}: virtual dependency." if [ "${_realpkg}" != "${_vpkg}" ]; then
continue _realpkg="${_vpkg}"
else
unset _curpkg
fi fi
pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}") pkgn=$($XBPS_UHELPER_CMD getpkgdepname "${_realpkg}")
if [ -z "$pkgn" ]; then if [ -z "$pkgn" ]; then
@ -282,15 +299,27 @@ install_pkg_deps() {
set -- ${_props} set -- ${_props}
$XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}" $XBPS_UHELPER_CMD pkgmatch ${1} "${_realpkg}"
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
echo " [runtime] ${_realpkg}: found ($2)" if [ -n "${_curpkg}" ]; then
echo " [runtime] ${_curpkg}:${_realpkg} (virtual dependency): found $1 ($2)"
else
echo " [runtime] ${_realpkg}: found $1 ($2)"
fi
shift 2 shift 2
continue continue
else else
echo " [runtime] ${_realpkg}: not found." if [ -n "${_curpkg}" ]; then
echo " [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
else
echo " [runtime] ${_realpkg}: not found."
fi
fi fi
shift 2 shift 2
else else
echo " [runtime] ${_realpkg}: not found." if [ -n "${_curpkg}" ]; then
echo " [runtime] ${_curpkg}:${_realpkg} (virtual dependency): not found."
else
echo " [runtime] ${_realpkg}: not found."
fi
fi fi
missing_rdeps+=("${_realpkg}") missing_rdeps+=("${_realpkg}")
done done

27
etc/defaults.virtual Normal file
View file

@ -0,0 +1,27 @@
# --*-- shell --*--
#
# etc/defaults.virtual
# default configuration of etc/virtual
#
# DO NOT EDIT THIS FILE DIRECTLY; IT MAY BE REPLACED DURING UPDATES,
# EDIT etc/virtual INSTEAD.
#
# This file specifies a mapping between virtual packages and real packages
# available in the source packages collection (srcpkgs).
#
# The format uses 2 arguments delimited by a blank: <vpkgname> <realpkgname>
#
# When building a package with "xbps-src", those dependencies declared like
# "virtual?foo" will use the replacement package defined in `etc/virtual`.
#
# NOTE: this mapping is only there to be able to build a default package
# to resolve the virtual package dependency later on with xbps-install(1).
#
# NOTE: Create your own etc/virtual file to override these defaults.
awk gawk
java-environment openjdk
java-runtime openjdk-jre
ntp-daemon chrony
xserver-abi-input xorg-server
xserver-abi-video xorg-server