The old implementation had both false negatives and false positives. Because of the -w option to grep, it didn't detect lines like: license=bad Additionally, it did detect irrelevant lines like this: --with-arch=${_arch} The latter is a false positive which made it difficult to build valid packages. Signed-off-by: David Grayson <davidegrayson@gmail.com> --- scripts/libmakepkg/lint_pkgbuild/variable.sh.in | 26 ++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in index 1daac26..eee6b54 100644 --- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in +++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in @@ -28,6 +28,25 @@ source "$LIBRARY/util/message.sh" lint_pkgbuild_functions+=('lint_variable') +lint_var_defined_as_non_array() { + if [[ "${!1+x}" == "" ]]; then + return 1 # not defined + fi + if [[ "$(declare -p $1)" == "declare -a "* ]]; then + return 1 # defined as an array + fi + return 0 +} + +lint_var_defined_as_array() { + if [[ "${!1+x}" == "" ]]; then + return 1 # not defined + fi + if [[ "$(declare -p $1)" == "declare -a "* ]]; then + return 0 # defined as an array + fi + return 1 +} lint_variable() { # TODO: refactor - similar arrays are used elsewhere @@ -39,17 +58,18 @@ lint_variable() { local i for i in ${array[@]}; do - if grep -w -q -e "$i=[^(]" -e "$i+=[^(]" "$BUILDSCRIPT"; then + if lint_var_defined_as_non_array $i; then error "$(gettext "%s should be an array")" "$i" ret=1 fi done + local a for a in ${arch[@]}; do [[ $a == "any" ]] && continue for i in ${arch_array[@]}; do - if grep -w -q -e "$i_$a=[^(]" -e "$i_$a+=[^(]" "$BUILDSCRIPT"; then + if lint_var_defined_as_non_array $i; then error "$(gettext "%s_%s should be an array")" "$i" "$a" ret=1 fi @@ -57,7 +77,7 @@ lint_variable() { done for i in ${string[@]}; do - if grep -w -q -e "$i=(" -e "$i+=(" "$BUILDSCRIPT"; then + if lint_var_defined_as_array $i; then error "$(gettext "%s should not be an array")" "$i" ret=1 fi -- 2.6.2