xbps-src: implement a 'check' stage

Add another stage 'check' between 'build' and 'install'. It is be enabled using the
variable XBPS_CHECK_PKGS=yes and disabled if unset, set to "0" or "no" in your
local etc/conf.

A new xbps-src option `-q` for `quick` will disable XBPS_CHECK_PKGS by overriding it to 0.
If enabled, `common/xbps-src/shutils/xbps-src-docheck.sh` checks for an existing
`do_check()` function in the package's template and, if it exists, calls it.

A new template variable `checkdepends` may be present and list packages required
to run the `do_check()` function. Example: `checkdepends="bc unittest-cpp"`.
This commit is contained in:
Jürgen Buchmüller 2017-02-23 22:03:31 +01:00
parent f9dface61c
commit c31dd888f6
14 changed files with 156 additions and 13 deletions

View file

@ -121,6 +121,8 @@ function, which is the directory to be used to compile the `source package`.
- `build` This phase compiles/prepares the `source files` via `make` or any other compatible method.
- `check` This optional phase checks the result of the `build` phase for example by running `make -k check`.
- `install` This phase installs the `package files` into the package destdir `<masterdir>/destdir/<pkgname>-<version>`,
via `make install` or any other compatible method.
@ -359,6 +361,10 @@ will be installed to the master directory. There is no need to specify a version
because the current version in srcpkgs will always be required.
Example `makedepends="foo blah"`.
- `checkdepends` The list of dependencies required to run the package checks, i.e.
the script or make rule specified in the template's `do_check()` function.
Example `checkdepends="gtest"`.
- `depends` The list of dependencies required to run the package. These dependencies
are not installed to the master directory, rather are only checked if a binary package
in the local repository exists to satisfy the required version. Dependencies

View file

@ -18,6 +18,7 @@ should be read by xbps-src:
* extract (before running extract phase)
* configure (before running configure phase)
* build (before running build phase)
* check (before running check phase)
* install (before running install phase)
* pkg (before running pkg phase)

View file

@ -0,0 +1 @@
../configure/bootstrap.sh

View file

@ -0,0 +1 @@
../configure/cross.sh

View file

@ -0,0 +1 @@
../configure/hardening.sh

View file

@ -0,0 +1 @@
../configure/pkg-config.sh

View file

@ -7,7 +7,7 @@ unset -v only_for_archs distfiles checksum build_style nocross broken
unset -v configure_script configure_args wrksrc build_wrksrc create_wrksrc
unset -v make_cmd make_build_args make_install_args make_build_target make_install_target python_version stackage
unset -v patch_args disable_parallel_build keep_libtool_archives
unset -v reverts subpackages makedepends hostmakedepends depends restricted
unset -v reverts subpackages makedepends hostmakedepends checkdepends depends restricted
unset -v nopie build_options build_options_default bootstrap repository reverts
unset -v CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LD_LIBRARY_PATH
unset -v CC CXX CPP GCC LD AR AS RANLIB NM OBJDUMP OBJCOPY STRIP READELF

View file

@ -61,6 +61,10 @@ $XBPS_LIBEXECDIR/xbps-src-doconfigure.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
$XBPS_LIBEXECDIR/xbps-src-dobuild.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
[ "$XBPS_TARGET" = "build" ] && exit 0
# Run check phase
$XBPS_LIBEXECDIR/xbps-src-docheck.sh $SOURCEPKG $XBPS_CROSS_BUILD || exit 1
[ "$XBPS_TARGET" = "check" ] && exit 0
# Install pkgs into destdir.
$XBPS_LIBEXECDIR/xbps-src-doinstall.sh $SOURCEPKG no $XBPS_CROSS_BUILD || exit 1

View file

