On Fri, Jun 08, 2018 at 08:42:11PM +0100, Morgan Adamiec wrote: > On Fri, 8 Jun 2018 at 20:33, Eli Schwartz <eschwa...@archlinux.org> wrote: > > > > On 06/08/2018 02:18 PM, morganamilo wrote: > > > When a split package overriddes an array using += and the array does not > > > exist globally, makepkg --printsrcinfo will print the field with an > > > empty vlaue before printing the acual values. > > > > > > For exampple: having `depends+=(foo bar)` will generate: > > > depends = > > > depends = foo > > > depends = bar > > > > > > Explicity check for empty array values and only print the values that > > > are not empty. > > > > > > Signed-off-by: morganamilo <morganam...@gmail.com> > > > --- > > > scripts/libmakepkg/srcinfo.sh.in | 6 +++++- > > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > > > diff --git a/scripts/libmakepkg/srcinfo.sh.in > > > b/scripts/libmakepkg/srcinfo.sh.in > > > index 509c4860..6a49be37 100644 > > > --- a/scripts/libmakepkg/srcinfo.sh.in > > > +++ b/scripts/libmakepkg/srcinfo.sh.in > > > @@ -44,7 +44,11 @@ srcinfo_write_attr() { > > > attrvalues=("${attrvalues[@]#[[:space:]]}") > > > attrvalues=("${attrvalues[@]%[[:space:]]}") > > > > > > - printf "\t$attrname = %s\n" "${attrvalues[@]}" > > > + for val in "${attrvalues[@]}"; do > > > + if [[ ! -z ${val// /} ]]; then > > > + printf "\t$attrname = %s\n" "$val" > > > + fi > > > + done > > > > This is odd, I wonder why get_pkgbuild_attribute is returning an > > array=('' foo bar) in this case? We should probably fix it more directly. > > > > -- > > Eli Schwartz > > Bug Wrangler and Trusted User > > > > In my investigation it came down to lines like this > https://git.archlinux.org/pacman.git/tree/scripts/libmakepkg/srcinfo.sh.in#n55 > > It seems appending an array to a non array value generates an array > with the first value being an empty string then the values appended. > > You can reproduce it with: > foo= > foo+=(bar) > echo "${#foo[@]}" > > I did think about fixing it there, but that function is used all over > and I didn't want to break something.
That's just bad shell code. Using foo= to declare an array is the same as writing foo=(''). Please don't change this to paper over bad PKGBUILDs. If anything, the fix here is to leverage bash 4.4 in our lint rules when it's available and use @a expansion to detect if something is an array or a string, e.g. $ licenses='MIT' $ [[ ${licenses@a} = *a* ]] || echo "licenses must be an array"