makepkg: perform all sanity checks before erroring out

It is pretty annoying to get one, fix it, and then get another. We should be
able to continue on through most of the sanity checks in one go so the user
gets all the error messages at once.

Also ensure $pkgbase is defined by the time we call this function;
previously we printed nothing where a package name should have been due to
this oversight.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-01-10 13:56:27 -06:00
parent 665528d7ba
commit a88cb03a58

View file

@ -1194,36 +1194,37 @@ install_package() {
check_sanity() { check_sanity() {
# check for no-no's in the build script # check for no-no's in the build script
local i local i
local ret=0
for i in 'pkgname' 'pkgrel' 'pkgver'; do for i in 'pkgname' 'pkgrel' 'pkgver'; do
if [[ -z ${!i} ]]; then if [[ -z ${!i} ]]; then
error "$(gettext "%s is not allowed to be empty.")" "$i" error "$(gettext "%s is not allowed to be empty.")" "$i"
return 1 ret=1
fi fi
done done
for i in "${pkgname[@]}"; do for i in "${pkgname[@]}"; do
if [[ ${i:0:1} = "-" ]]; then if [[ ${i:0:1} = "-" ]]; then
error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname" error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
return 1 ret=1
fi fi
done done
if [[ ${pkgbase:0:1} = "-" ]]; then if [[ ${pkgbase:0:1} = "-" ]]; then
error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase" error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgbase"
return 1 ret=1
fi fi
if [[ $pkgver != ${pkgver//-/} ]]; then if [[ $pkgver =~ [:-] ]]; then
error "$(gettext "%s is not allowed to contain hyphens.")" "pkgver" error "$(gettext "%s is not allowed to contain colons or hyphens.")" "pkgver"
return 1 ret=1
fi fi
if [[ $pkgrel != ${pkgrel//-/} ]]; then if [[ $pkgrel != ${pkgrel//-/} ]]; then
error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel" error "$(gettext "%s is not allowed to contain hyphens.")" "pkgrel"
return 1 ret=1
fi fi
if [[ ! $epoch =~ ^[0-9]*$ ]]; then if [[ ! $epoch =~ ^[0-9]*$ ]]; then
error "$(gettext "%s must be an integer.")" "epoch" error "$(gettext "%s must be an integer.")" "epoch"
return 1 ret=1
fi fi
if [[ $arch != 'any' ]]; then if [[ $arch != 'any' ]]; then
@ -1232,7 +1233,7 @@ check_sanity() {
error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH" 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 "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
plain "$(gettext "such as arch=('%s').")" "$CARCH" plain "$(gettext "such as arch=('%s').")" "$CARCH"
return 1 ret=1
fi fi
fi fi
fi fi
@ -1242,7 +1243,7 @@ check_sanity() {
for i in ${provides_list[@]}; do for i in ${provides_list[@]}; do
if [[ $i != ${i//</} || $i != ${i//>/} ]]; then if [[ $i != ${i//</} || $i != ${i//>/} ]]; then
error "$(gettext "Provides array cannot contain comparison (< or >) operators.")" error "$(gettext "Provides array cannot contain comparison (< or >) operators.")"
return 1 ret=1
fi fi
done done
@ -1251,7 +1252,7 @@ check_sanity() {
for i in "${backup_list[@]}"; do for i in "${backup_list[@]}"; do
if [[ ${i:0:1} = "/" ]]; then if [[ ${i:0:1} = "/" ]]; then
error "$(gettext "Backup entry should not contain leading slash : %s")" "$i" error "$(gettext "Backup entry should not contain leading slash : %s")" "$i"
return 1 ret=1
fi fi
done done
@ -1272,7 +1273,7 @@ check_sanity() {
eval file=${file} eval file=${file}
if [[ ! -f $file ]]; then if [[ ! -f $file ]]; then
error "$(gettext "%s file (%s) does not exist.")" "$i" "$file" error "$(gettext "%s file (%s) does not exist.")" "$i" "$file"
return 1 ret=1
fi fi
done done
done done
@ -1294,14 +1295,14 @@ check_sanity() {
fi fi
done done
if (( ! valid_options )); then if (( ! valid_options )); then
return 1 ret=1
fi fi
if (( ${#pkgname[@]} > 1 )); then if (( ${#pkgname[@]} > 1 )); then
for i in ${pkgname[@]}; do for i in ${pkgname[@]}; do
if ! declare -f package_${i} >/dev/null; then if ! declare -f package_${i} >/dev/null; then
error "$(gettext "missing package function for split package '%s'")" "$i" error "$(gettext "missing package function for split package '%s'")" "$i"
return 1 ret=1
fi fi
done done
fi fi
@ -1309,11 +1310,11 @@ check_sanity() {
for i in ${PKGLIST[@]}; do for i in ${PKGLIST[@]}; do
if ! in_array $i ${pkgname[@]}; then if ! in_array $i ${pkgname[@]}; then
error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE" error "$(gettext "requested package %s is not provided in %s")" "$i" "$BUILDFILE"
return 1 ret=1
fi fi
done done
return 0 return $ret
} }
devel_check() { devel_check() {
@ -1838,6 +1839,8 @@ if (( GENINTEG )); then
exit 0 # $E_OK exit 0 # $E_OK
fi fi
pkgbase=${pkgbase:-${pkgname[0]}}
# check the PKGBUILD for some basic requirements # check the PKGBUILD for some basic requirements
check_sanity || exit 1 check_sanity || exit 1
@ -1868,8 +1871,6 @@ elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then
SPLITPKG=1 SPLITPKG=1
fi fi
pkgbase=${pkgbase:-${pkgname[0]}}
if [[ -n "${PKGLIST[@]}" ]]; then if [[ -n "${PKGLIST[@]}" ]]; then
unset pkgname unset pkgname
pkgname=("${PKGLIST[@]}") pkgname=("${PKGLIST[@]}")