Commit 9977e9cc authored by Leo's avatar Leo

alint: add

parents
#!/bin/sh
# alint APKBUILD - scan APKBUILD template for common mistakes
#
# Adapted from xlint from Void Linux's xtools to Alpine Linux
# https://github.com/leahneukirchen/xtools/
#
# Required packages (names are Alpine Linux pkgs):
# busybox - for sed, tr, sort, head and other simple utiltiies
# grep - for grep with -P
export LC_ALL=C
scan() {
local rx="$1" msg="$2"
grep -P -Hn -e "$rx" "$apkbuild" |
sed "s/^\([^:]*:[^:]*:\)\(.*\)/\1 $msg/"
}
once() {
head -n 1
}
variables=$(echo -n "#.*
_.*
startdir
srcdir
pkgdir
subpkgdir
builddir
arch
depends
depends_dev
checkdepends
giturl
install
.*.pre-install
.*.post-install
.*.pre-upgrade
.*.post-upgrade
.*.pre-deinstall
.*.post-deinstall
install_if
license
makedepends
md5sums
sha256sums
sha512sums
options
pkgdesc
pkggroups
pkgname
pkgrel
pkgusers
pkgver
provides
provider_priority
replaces
replaces_priority
source
subpackages
triggers
ldpath
url" | tr '\n' '|')
ret=0
for apkbuild; do
if [ -f "$apkbuild" ]; then
# Source apkbuild
srcdir="" . "$apkbuild" 2>/dev/null
if [ "$builddir" = "/$pkgname-$pkgver" ]; then
scan '^builddir=' "builddir can be removed as it is the default value"
fi
# Find duplicates in
printf "%s\n" "$depends" | tr " " "\n" | sort | uniq -d | while read -r dup; do
printf "$apkbuild:: duplicate '$dup' in depends\n"
done
printf "%s\n" "$makedepends" | tr " " "\n" | sort | uniq -d | while read -r dup; do
printf "$apkbuild:: duplicate '$dup' in makedepends\n"
done
printf "%s\n" "$checkdepends" | tr " " "\n" | sort | uniq -d | while read -r dup; do
printf "$apkbuild:: duplicate '$dup' in checkdepends\n"
done
printf "%s\n" "$depends_dev" | tr " " "\n" | sort | uniq -d | while read -r dup; do
printf "$apkbuild:: duplicate '$dup' in depends_dev\n"
done
scan '\|\| return 1' "|| return 1 is not required as set -e is used"
scan '^pkgname="[^$]+"' "pkgname must not be quoted"
scan '^pkgver="[^$]+"' "pkgver must not be quoted"
scan '^[^ =]*=(|''|)$' "variable set to empty string: \2"
scan '^(?!\s*^('"$variables"'))[^\s=-]+=' \
"prefix custom variable with _: \2"
scan '^ ' "indent with tabs"
scan '[\t ]$' "trailing whitespace"
scan '[^\\]`' "use \$() instead of backticks"
scan '^\t*function\b' 'do not use the function keyword'
scan '^\t*[^ ]* *\(\)' 'do not use space before function parenthesis'
scan '^\t*[^ ]*\(\)(| *){' 'use one space after function parenthesis'
scan '^\t*[^ ]*\(\)$' 'do not use a newline before function opening brace'
# Don't perform these checks on packages from main
if ! [ -z "${apkbuild##*main/*}" ]; then
for phase in build check package; do
sed -n "/^$phase() {/,/^}/{p;=}" "$apkbuild" | grep -m 1 -B 1 'cd "$builddir"$' | head -1 | while read -r l; do
if [ -z "$l" ]; then
continue
fi
printf "$apkbuild:$l: cd \"\$builddir\" can be removed\n"
done
done
_pkgname="$(grep -Po "^pkgname=\K.*" "$apkbuild")"
_pkgver="$(grep -Po "^pkgver=\K.*" "$apkbuild")"
fi
else
echo no such apkbuild "$apkbuild" 1>&2
fi | sort -t: -n -k2 | grep . && ret=1
done
exit $ret
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment