Mercurial > vanilla
changeset 1028:e46348eb3fbd
vanilla: create a generic lint.sh script
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 30 Aug 2019 21:05:00 +0200 |
parents | 34c9fa83dc08 |
children | 36cafca2de8e |
files | Scripts/lint-deps.sh Scripts/lint-options.sh Scripts/lint-pkg.sh Scripts/lint-src.sh Scripts/lint.sh Scripts/list.sh Scripts/scripts.subr |
diffstat | 7 files changed, 254 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/Scripts/lint-deps.sh Thu Aug 29 21:00:00 2019 +0200 +++ b/Scripts/lint-deps.sh Fri Aug 30 21:05:00 2019 +0200 @@ -17,20 +17,13 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # -alias basename="busybox basename" -alias dirname="busybox dirname" -alias echo="busybox echo" -alias find="busybox find" -alias grep="busybox grep" -alias realpath="busybox realpath" +. $(dirname $0)/scripts.subr -TOP=$(realpath $(dirname $0)/../) -PROGNAME=$(basename $0) -TMPDIR=/tmp/vanilla-lint-deps +tmpdir=/tmp/vanilla/lint-deps clean() { - rm -rf $TMPDIR + rm -rf $tmpdir } usage() @@ -40,49 +33,31 @@ } check() -{( - local name=$(basename $1).sh - local failed=0 - - cd $TOP/$1 +{ + vnl_open_build $1 - echo -n "checking dependencies for $1: " + if [ -z "$PKGNAME" ]; then + exit 1 + fi - # Reset PKGDEPENDS in case script is broken. - PKGDEPENDS="" - - . ./$name + echo "=> checking dependencies for $PKGNAME" for d in $PKGDEPENDS; do local dep=${d%:*} - - if ! grep -q $dep $TMPDIR/list; then - # Only print "error" once. - if [ $failed -eq 0 ]; then - failed=1 - echo "error" - fi - echo "missing $dep" 1>&2 + if ! grep -q $dep $tmpdir/list; then + echo "warning: missing $dep" 1>&2 fi done +} - if [ $failed -eq 0 ]; then - echo "ok" - fi -)} +trap "clean; exit 1" INT QUIT TERM EXIT -trap "clean; exit 1" INT QUIT TERM - -rm -rf $TMPDIR -mkdir -p $TMPDIR +rm -rf $tmpdir +mkdir -p $tmpdir # First, retrieve all packages. -$TOP/Scripts/list.sh | sed -re "s|[^/]*/||" > $TMPDIR/list +$TOP/Scripts/list.sh | sed -re "s|[^/]*/||" > $tmpdir/list -# Now check dependencies. -$TOP/Scripts/list.sh $1 | while read -r pkg; do - check $pkg -done - +check $1 clean
--- a/Scripts/lint-options.sh Thu Aug 29 21:00:00 2019 +0200 +++ b/Scripts/lint-options.sh Fri Aug 30 21:05:00 2019 +0200 @@ -17,35 +17,23 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # -alias basename="busybox basename" -alias dirname="busybox dirname" -alias echo="busybox echo" -alias grep="busybox grep" -alias realpath="busybox realpath" - -TOP=$(realpath $(dirname $0)/../) -PROGNAME=$(basename $0) +. $(dirname $0)/scripts.subr check() -{( - name=$(basename $1).sh +{ + vnl_open_build $1 - cd $TOP/$1 - - if [ ! -f $name ]; then - echo "warning: skipping $pkg" 1>&2 - return 1 + if [ -z "$PKGNAME" ]; then + exit 1 fi - . ./$name + echo "=> checking common options for $PKGNAME" for o in $PKGOPTIONS; do - if ! grep -q $o $TOP/Docs/options.md; then - echo "$pkg: option $o is unknown or custom" + if ! grep -q "^- $o:" $TOP/Docs/options.md; then + echo "note: option $o is unknown or custom" 1>&2 fi done -)} +} -$TOP/Scripts/list.sh $1 | while read -r pkg; do - check $pkg -done +check $1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Scripts/lint-pkg.sh Fri Aug 30 21:05:00 2019 +0200 @@ -0,0 +1,64 @@ +#!/bin/busybox sh +# +# lint-pkg.sh -- check various things in the package +# +# Copyright (c) 2019 David Demelier <markand@malikania.fr> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +. $(dirname $0)/scripts.subr + +check_fhs() +{ + echo "==> checking directory hierarchy" + + if tar tf $1 | grep -Ev '^(bin|etc|include|lib|libexec|local|share|tmp|var)' 1>&2; then + echo "warning: the above files are not part of Vanilla Linux FHS" 1>&2 + fi +} + +check_libtool() +{ + echo "==> checking presence of libtool files:" + + if tar tf $1 | grep -E '\.la$' 1>&2; then + echo "warning: the following libtool files must be removed" 1>&2 + fi +} + +check_manpages() +{ + echo "==> checking manual pages in uncompressed form:" + + if tar tf $1 | grep -E 'share/man/man./.*\.(gz|bz2)$'; then + echo "warning: the above files must not be compressed" 1>&2 + fi +} + +usage() +{ + echo "usage: lint-pkg.sh binary-package" 1>&2 + exit 1 +} + +if [ "$#" -lt 1 ]; then + usage + # NOTREACHED +fi + +echo "=> checking binary package content for $1" + +check_fhs $1 +check_libtool $1 +check_manpages $1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Scripts/lint-src.sh Fri Aug 30 21:05:00 2019 +0200 @@ -0,0 +1,54 @@ +#!/bin/busybox sh +# +# lint-src.sh -- check various things in the source package +# +# Copyright (c) 2019 David Demelier <markand@malikania.fr> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +. $(dirname $0)/scripts.subr + +check_structure() +{ + echo "==> checking structure" + + local pkgname=$(basename ${1%#*}) + + # Check if we have the extracted source tree? + if [ $(tar tf $1 2> /dev/null | wc -l) -gt 32 ]; then + echo "warning: the source file seems to have too many files" 1>&2 + fi + + # Check build script file + if ! tar tf $1 $pkgname/$pkgname.sh > /dev/null 2>&1; then + echo "warning: missing build script file" 1>&2 + fi + + # TODO: verify PKGDOWNLOAD. +} + +usage() +{ + echo "usage: lint-src.sh source-package" 1>&2 + exit 1 +} + +if [ "$#" -lt 1 ]; then + usage + # NOTREACHED +fi + +echo "=> checking binary package content for $1" + +check_structure $1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Scripts/lint.sh Fri Aug 30 21:05:00 2019 +0200 @@ -0,0 +1,53 @@ +#!/bin/busybox sh +# +# lint.sh -- check package quality +# +# Copyright (c) 2019 David Demelier <markand@malikania.fr> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +. $(dirname $0)/scripts.subr + +$TOP/Scripts/lint-deps.sh $1 +$TOP/Scripts/lint-options.sh $1 + +vnl_open_build $1 + +if [ -f /etc/vpk.conf ]; then + . /etc/vpk.conf +fi + +case ${COMPRESSION:-xz} in +"xz") + extension="txz" + ;; +"gzip") + extension="tgz" + ;; +"bzip2") + extension="tbz" + ;; +esac + +# Check if binary package is available. +pkg="/tmp/vpk/$PKGNAME#$PKGVERSION-$PKGREVISION-pkg.$extension" +src="/tmp/vpk/$PKGNAME#$PKGVERSION-$PKGREVISION-src.$extension" + +if [ -f "$pkg" ]; then + $TOP/Scripts/lint-pkg.sh $pkg +fi + +if [ -f "$src" ]; then + $TOP/Scripts/lint-src.sh $src +fi
--- a/Scripts/list.sh Thu Aug 29 21:00:00 2019 +0200 +++ b/Scripts/list.sh Fri Aug 30 21:05:00 2019 +0200 @@ -17,14 +17,7 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # -alias basename="busybox basename" -alias echo="busybox echo" -alias find="busybox find" -alias grep="busybox grep" -alias realpath="busybox realpath" -alias sed="busybox sed" - -TOP=$(realpath $(dirname $0)/../) +. $(dirname $0)/scripts.subr scriptfile() { @@ -37,7 +30,7 @@ cd $TOP find -mindepth 2 -maxdepth 2 -type d | grep -v '\.hg' | sed -e 's|^./||' else - file=$(scriptfile $1) + local file=$(scriptfile $1) if [ ! -f $file ]; then echo "abort: invalid package specified '$1'" 1>&2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Scripts/scripts.subr Fri Aug 30 21:05:00 2019 +0200 @@ -0,0 +1,54 @@ +# +# script.subr -- subroutines for Vanilla scripts +# +# Copyright (c) 2019 David Demelier <markand@malikania.fr> +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +for applet in $(busybox --list); do + alias applet="busybox $applet" +done + +TOP=$(realpath $(dirname $0)/../) + +vnl_warn() +{ + echo "abort: $1" 1>&2 +} + +vnl_err() +{ + vnl_warn "$@" + exit 1 +} + +vnl_open_build() +{ + local path + local name + + if [ -n "$1" ]; then + path=$TOP/$1 + else + path=$(pwd) + fi + + name=$(basename $path) + + if [ ! -f $path/$name.sh ]; then + vnl_err "not a source package directory" + fi + + . $path/$name.sh +}