clojure-lsp: update to 2024.08.05.
[void-pkg.git] / common / hooks / pre-pkg / 99-pkglint.sh
blob90cb07da3f4affe8763b3c029a3c21eba7951cbb
1 # This hook checks for common issues related to void.
3 hook() {
4 local error=0 filename= rev= libname= conflictPkg= conflictFile=
5 local conflictRev= ignore= found= mapshlibs=$XBPS_COMMONDIR/shlibs
6 local emptypkg=yes
8 set +E
10 # Check for forbidden directories that are symlinks in void.
11 for f in lib bin sbin lib64 lib32 usr/sbin usr/lib64; do
12 [ -e "${PKGDESTDIR}/${f}" ] || continue
13 if [ "${pkgname}" = "base-files" ]; then
14 if [ -L "${PKGDESTDIR}/${f}" ]; then
15 continue
17 msg_red "${pkgver}: /${f} must be a symlink.\n"
18 error=1
19 else
20 msg_red "${pkgver}: /${f} must not exist.\n"
21 error=1
23 done
25 for f in var/run usr/local usr/etc; do
26 if [ -d ${PKGDESTDIR}/${f} ]; then
27 msg_red "${pkgver}: /${f} directory is not allowed, remove it!\n"
28 error=1
30 done
32 if [ -d ${PKGDESTDIR}/usr/lib/libexec ]; then
33 # Add exception for kconfig,
34 # other packages hard-coded path to its files
35 if [ "${pkgname}" != kconfig ]; then
36 msg_red "${pkgver}: /usr/lib/libexec directory is not allowed!\n"
37 error=1
41 for f in "$PKGDESTDIR"/*; do
42 f="${f##*/}"
43 case "$f" in
44 '*') # The filename is exactly '*'
45 if [ -e "${PKGDESTDIR}/*" ]; then
46 msg_red "${pkgver}: File /* is not allowed\n"
47 error=1
50 lib|bin|sbin|lib64|lib32|usr|var|opt|etc|boot|srv)
51 emptypkg=no
53 INSTALL|INSTALL.msg|REMOVE|REMOVE.msg|rdeps|shlib-requires|shlib-provides)
54 if [ ! -f "${PKGDESTDIR}/$f" ]; then
55 msg_red "${pkgver}: /${f} is not allowed\n"
56 error=1
60 msg_red "${pkgver}: /${f} directory is not allowed, remove it!\n"
61 error=1
63 esac
64 done
66 # Forbid empty packages unless build_style=meta or it is 32bit devel package
67 if [ "$build_style" != meta ] && [ "$emptypkg" != no ] && [[ ${pkgname} != *-devel-32bit ]]; then
68 msg_red "${pkgver}: PKGDESTDIR is empty and build_style != meta\n"
69 error=1
72 # Check that configuration files really exist.
73 for f in $(expand_destdir "${conf_files}"); do
74 if [ ! -f "${PKGDESTDIR}/${f}" ]; then
75 msg_red "${pkgver}: '$f' configuration file not in PKGDESTDIR!\n"
76 error=1
78 done
80 # Check for l10n files in usr/lib/locale
81 if [ -d ${PKGDESTDIR}/usr/lib/locale ]; then
82 local locale_allow=0 ldir
83 local lroot="${PKGDESTDIR}/usr/lib/locale"
85 if [ "${pkgname}" = "glibc" ]; then
86 # glibc gets an exception for its included C.utf8 locale
87 locale_allow=1
88 for ldir in "${lroot}"/*; do
89 [ "${ldir}" = "${lroot}/C.utf8" ] && continue
90 locale_allow=0
91 done
94 if [ "${locale_allow}" -ne 1 ]; then
95 msg_red "${pkgver}: /usr/lib/locale is forbidden, use /usr/share/locale!\n"
96 error=1
100 # Check for bash completions in etc/bash_completion.d
101 # should be on usr/share/bash-completion/completions
102 if [ -d ${PKGDESTDIR}/etc/bash_completion.d ]; then
103 msg_red "${pkgver}: /etc/bash_completion.d is forbidden. Use /usr/share/bash-completion/completions.\n"
104 error=1
107 # Prevent packages from installing to these paths in etc, they should use
108 # their equivalent in usr/lib
109 for f in udev/{rules.d,hwdb.d} modprobe.d sysctl.d; do
110 if [ -d ${PKGDESTDIR}/etc/${f} ]; then
111 msg_red "${pkgver}: /etc/${f} is forbidden. Use /usr/lib/${f}.\n"
112 error=1
114 done
116 # Likewise with the comment above but for usr/share
117 for f in X11/xorg.conf.d gconf/schemas; do
118 if [ -d ${PKGDESTDIR}/etc/${f} ]; then
119 msg_red "${pkgver}: /etc/${f} is forbidden. Use /usr/share/${f}.\n"
120 error=1
122 done
124 if [ -d ${PKGDESTDIR}/etc/dracut.conf.d ]; then
125 msg_red "${pkgver}: /etc/dracut.conf.d is forbidden. Use /usr/lib/dracut/dracut.conf.d.\n"
126 error=1
129 if [ -d ${PKGDESTDIR}/usr/usr ]; then
130 msg_red "${pkgver}: /usr/usr is forbidden, use /usr.\n"
131 error=1
134 if [ -d ${PKGDESTDIR}/usr/man ]; then
135 msg_red "${pkgver}: /usr/man is forbidden, use /usr/share/man.\n"
136 error=1
139 if [[ -d ${PKGDESTDIR}/usr/share/man/man ]]; then
140 msg_red "${pkgver}: /usr/share/man/man is forbidden, use /usr/share/man.\n"
141 error=1
144 if [ -d ${PKGDESTDIR}/usr/doc ]; then
145 msg_red "${pkgver}: /usr/doc is forbidden. Use /usr/share/doc.\n"
146 error=1
149 if [ -d ${PKGDESTDIR}/usr/dict ]; then
150 msg_red "${pkgver}: /usr/dict is forbidden. Use /usr/share/dict.\n"
151 error=1
154 if [ -e ${PKGDESTDIR}/usr/share/glib-2.0/schemas/gschemas.compiled ]; then
155 msg_red "${pkgver}: /usr/share/glib-2.0/schemas/gschemas.compiled is forbidden. Delete it.\n"
156 error=1
159 # Forbid files would be generated by mimedb trigger
160 for f in XMLnamespaces aliases generic-icons globs globs2 icons \
161 magic mime.cache subclasses treemagic types version ; do
162 if [ -f "${PKGDESTDIR}/usr/share/mime/$f" ]; then
163 msg_red "${pkgver}: /usr/share/mime/$f is forbidden. Delete it.\n"
164 error=1
166 done
168 if [ $error -gt 0 ]; then
169 msg_error "${pkgver}: cannot continue with installation!\n"
172 # Check for missing shlibs and SONAME bumps.
173 if [ ! -s "${PKGDESTDIR}/shlib-provides" ]; then
174 return 0
177 for filename in $(<${PKGDESTDIR}/shlib-provides); do
178 rev=${filename#*.so.}
179 libname=${filename%.so*}
180 _shlib=$(echo "$libname"|sed -E 's|\+|\\+|g')
181 _pkgname=$(echo "$pkgname"|sed -E 's|\+|\\+|g')
182 if [ "$rev" = "$filename" ]; then
183 _pattern="^${_shlib}\.so[[:blank:]]+${_pkgname}-[^-]+_[0-9]+"
184 else
185 _pattern="^${_shlib}\.so\.[0-9]+(.*)[[:blank:]]+${_pkgname}-[^-]+_[0-9]+"
187 grep -E "${_pattern}" $mapshlibs | { \
188 while read -r conflictFile conflictPkg ignore; do
189 found=1
190 conflictRev=${conflictFile#*.so.}
191 if [ -n "$ignore" -a "$ignore" != "$XBPS_TARGET_MACHINE" ]; then
192 continue
193 elif [ "$rev" = "$conflictRev" ]; then
194 continue
195 elif [[ ${rev}.* =~ $conflictRev ]]; then
196 continue
198 msg_red "${pkgver}: SONAME bump detected: ${libname}.so.${conflictRev} -> ${libname}.so.${rev}\n"
199 msg_red "${pkgver}: please update common/shlibs with this line: \"${libname}.so.${rev} ${pkgver}\"\n"
200 msg_red "${pkgver}: all reverse dependencies should also be revbumped to be rebuilt against ${libname}.so.${rev}:\n"
201 _revdeps=$($XBPS_QUERY_XCMD -Rs ${libname}.so -p shlib-requires|cut -d ' ' -f1)
202 for x in ${_revdeps}; do
203 msg_red " ${x%:}\n"
204 done
205 msg_error "${pkgver}: cannot continue with installation!\n"
206 done
207 # Try to match provided shlibs in virtual packages.
208 for f in ${provides}; do
209 _vpkgname="$($XBPS_UHELPER_CMD getpkgname ${f} 2>/dev/null)"
210 _spkgname="$(grep "^${filename}" $mapshlibs | cut -d ' ' -f2)"
211 _libpkgname="$($XBPS_UHELPER_CMD getpkgname ${_spkgname} 2>/dev/null)"
212 if [ -z "${_spkgname}" -o -z "${_libpkgname}" ]; then
213 continue
215 if [ "${_vpkgname}" = "${_libpkgname}" ]; then
216 found=1
217 break
219 done;
220 if [ -z "$found" ]; then
221 _myshlib="${libname}.so"
222 [ "${_myshlib}" != "${rev}" ] && _myshlib+=".${rev}"
223 msg_normal "${pkgver}: ${_myshlib} not found in common/shlibs.\n"
226 done