makepkg: refactor sanity checking into a function

No new checks, just move it into a function and return 1 rather than exit
directly. This also allows the use of local variables.

Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Dan McGee 2009-06-06 12:49:37 -05:00
parent 13b281d743
commit e61ab1536f
1 changed files with 76 additions and 66 deletions

View File

@ -1103,6 +1103,79 @@ install_package() {
fi
}
check_sanity() {
# check for no-no's in the build script
if [ -z "$pkgname" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgname"
return 1
fi
if [ -z "$pkgver" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgver"
return 1
fi
if [ -z "$pkgrel" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
return 1
fi
if [ "$pkgver" != "${pkgver//-/}" ]; then
error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver"
return 1
fi
if [ "$pkgrel" != "${pkgrel//-/}" ]; then
error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
return 1
fi
if [ "$arch" = 'any' ]; then
CARCH='any'
fi
pkgbase=${pkgbase:-${pkgname[0]}}
if ! in_array $CARCH ${arch[@]}; then
if [ "$IGNOREARCH" -eq 0 ]; then
error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
plain "$(gettext "such as arch=('%s').")" "$CARCH"
return 1
fi
fi
local provide
for provide in ${provides[@]}; do
if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
return 1
fi
done
if [ "$install" -a ! -f "$install" ]; then
error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
return 1
fi
local valid_options=1
local opt known kopt
for opt in ${options[@]}; do
known=0
# check if option matches a known option or its inverse
for kopt in ${packaging_options[@]} ${other_options[@]}; do
if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
known=1
fi
done
if [ $known -eq 0 ]; then
error "$(gettext "options array contains unknown option '%s'")" "$opt"
valid_options=0
fi
done
if [ $valid_options -eq 0 ]; then
return 1
fi
return 0
}
devel_check() {
newpkgver=""
@ -1556,74 +1629,11 @@ if [ "$(type -t package)" = "function" ]; then
PKGFUNC=1
fi
# check for no-no's in the build script
if [ -z "$pkgname" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgname"
# check the PKGBUILD for some basic requirements
check_sanity || insane=1
if [ $insane -eq 1 ]; then
exit 1
fi
if [ -z "$pkgver" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgver"
exit 1
fi
if [ -z "$pkgrel" ]; then
error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
exit 1
fi
if [ "$pkgver" != "${pkgver//-/}" ]; then
error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver"
exit 1
fi
if [ "$pkgrel" != "${pkgrel//-/}" ]; then
error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
exit 1
fi
if [ "$arch" = 'any' ]; then
CARCH='any'
fi
pkgbase=${pkgbase:-${pkgname[0]}}
if ! in_array $CARCH ${arch[@]}; then
if [ "$IGNOREARCH" -eq 0 ]; then
error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
plain "$(gettext "such as arch=('%s').")" "$CARCH"
exit 1
fi
fi
for provide in ${provides[@]}; do
if [ $provide != ${provide//</} -o $provide != ${provide//>/} ]; then
error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
exit 1
fi
done
unset provide
if [ "$install" -a ! -f "$install" ]; then
error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
exit 1
fi
valid_options=1
for opt in ${options[@]}; do
known=0
# check if option matches a known option or its inverse
for kopt in ${packaging_options[@]} ${other_options[@]}; do
if [ "${opt}" = "${kopt}" -o "${opt}" = "!${kopt}" ]; then
known=1
fi
done
if [ $known -eq 0 ]; then
error "$(gettext "options array contains unknown option '%s'")" "$opt"
valid_options=0
fi
done
if [ $valid_options -eq 0 ]; then
exit 1
fi
unset valid_options opt known kopt
# We need to run devel_update regardless of whether we are in the fakeroot
# build process so that if the user runs makepkg --forcever manually, we