diff options
author | Đoàn Trần Công Danh <congdanhqx@gmail.com> | 2020-12-05 01:13:56 +0000 |
---|---|---|
committer | Đoàn Trần Công Danh <congdanhqx@gmail.com> | 2020-12-14 02:35:02 +0000 |
commit | 3996821f07592bba37206303b3618be2ab5ef7f5 (patch) | |
tree | 7c4390da797a090d73923852bcca2934f819f02b | |
parent | 29722b3a524049a83059b413c16c6d087c010a17 (diff) | |
download | void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.tar void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.tar.gz void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.tar.bz2 void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.tar.lz void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.tar.xz void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.tar.zst void-packages-3996821f07592bba37206303b3618be2ab5ef7f5.zip |
99-pkglint-subpkgs: correct for multiline subpackages
As discussing in [1], on template with "subpackages" as multilines will
report false positive on some packages will never be built.
There're multiple problems here:
- expanded "subpackages" will have an empty line if it has a newline
inside template
- "sed" expression couldn't work with multilines "subpackages"
Let's not quote "$subpkgs" and "$subpackages" in "printf" to let the
shell do expansion and trim the empty lines for us. And rewrite the
"sed" expression to work with multilines "subpackages"
[1]: https://github.com/void-linux/void-packages/pull/26939#issuecomment-739098547
-rw-r--r-- | common/hooks/pre-pkg/99-pkglint-subpkgs.sh | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/common/hooks/pre-pkg/99-pkglint-subpkgs.sh b/common/hooks/pre-pkg/99-pkglint-subpkgs.sh index add7fdd4a07..fd1fee6c445 100644 --- a/common/hooks/pre-pkg/99-pkglint-subpkgs.sh +++ b/common/hooks/pre-pkg/99-pkglint-subpkgs.sh @@ -18,21 +18,27 @@ hook() { subpkgs=$(get_subpkgs) - subpackages="${subpackages// /$'\n'}" - # Sort the strings so they can be compare for equality - subpkgs="$(printf "%s\\n" "$subpkgs" | sort)" - subpackages="$(printf "%s\\n" "$subpackages" | sort)" + subpkgs="$(printf '%s\n' $subpkgs | sort)" + subpackages="$(printf '%s\n' $subpackages | sort)" if [ "$subpackages" = "$subpkgs" ]; then return 0 fi - # XXX: Make the sed call work when subpackages has multiple lines - # this can be done with grep with perl regexp (-P) but chroot-grep - # is compiled without it - matches="$(sed -n 's/subpackages.*"\(.*\)"[^"]*$/\1/p' $XBPS_SRCPKGDIR/$pkgname/template \ - | tr " " "\n" | sort)" + # sed supports comment but let's put them here + # 1: print everything between pairs of <""> in subpackages[+]?="..." + # 2: multiline subpackages="...\n..." + # 2.1: For any line in the middle, i.e. no <"> exists, print it + # 2.2: For the first line, print everything after <"> + # 2.3: For last line, print everything before <"> + matches="$(sed -n -e 's/subpackages.*"\(.*\)"[^"]*$/\1/p' \ + -e '/subpackages[^"]*"[^"]*$/,/"/{ + /"/!p + /subpackages/s/.*"//p + s/".*//p + }' $XBPS_SRCPKGDIR/$pkgname/template | + tr ' ' '\n' | sort)" for s in $subpkgs; do grep -q "^$s$" <<< "$matches" || |