99-pkglint-subpkgs.sh (1603B)
1# vim: set ts=4 sw=4 et: 2# 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=) 6 7hook() { 8 local subpkgs matches 9 10 # Run this only against the main package 11 if [ "$pkgname" != "$sourcepkg" ]; then 12 return 0 13 fi 14 15 if [ -z "$subpackages" ]; then 16 return 0 17 fi 18 19 subpkgs=$(get_subpkgs) 20 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)" 24 25 if [ "$subpackages" = "$subpkgs" ]; then 26 return 0 27 fi 28 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' ' ')" 42 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 49 50 case " $matches " in 51 *" $pkgname "*) 52 msg_warn "$pkgname is sourcepkg but is in subpackages=.\n" ;; 53 esac 54}