@ -0,0 +1,54 @@
#!/bin/bash
#
# vim: set ts=4 sw=4 et:
#
# Passed arguments:
# $1 - pkgname to build [REQUIRED]
# $2 - cross target [OPTIONAL]
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "${0##*/}: invalid number of arguments: pkgname [cross-target]"
exit 1
fi
PKGNAME="$1"
XBPS_CROSS_BUILD="$2"
for f in $XBPS_SHUTILSDIR/*.sh; do
. $f
done
setup_pkg "$PKGNAME" $XBPS_CROSS_BUILD
XBPS_CHECK_DONE="${XBPS_STATEDIR}/${sourcepkg}_${XBPS_CROSS_BUILD}_check_done"
if [ -n "$XBPS_CROSS_BUILD" ]; then
msg_normal "${pkgname}-${version}_${revision}: skipping check (cross build for $XBPS_CROSS_BUILD) ...\n"
exit 0
fi
if [ -z "$XBPS_CHECK_PKGS" -o "$XBPS_CHECK_PKGS" = "0" -o "$XBPS_CHECK_PKGS" = "no" ]; then
msg_normal "${pkgname}-${version}_${revision}: skipping check (XBPS_CHECK_PKGS is disabled) ...\n"
exit 0
fi
for f in $XBPS_COMMONDIR/environment/check/*.sh; do
source_file "$f"
done
cd "$wrksrc" || msg_error "$pkgver: cannot access wrksrc directory [$wrksrc]\n"
if [ -n "$build_wrksrc" ]; then
cd $build_wrksrc || \
msg_error "$pkgver: cannot access build_wrksrc directory [$build_wrksrc]\n"
fi
# Run do_check() if the function is defined
if declare -f do_check > /dev/null; then
run_func do_check
else
msg_normal "${pkgname}-${version}_${revision}: template does not have do_check() ...\n"
fi
touch -f $XBPS_CHECK_DONE
exit 0

View file

@ -49,6 +49,13 @@ setup_pkg_depends() {
_depver=$(srcpkg_get_version ${_depname}) || exit $?
host_build_depends+=" ${_depname}-${_depver}"
done
if ! [ -z "$XBPS_CHECK_PKGS" -o "$XBPS_CHECK_PKGS" = "0" -o "$XBPS_CHECK_PKGS" = "no" ]; then
for j in ${checkdepends}; do
_depname="${j%\?*}"
_depver=$(srcpkg_get_version ${_depname}) || exit $?
host_check_depends+=" ${_depname}-${_depver}"
done
fi
for j in ${makedepends}; do
_depname="${j%\?*}"
_depver=$(srcpkg_get_version ${_depname}) || exit $?
@ -183,7 +190,8 @@ install_pkg_deps() {
local rval _realpkg _vpkg _curpkg curpkgdepname pkgn iver
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 check_binpkg_deps binpkg_deps
local -a host_missing_deps check_missing_deps missing_deps missing_rdeps
[ -z "$pkgname" ] && return 2
@ -195,7 +203,7 @@ install_pkg_deps() {
msg_normal "$pkgver: building ...\n"
fi
if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$run_depends" ]; then
if [ -z "$build_depends" -a -z "$host_build_depends" -a -z "$host_check_depends" -a -z "$run_depends" ]; then
return 0
fi
@ -231,6 +239,39 @@ install_pkg_deps() {
host_missing_deps+=("${i}")
done
#
# Host check dependencies.
#
for i in ${host_check_depends}; do
check_pkgdep_matched "$i" version
local rval=$?
if [ $rval -eq 0 ]; then
echo " [check] ${i}: installed."
continue
elif [ $rval -eq 1 ]; then
_realpkg="$($XBPS_UHELPER_CMD getpkgname $i 2>/dev/null)"
iver=$($XBPS_UHELPER_CMD version ${_realpkg})
if [ $? -eq 0 -a -n "$iver" ]; then
echo " [check] ${i}: installed $iver (virtualpkg)."
continue
else
echo " [check] ${i}: unresolved check dependency!"
return 1
fi
else
repo=$($XBPS_QUERY_CMD -R -prepository ${i} 2>/dev/null)
if [ -n "${repo}" ]; then
echo " [check] ${i}: found ($repo)"
check_binpkg_deps+=("${i}")
continue
else
echo " [check] ${i}: not found."
fi
fi
check_missing_deps+=("${i}")
done
#
# Target build dependencies.
#
@ -324,7 +365,7 @@ install_pkg_deps() {
missing_rdeps+=("${_realpkg}")
done
# Host missing dependencies, build from srcpkgs.
# Missing host dependencies, build from srcpkgs.
for i in ${host_missing_deps[@]}; do
# packages not found in repos, install from source.
(
@ -336,7 +377,19 @@ install_pkg_deps() {
host_binpkg_deps+=("$i")
done
# Target missing dependencies, build from srcpkgs.
# Missing check dependencies, build from srcpkgs.
for i in ${check_missing_deps[@]}; do
# packages not found in repos, install from source.
(
curpkgdepname=$($XBPS_UHELPER_CMD getpkgname "$i" 2>/dev/null)
setup_pkg $curpkgdepname
exec env XBPS_DEPENDENCY=1 XBPS_BINPKG_EXISTS=1 \
$XBPS_LIBEXECDIR/build.sh $sourcepkg $pkg $target || exit $?
) || exit $?
check_binpkg_deps+=("$i")
done
# Missing target dependencies, build from srcpkgs.
for i in ${missing_deps[@]}; do
# packages not found in repos, install from source.
(
@ -374,6 +427,11 @@ install_pkg_deps() {
install_pkg_from_repos "${i}"
done
for i in ${check_binpkg_deps[@]}; do
msg_normal "$pkgver: installing check dependency '$i' ...\n"
install_pkg_from_repos "${i}"
done
for i in ${binpkg_deps[@]}; do
msg_normal "$pkgver: installing target dependency '$i' ...\n"
install_pkg_from_repos "$i" $cross

View file

@ -33,7 +33,7 @@ XBPS_SRC_VERSION="$XBPS_SRC_VERSION"
PATH=/void-packages:/usr/bin:/usr/sbin
exec env -i SHELL=/bin/sh PATH="\$PATH" DISTCC_HOSTS="\$XBPS_DISTCC_HOSTS" DISTCC_DIR="/host/distcc" @@XARCH@@ \
CCACHE_DIR="/host/ccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \
@@CHECK@@ CCACHE_DIR="/host/ccache" IN_CHROOT=1 LC_COLLATE=C LANG=en_US.UTF-8 TERM=linux HOME="/tmp" \
PS1="[\u@$XBPS_MASTERDIR \W]$ " /bin/bash +h
_EOF
if [ -n "$XBPS_ARCH" ]; then
@ -41,6 +41,11 @@ _EOF
else
sed -e 's,@@XARCH@@,,g' -i $XBPS_MASTERDIR/bin/xbps-shell
fi
if [ -z "$XBPS_CHECK_PKGS" -o "$XBPS_CHECK_PKGS" = "0" -o "$XBPS_CHECK_PKGS" = "no" ]; then
sed -e 's,@@CHECK@@,,g' -i $XBPS_MASTERDIR/bin/xbps-shell
else
sed -e "s,@@CHECK@@,XBPS_CHECK_PKGS=$XBPS_CHECK_PKGS,g" -i $XBPS_MASTERDIR/bin/xbps-shell
fi
chmod 755 $XBPS_MASTERDIR/bin/xbps-shell
cp -f /etc/resolv.conf $XBPS_MASTERDIR/etc
@ -170,7 +175,7 @@ chroot_handler() {
[ -z "$action" -a -z "$pkg" ] && return 1
case "$action" in
fetch|extract|build|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
fetch|extract|build|check|configure|install|install-destdir|pkg|build-pkg|bootstrap-update|chroot)
chroot_prepare || return $?
chroot_init || return $?
chroot_sync_repos || return $?
@ -188,6 +193,7 @@ chroot_handler() {
[ -n "$XBPS_BUILD_FORCEMODE" ] && arg="$arg -f"
[ -n "$XBPS_MAKEJOBS" ] && arg="$arg -j$XBPS_MAKEJOBS"
[ -n "$XBPS_DEBUG_PKGS" ] && arg="$arg -g"
[ -z "$XBPS_CHECK_PKGS" -o "$XBPS_CHECK_PKGS" = "0" -o "$XBPS_CHECK_PKGS" = "no" ] && arg="$arg -q"
[ -n "$XBPS_SKIP_DEPS" ] && arg="$arg -I"
[ -n "$XBPS_ALT_REPOSITORY" ] && arg="$arg -r $XBPS_ALT_REPOSITORY"
[ -n "$XBPS_USE_GIT_REVS" ] && arg="$arg -G"

View file

@ -4,7 +4,7 @@ consistency_check_existing () {
while IFS=" " read -r dep origname deplabel; do
[ -f "$XBPS_SRCPKGDIR/$dep/template" ] && continue
case "$deplabel" in
makedepends|hostmakedepends)
makedepends|hostmakedepends|checkdepends)
msg_warn "unsatisfied $deplabel in $origname: $dep does not exist\n";
;;
*) printf "%s %s %s\n" "$dep" "$origname" "$deplabel" ;;
@ -16,7 +16,7 @@ consistency_convert_pkgname () {
local origname= pkgname version= revision=
while IFS=" " read -r dep origname deplabel; do
case "$deplabel" in
makedepends|hostmakedepends)
makedepends|hostmakedepends|checkdepends)
printf "%s %s %s\n" "$dep" "$origname" "$deplabel"
continue
;;
@ -41,7 +41,7 @@ consistency_check_smart () {
local pkgname= depdef= dep=
while IFS=" " read -r depdef origname deplabel; do
case "$deplabel" in
makedepends|hostmakedepends)
makedepends|hostmakedepends|checkdepends)
printf "%s %s %s\n" "$depdef" "$origname" "$deplabel"
continue
;;
@ -73,6 +73,7 @@ consistency_check() {
[ -L "$XBPS_SRCPKGDIR/$XBPS_TARGET_PKG" ] && continue
[ "$makedepends" ] && printf "%s $pkgname makedepends\n" $makedepends
[ "$hostmakedepends" ] && printf "%s $pkgname hostmakedepends\n" $hostmakedepends
[ "$checkdepends" ] && printf "%s $pkgname checkdepends\n" $checkdepends
)
done | grep -v "^virtual?" | sed "s/^[^ ]*?//" | consistency_check_existing | \
consistency_convert_pkgname | consistency_check_smart

View file

@ -63,6 +63,11 @@ XBPS_SUCMD="sudo /bin/sh -c"
#
#XBPS_USE_GIT_REVS=yes
# [OPTIONAL]
# Enable running the (optional) do_check() function of a package.
#
#XBPS_CHECK_PKGS=yes
# [OPTIONAL]
# Enable building -dbg subpackages with debugging symbols. Please note
# that building with debugging symbols make take a long while in some

View file

@ -30,6 +30,9 @@ bootstrap-update
build <pkgname>
Build package source (fetch + extract + configure + build).
check <pkgname>
Run the package check(s) after building the package source.
consistency-check
Runs a consistency check on all packages
@ -412,7 +415,7 @@ readonly XBPS_GCC_VERSION=${XBPS_GCC_VERSION_MAJOR}.${XBPS_GCC_VERSION_MINOR}.${
# main()
#
XBPS_OPTIONS=
XBPS_OPTSTRING="a:CEfgGhH:Ij:Lm:No:r:tV"
XBPS_OPTSTRING="a:CEfgGhH:Ij:Lm:No:qr:tV"
# Preprocess arguments in order to allow options before and after XBPS_TARGET.
eval set -- $(getopt -- "$XBPS_OPTSTRING" "$@");
@ -433,6 +436,7 @@ while getopts "$XBPS_OPTSTRING" opt; do
m) readonly XBPS_MASTERDIR=$(readlink -m $OPTARG 2>/dev/null); XBPS_OPTIONS+=" -m $XBPS_MASTERDIR";;
N) readonly XBPS_SKIP_REMOTEREPOS=1; XBPS_OPTIONS+=" -N";;
o) readonly XBPS_PKG_OPTIONS="$OPTARG"; XBPS_OPTIONS+=" -o $OPTARG";;
q) export XBPS_CHECK_PKGS=0; XBPS_OPTIONS+=" -q";;
r) readonly XBPS_ALT_REPOSITORY="$OPTARG"; XBPS_OPTIONS+=" -r $OPTARG";;
t) export XBPS_TEMP_MASTERDIR=1; XBPS_OPTIONS+=" -t -C";;
V) echo $XBPS_SRC_VERSION && exit 0;;
@ -569,7 +573,7 @@ export XBPS_SHUTILSDIR XBPS_CROSSPFDIR XBPS_TRIGGERSDIR \
XBPS_CMPVER_CMD XBPS_FETCH_CMD XBPS_VERSION XBPS_APIVER \
XBPS_BUILDSTYLEDIR XBPS_CPPFLAGS XBPS_CFLAGS XBPS_CXXFLAGS XBPS_LDFLAGS \
XBPS_MAKEJOBS XBPS_BUILD_FORCEMODE XBPS_USE_GIT_REVS XBPS_DEBUG_PKGS \
XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
XBPS_CHECK_PKGS XBPS_CCACHE XBPS_DISTCC XBPS_DISTCC_HOSTS XBPS_SKIP_DEPS \
XBPS_SKIP_REMOTEREPOS XBPS_CROSS_BUILD XBPS_PKG_OPTIONS XBPS_CONFIG_FILE \
XBPS_KEEP_ALL XBPS_HOSTDIR XBPS_MASTERDIR XBPS_SRC_VERSION \
XBPS_DESTDIR XBPS_MACHINE XBPS_TEMP_MASTERDIR XBPS_BINPKG_EXISTS \
@ -697,7 +701,7 @@ case "$XBPS_TARGET" in
remove_pkg_autodeps
fi
;;
fetch|extract|build|configure|install|pkg)
fetch|extract|build|check|configure|install|pkg)
read_pkg
if [ -n "$CHROOT_READY" -a -z "$IN_CHROOT" ]; then
chroot_handler $XBPS_TARGET $XBPS_TARGET_PKG