[pacman-dev,4/7] libmakepkg: lint disallowed architecture specific variables

Message ID 20180608181859.20724-5-morganamilo@gmail.com
State Superseded, archived
Headers show
Series Improve linting for makepkg | expand

Commit Message

morganamilo June 8, 2018, 6:18 p.m. UTC
Variables such as 'pkgdesc_x86_64' are invalid, instead of ignoring them
raise an error.

Signed-off-by: morganamilo <morganamilo@gmail.com>
---
 .../libmakepkg/lint_pkgbuild/variable.sh.in   | 24 ++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Allan McRae June 19, 2018, 12:23 p.m. UTC | #1
On 09/06/18 04:18, morganamilo wrote:
> Variables such as 'pkgdesc_x86_64' are invalid, instead of ignoring them
> raise an error.
> 
> Signed-off-by: morganamilo <morganamilo@gmail.com>
> ---
>  .../libmakepkg/lint_pkgbuild/variable.sh.in   | 24 ++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
> index 68512a62..b9264768 100644
> --- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
> +++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
> @@ -69,6 +69,15 @@ lint_variable() {
>  				fi
>  			fi
>  		done
> +
> +		for i in ${array[@]} ${string[@]}; do
> +			v="${i}_${a}"
> +			eval "keys=(\"\${!${v}[@]}\")"
> +			if (( ${#keys[*]} > 0 )); then
> +				error "$(gettext "%s_%s can not be architecture specific")" "$i" "$a"

This patch looks OK.  I think the following error message would be more
clear:

error "$(gettext "%s can not be architecture specific: $s_$s")" "$i"
"$i" "$a"

> +				ret=1
> +			fi
> +		done
>  	done
>  
>  	for i in ${string[@]}; do
> @@ -93,6 +102,20 @@ lint_variable() {
>  		for a in ${arch[@]}; do
>  			[[ $a == "any" ]] && continue
>  
> +			for i in ${string[@]}; do
> +				if extract_function_variable "package_$pkg" "${i}_${a}" 0 out; then
> +					error "$(gettext "%s_%s can not be architecture specific")" "$i" "$a"
> +					ret=1
> +				fi
> +			done
> +
> +			for i in ${array[@]}; do
> +				if extract_function_variable "package_$pkg" "${i}_${a}" 1 out; then
> +					error "$(gettext "%s_%s can not be architecture specific")" "$i" "$a"
> +					ret=1
> +				fi
> +			done
> +>  			for i in ${no_overide_string[@]}; do
>  				if extract_function_variable "package_$pkg" "${i}_${a}" 0 out; then
>  					error "$(gettext "%s_%s can not be overridden in package function")" "$i" "$a"
> @@ -108,7 +131,6 @@ lint_variable() {
>  
>  			done
>  
> -
>  			for i in ${arch_array[@]}; do
>  				if extract_function_variable "package_$pkg" "${i}_${a}" 0 out; then
>  					error "$(gettext "%s_%s should be an array")" "$i" "$a"
>

Patch

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index 68512a62..b9264768 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -69,6 +69,15 @@  lint_variable() {
 				fi
 			fi
 		done
+
+		for i in ${array[@]} ${string[@]}; do
+			v="${i}_${a}"
+			eval "keys=(\"\${!${v}[@]}\")"
+			if (( ${#keys[*]} > 0 )); then
+				error "$(gettext "%s_%s can not be architecture specific")" "$i" "$a"
+				ret=1
+			fi
+		done
 	done
 
 	for i in ${string[@]}; do
@@ -93,6 +102,20 @@  lint_variable() {
 		for a in ${arch[@]}; do
 			[[ $a == "any" ]] && continue
 
+			for i in ${string[@]}; do
+				if extract_function_variable "package_$pkg" "${i}_${a}" 0 out; then
+					error "$(gettext "%s_%s can not be architecture specific")" "$i" "$a"
+					ret=1
+				fi
+			done
+
+			for i in ${array[@]}; do
+				if extract_function_variable "package_$pkg" "${i}_${a}" 1 out; then
+					error "$(gettext "%s_%s can not be architecture specific")" "$i" "$a"
+					ret=1
+				fi
+			done
+
 			for i in ${no_overide_string[@]}; do
 				if extract_function_variable "package_$pkg" "${i}_${a}" 0 out; then
 					error "$(gettext "%s_%s can not be overridden in package function")" "$i" "$a"
@@ -108,7 +131,6 @@  lint_variable() {
 
 			done
 
-
 			for i in ${arch_array[@]}; do
 				if extract_function_variable "package_$pkg" "${i}_${a}" 0 out; then
 					error "$(gettext "%s_%s should be an array")" "$i" "$a"