libmakepkg: improve validity checking of arch array

Only a subset of checks were being performed on the overridden arch
arrays in package functions. Refactor checking such that all checks
are perform on all arch arrays.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2024-12-20 14:21:32 +10:00
parent 62d3192126
commit 5e2a763e4a

View file

@ -30,15 +30,23 @@ source "$MAKEPKG_LIBRARY/util/pkgbuild.sh"
lint_pkgbuild_functions+=('lint_arch') lint_pkgbuild_functions+=('lint_arch')
lint_arch() { validate_arch() {
local a name list ret=0 local n="$1"; shift
local a=("$@")
if in_array "any" "${arch[@]}"; then if (( ${#a[@]} == 0 )); then
if (( ${#arch[@]} == 1 )); then error "$(gettext "%s is not allowed to be empty.")" "arch"
return 0; ret=1
else else
if in_array "any" "${a[@]}"; then
if (( ${#a[@]} != 1 )); then
error "$(gettext "Can not use '%s' architecture with other architectures")" "any" error "$(gettext "Can not use '%s' architecture with other architectures")" "any"
return 1; ret=1
fi
else
if ! in_array "$CARCH" "${a[@]}"; then
error "$(gettext "%s is not available for the '%s' architecture.")" "$n" "$CARCH"
ret=1
fi fi
fi fi
@ -49,21 +57,24 @@ lint_arch() {
ret=1 ret=1
fi fi
done done
fi
}
if (( ! IGNOREARCH )) && ! in_array "$CARCH" "${arch[@]}"; then lint_arch() {
error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH" local name list ret=0
return 1
if (( IGNOREARCH )); then
return 0;
fi fi
validate_arch "$pkgbase" "${arch[@]}"
if (( ret == 0 )); then
for name in "${pkgname[@]}"; do for name in "${pkgname[@]}"; do
get_pkgbuild_attribute "$name" 'arch' 1 list get_pkgbuild_attribute "$name" 'arch' 1 list
if [[ $list && $list != 'any' ]] && ! in_array $CARCH "${list[@]}"; then validate_arch "$name" "${list[@]}"
if (( ! IGNOREARCH )); then
error "$(gettext "%s is not available for the '%s' architecture.")" "$name" "$CARCH"
ret=1
fi
fi
done done
fi
return $ret return $ret
} }