From ae0b7954b9541c1489d530ebab4f79aff562ce8b Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 19 Nov 2020 03:14:50 +0100 Subject: [PATCH] Import the newer scripts from DeforaOS configure --- doc/docbook.sh | 15 ++++-- po/gettext.sh | 13 +++-- tests/clint.sh | 42 ++++++++++------ tests/fixme.sh | 126 ++++++++++++++++++++++++++++++++++------------ tests/htmllint.sh | 24 ++++++--- tests/xmllint.sh | 37 +++++++++++--- 6 files changed, 188 insertions(+), 69 deletions(-) diff --git a/doc/docbook.sh b/doc/docbook.sh index 620374f..83bbf54 100755 --- a/doc/docbook.sh +++ b/doc/docbook.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2012-2015 Pierre Pronchery +#Copyright (c) 2012-2020 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -25,8 +25,8 @@ #variables +CONFIGSH="${0%/docbook.sh}/../config.sh" PREFIX="/usr/local" -[ -f "../config.sh" ] && . "../config.sh" PROGNAME="docbook.sh" #executables DEBUG="_debug" @@ -37,6 +37,8 @@ RM="rm -f" XMLLINT="xmllint" XSLTPROC="xsltproc --nonet --xinclude" +[ -f "$CONFIGSH" ] && . "$CONFIGSH" + #functions #debug @@ -114,7 +116,7 @@ _usage() clean=0 install=0 uninstall=0 -while getopts "ciuP:" name; do +while getopts "ciO:uP:" name; do case "$name" in c) clean=1 @@ -123,6 +125,9 @@ while getopts "ciuP:" name; do uninstall=0 install=1 ;; + O) + export "${OPTARG%%=*}"="${OPTARG#*=}" + ;; u) install=0 uninstall=1 @@ -137,7 +142,7 @@ while getopts "ciuP:" name; do esac done shift $((OPTIND - 1)) -if [ $# -eq 0 ]; then +if [ $# -lt 1 ]; then _usage exit $? fi @@ -167,7 +172,7 @@ while [ $# -gt 0 ]; do xpath="string(/refentry/refmeta/manvolnum)" section=$($XMLLINT --xpath "$xpath" "$source") if [ $? -eq 0 -a -n "$section" ]; then - instdir="$DATADIR/man/html$section" + instdir="$MANDIR/html$section" fi ;; pdf) diff --git a/po/gettext.sh b/po/gettext.sh index 5bb7c9b..d1b91a2 100755 --- a/po/gettext.sh +++ b/po/gettext.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2010-2015 Pierre Pronchery +#Copyright (c) 2010-2020 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -25,8 +25,8 @@ #variables +CONFIGSH="${0%/gettext.sh}/../config.sh" PREFIX="/usr/local" -[ -f "../config.sh" ] && . "../config.sh" LOCALEDIR="$PREFIX/share/locale" POTFILES="POTFILES" PROGNAME="gettext.sh" @@ -40,6 +40,8 @@ MSGMERGE="msgmerge" RM="rm -f" XGETTEXT="xgettext --force-po" +[ -f "$CONFIGSH" ] && . "$CONFIGSH" + #functions #debug @@ -112,7 +114,7 @@ _gettext_pot() clean=0 install=0 uninstall=0 -while getopts "ciuP:" name; do +while getopts "ciO:uP:" name; do case "$name" in c) clean=1 @@ -121,6 +123,9 @@ while getopts "ciuP:" name; do uninstall=0 install=1 ;; + O) + export "${OPTARG%%=*}"="${OPTARG#*=}" + ;; u) install=0 uninstall=1 @@ -135,7 +140,7 @@ while getopts "ciuP:" name; do esac done shift $(($OPTIND - 1)) -if [ $# -eq 0 ]; then +if [ $# -lt 1 ]; then _usage exit $? fi diff --git a/tests/clint.sh b/tests/clint.sh index bf01d00..a7d22ba 100755 --- a/tests/clint.sh +++ b/tests/clint.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2016-2019 Pierre Pronchery +#Copyright (c) 2016-2020 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -25,6 +25,7 @@ #variables +CONFIGSH="${0%/clint.sh}/../config.sh" CFLAGS= CPPFLAGS= PROGNAME="clint.sh" @@ -35,16 +36,19 @@ DEBUG="_debug" FIND="find" GREP="grep" LINT="lint -g" +MKDIR="mkdir -p" SORT="sort -n" TR="tr" +[ -f "$CONFIGSH" ] && . "$CONFIGSH" + #functions #clint _clint() { - ret=0 - subdirs="data doc src tests tools" + res=0 + subdirs= $DATE while read line; do @@ -58,6 +62,10 @@ _clint() ;; esac done < "$PROJECTCONF" + if [ ! -n "$subdirs" ]; then + _error "Could not locate directories to analyze" + return $? + fi for subdir in $subdirs; do [ -d "../$subdir" ] || continue for filename in $($FIND "../$subdir" -type f | $SORT); do @@ -79,13 +87,13 @@ _clint() if [ $? -ne 0 ]; then echo "FAIL" echo "$PROGNAME: $filename: FAIL" 1>&2 - ret=2 + res=2 else echo "OK" fi done done - return $ret + return $res } _clint_lint() @@ -117,6 +125,14 @@ _debug() } +#error +_error() +{ + echo "$PROGNAME: $@" 1>&2 + return 2 +} + + #usage _usage() { @@ -125,14 +141,6 @@ _usage() } -#warning -_warning() -{ - echo "$PROGNAME: $@" 1>&2 - return 2 -} - - #main clean=0 while getopts "cO:P:" name; do @@ -162,9 +170,15 @@ fi [ $clean -ne 0 ] && exit 0 exec 3>&1 +ret=0 while [ $# -gt 0 ]; do target="$1" + dirname="${target%/*}" shift - _clint > "$target" || exit 2 + if [ -n "$dirname" -a "$dirname" != "$target" ]; then + $MKDIR -- "$dirname" || ret=$? + fi + _clint > "$target" || ret=$? done +exit $ret diff --git a/tests/fixme.sh b/tests/fixme.sh index f4c921c..84319cf 100755 --- a/tests/fixme.sh +++ b/tests/fixme.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2017-2019 Pierre Pronchery +#Copyright (c) 2017-2020 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -25,23 +25,30 @@ #variables +CONFIGSH="${0%/fixme.sh}/../config.sh" PROGNAME="fixme.sh" PROJECTCONF="../project.conf" +REGEXP_ERROR="FIXME" +REGEXP_WARNING="\\(TODO\|XXX\\)" #executables DATE="date" DEBUG="_debug" FIND="find" GREP="grep" +HEAD="head" MKDIR="mkdir -p" SORT="sort -n" TR="tr" +[ -f "$CONFIGSH" ] && . "$CONFIGSH" + #functions #fixme _fixme() { res=0 + subdirs= $DATE echo @@ -56,27 +63,14 @@ _fixme() ;; esac done < "$PROJECTCONF" + if [ ! -n "$subdirs" ]; then + _error "Could not locate directories to analyze" + return $? + fi for subdir in $subdirs; do [ -d "../$subdir" ] || continue for filename in $($FIND "../$subdir" -type f | $SORT); do - callback= - ext=${filename##*/} - ext=${ext%.in} - ext=${ext##*.} - case "$ext" in - asm|S) - callback="_fixme_asm" - ;; - c|cc|cpp|cxx|h|js) - callback="_fixme_c" - ;; - conf|sh) - callback="_fixme_sh" - ;; - htm|html|xml) - callback="_fixme_xml" - ;; - esac + callback=$(_fixme_callback "$filename") [ -n "$callback" ] || continue ($callback "$filename") 2>&1 if [ $? -ne 0 ]; then @@ -88,54 +82,114 @@ _fixme() return $res } -_fixme_asm() +_fixme_callback() +{ + filename="$1" + ext=${filename##*/} + ext=${ext%.in} + ext=${ext##*.} + callback= + + case "$ext" in + asm|S) + echo "_fixme_callback_asm" + return 0 + ;; + c|cc|cpp|cxx|h|js|v) + echo "_fixme_callback_c" + return 0 + ;; + conf|sh) + echo "_fixme_callback_sh" + return 0 + ;; + py) + echo "_fixme_callback_python" + return 0 + ;; + htm|html|xml|xsl) + echo "_fixme_callback_xml" + return 0 + ;; + esac + case $($HEAD -n 1 "$filename") in + "#!/bin/sh"*|"#! /bin/sh"*|\ + "#!/usr/bin/env bash"*|"#! /usr/bin/env bash"*) + echo "_fixme_callback_sh" + return 0 + ;; + "#!/usr/bin/env python"*|"#! /usr/bin/env python"*) + echo "_fixme_callback_python" + return 0 + ;; + "&2 + return 2 +} + + #usage _usage() { diff --git a/tests/htmllint.sh b/tests/htmllint.sh index df4a4dd..37975c3 100755 --- a/tests/htmllint.sh +++ b/tests/htmllint.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2014-2017 Pierre Pronchery +#Copyright (c) 2014-2020 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -25,6 +25,7 @@ #variables +CONFIGSH="${0%/htmllint.sh}/../config.sh" DEVNULL="/dev/null" PROGNAME="htmllint.sh" PROJECTCONF="../project.conf" @@ -32,16 +33,19 @@ PROJECTCONF="../project.conf" DATE="date" DEBUG="_debug" FIND="find" -HTMLLINT="xmllint --html" +HTMLLINT="xmllint --html --nonet" +MKDIR="mkdir -p" SORT="sort -n" TR="tr" +[ -f "$CONFIGSH" ] && . "$CONFIGSH" + #functions #htmllint _htmllint() { - ret=0 + res=0 $DATE echo @@ -58,17 +62,17 @@ _htmllint() done < "$PROJECTCONF" for subdir in $subdirs; do [ -d "../$subdir" ] || continue - for filename in $($FIND "../$subdir" -iname '*.html' -o -iname '*.htm' | $SORT); do + for filename in $($FIND "../$subdir" -type f -a \( -iname '*.html' -o -iname '*.htm' \) | $SORT); do $DEBUG $HTMLLINT "$filename" 2>&1 > "$DEVNULL" if [ $? -eq 0 ]; then echo "$filename:" else echo "$PROGNAME: $filename: FAIL" 1>&2 - ret=2 + res=2 fi done done - return $ret + return $res } @@ -121,9 +125,15 @@ fi [ $clean -ne 0 ] && exit 0 exec 3>&1 +ret=0 while [ $# -gt 0 ]; do target="$1" + dirname="${target%/*}" shift - _htmllint > "$target" || exit 2 + if [ -n "$dirname" -a "$dirname" != "$target" ]; then + $MKDIR -- "$dirname" || ret=$? + fi + _htmllint > "$target" || ret=$? done +exit $ret diff --git a/tests/xmllint.sh b/tests/xmllint.sh index 70638f5..6773845 100755 --- a/tests/xmllint.sh +++ b/tests/xmllint.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2014-2017 Pierre Pronchery +#Copyright (c) 2014-2020 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -25,6 +25,7 @@ #variables +CONFIGSH="${0%/xmllint.sh}/../config.sh" DEVNULL="/dev/null" PROGNAME="xmllint.sh" PROJECTCONF="../project.conf" @@ -32,16 +33,20 @@ PROJECTCONF="../project.conf" DATE="date" DEBUG="_debug" FIND="find" +MKDIR="mkdir -p" SORT="sort -n" TR="tr" -XMLLINT="xmllint" +XMLLINT="xmllint --nonet" + +[ -f "$CONFIGSH" ] && . "$CONFIGSH" #functions #xmllint _xmllint() { - ret=0 + res=0 + subdirs= $DATE echo @@ -56,19 +61,23 @@ _xmllint() ;; esac done < "$PROJECTCONF" + if [ ! -n "$subdirs" ]; then + _error "Could not locate directories to analyze" + return $? + fi for subdir in $subdirs; do [ -d "../$subdir" ] || continue - for filename in $($FIND "../$subdir" -name '*.xml' -o -name '*.xsl' | $SORT); do + for filename in $($FIND "../$subdir" -type f -a \( -name '*.xml' -o -name '*.xsl' \) | $SORT); do $DEBUG $XMLLINT "$filename" 2>&1 > "$DEVNULL" if [ $? -eq 0 ]; then echo "$filename:" else echo "$PROGNAME: $filename: FAIL" 1>&2 - ret=2 + res=2 fi done done - return $ret + return $res } @@ -84,6 +93,14 @@ _debug() } +#error +_error() +{ + echo "$PROGNAME: $@" 1>&2 + return 2 +} + + #usage _usage() { @@ -121,9 +138,15 @@ fi [ $clean -ne 0 ] && exit 0 exec 3>&1 +ret=0 while [ $# -gt 0 ]; do target="$1" + dirname="${target%/*}" shift - _xmllint > "$target" || exit 2 + if [ -n "$dirname" -a "$dirname" != "$target" ]; then + $MKDIR -- "$dirname" || ret=$? + fi + _xmllint > "$target" || ret=$? done +exit $ret