clojure-lsp: update to 2024.08.05.
[void-pkg.git] / common / hooks / pre-pkg / 99-pkglint-subpkgs.sh
blob240d5ef0bc4820e870b0ad0acaf91d7ff627f50e
1 # vim: set ts=4 sw=4 et:
3 # This hook executes the following tasks:
4 # - Warns if the main package is in subpackages=
5 # - Warns if a subpackage is unreachable (never appears in subpackages=)
7 hook() {
8 local subpkgs matches
10 # Run this only against the main package
11 if [ "$pkgname" != "$sourcepkg" ]; then
12 return 0
15 if [ -z "$subpackages" ]; then
16 return 0
19 subpkgs=$(get_subpkgs)
21 # Sort the strings so they can be compare for equality
22 subpkgs="$(printf '%s\n' $subpkgs | sort)"
23 subpackages="$(printf '%s\n' $subpackages | sort)"
25 if [ "$subpackages" = "$subpkgs" ]; then
26 return 0
29 # sed supports comment but let's put them here
30 # 1: print everything between pairs of <""> in subpackages[+]?="..."
31 # 2: multiline subpackages="...\n..."
32 # 2.1: For any line in the middle, i.e. no <"> exists, print it
33 # 2.2: For the first line, print everything after <">
34 # 2.3: For last line, print everything before <">
35 matches="$(sed -n -e 's/subpackages.*"\(.*\)"[^"]*$/\1/p' \
36 -e '/subpackages[^"]*"[^"]*$/,/"/{
37 /"/!p
38 /subpackages/s/.*"//p
39 s/".*//p
40 }' $XBPS_SRCPKGDIR/$pkgname/template |
41 tr '\v\t\r\n' ' ')"
43 for s in $subpkgs; do
44 case " $matches " in
45 *" $s "*) ;;
46 *) msg_warn "${s}_package() defined but will never be built.\n" ;;
47 esac
48 done
50 case " $matches " in
51 *" $pkgname "*)
52 msg_warn "$pkgname is sourcepkg but is in subpackages=.\n" ;;
53 esac