#!/bin/bash
# dev/package/check - Package Checking Support
set -e
lib_load 'dev/package/versions'
lib_load 'dev/package/dist'
lib_load 'dev/tool/make'
lib_load 'sys/tool/tar'
######
# Package Checking
package_check_clean() {
has_args 1 "$@"
local testdir=$1
run rm -rf "$testdir"
}
package_check_clone() {
has_args 1 "$@"
local testdir=$1
if [ -d .git ]; then
git_clone_or_update . "$testdir"
elif [ "$(pwd)" != "$(realpath "$testdir")" ]; then
local rsync_archive=true
run_mkdir "$testdir"
rsync_run -a "${DIST[@]}" "$testdir"
elif [ ! -d "$testdir" ]; then
error "$testdir: directory does not exist"
fi
}
package_check_build() {
has_args 1 "$@"
local testdir=$1
run_pushd "$testdir"
run ./bootstrap.sh
make_run info
make_run uninstall
make_run install
run git status --ignored
run_popd
}
######
# Distribution Checking
package_check_flag_file() { echo "dist/.check.stamp"; }
package_check_passed() {
# - Saves the repository revision that was checked.
git_rev_parse HEAD >"$(package_check_flag_file)"
}
# package_check_dist() - This function performs the actions required for
# implementing the ``distcheck`` rule in a package ``Makefile``. Its goal
# is to verify that the package distribution archives work from
# beginning to the end. This is accomplished by the following steps:
# $1 - Test directory
package_check_dist() {
has_args 1 "$@"
local testdir=$1
[ -d "$testdir" ] || error "$testdir missing; did you run 'make check'?"
app_echo "creating distribution archives"
run sed -i -e 's,=debug$,=release,' "$testdir/system.i7"
# - Runs ``check-archive`` rule in the test directory.
make_run -C "$testdir" check-archive
}
# package_check_archive() - This function performs the actions required for
# implementing the ``check-archive`` rule in a package ``Makefile``. Its goal
# is to verify that a package distribution archive can be extracted,
# built, and tested. This is accomplished by the following steps:
# $1 - Test directory
package_check_archive() {
has_args 1 "$@"
local testdir=$1
local debug=true
# - Prepares the distribution archive for testing:
# - Removes the old test directory, if it exists.
if [ -d "$testdir" ]; then
app_echo "removing old test directory"
run rm -rf "$testdir"
fi
# - Extracts the archive to the test directory
package_check_archive_extract "$testdir"
# - Builds and checks the extracted package archive
package_check_archive_build "$testdir"
}
package_check_archive_extract() {
has_args 1 "$@"
local testdir=$1
# - Extracts the archive
app_echo "extracting package distribution archive"
local archive="$(package_dist_tarfile).$tar_file_extensions"
local tar_verbose=true
run tar_extract "$archive"
# - Moves extracted package directory to testing location
local distdir=${archive##*/}
run mv "${distdir%.tar*}" "$testdir"
}
package_check_archive_build() {
has_args 1 "$@"
local testdir=$1
# - Bootstrap script builds everything
app_echo "running bootstrap in extracted archive"
run_in_dir "$testdir" ./bootstrap.sh
# - Built-in test suites pass
app_echo "running tests on extracted archive"
make_run -C "$testdir" check
}
package_check_archive_clean() {
has_args 1 "$@"
local testdir=$1
# - Cleanup rules remove all generated files
app_echo "removing generated files"
make_run -C "$testdir" clean
# - Cleans up the test directory
app_echo "removing extracted archive"
run rm -rf "$testdir"
app_echo "removing output files"
make_run distclean
}
Generated on Sat Jul 8 19:39:16 PDT 2017 by mcsh d14 v0.22.0.