]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
qa/coccinelle: allow to run from non git directory
authorJason Ish <ish@unx.ca>
Thu, 3 May 2018 17:35:18 +0000 (11:35 -0600)
committerVictor Julien <victor@inliniac.net>
Fri, 4 May 2018 14:38:55 +0000 (16:38 +0200)
For example, when I put the contents of a git worktree into
a Docker image for a test build .git will not be a directory
causing the run_check.sh script to fail.

qa/coccinelle/Makefile.am
qa/coccinelle/run_check.sh

index 4bc94f9bbb2a29d1bd99e026e19ac2b13c93cda6..1599404434a5f11afea9fe5af6a6bddfe66b74b7 100644 (file)
@@ -15,7 +15,7 @@ struct-flags.cocci:
        $(srcdir)/struct-flags.py > $(top_builddir)/qa/coccinelle/struct-flags.cocci
 
 check:
-       $(top_srcdir)/qa/coccinelle/run_check.sh
+       TOP_SRCDIR=$(abs_top_srcdir) $(top_srcdir)/qa/coccinelle/run_check.sh
 
 distclean-local:
        -rm $(top_builddir)/qa/coccinelle/struct-flags.cocci
index 79ec9cc6f0fee79f98e8864e2867f4f26c8adfb3..f04829d34c6a7d6884f3d6a320722807ecb6834f 100755 (executable)
@@ -4,6 +4,7 @@ if [ $1 ]; then
        case $1 in
        *[ch])
                LIST=$@;
+               PREFIX=$(git rev-parse --show-toplevel)/
                ;;
         *..*) 
                LIST=$(git diff --pretty="format:" --name-only $1 | grep -E '[ch]$')
@@ -14,9 +15,12 @@ if [ $1 ]; then
                PREFIX=$(git rev-parse --show-toplevel)/
                ;;
        esac
-else
+elif git rev-parse > /dev/null 2>&1; then
        LIST=$(git ls-tree -r --name-only --full-tree  HEAD src/ | grep -E '*.c$')
        PREFIX=$(git rev-parse --show-toplevel)/
+elif [ "${TOP_SRCDIR}" != "" ]; then
+       LIST=$(cd ${TOP_SRCDIR} && find src -name \*.[ch])
+       PREFIX=${TOP_SRCDIR}/
 fi
 
 if [ -z "$CONCURRENCY_LEVEL" ]; then
@@ -26,7 +30,7 @@ else
        echo "Using concurrency level $CONCURRENCY_LEVEL"
 fi
 
-for SMPL in $(git rev-parse --show-toplevel)/qa/coccinelle/*.cocci; do
+for SMPL in ${PREFIX}qa/coccinelle/*.cocci; do
        echo "Testing cocci file: $SMPL"
        if command -v parallel >/dev/null; then
                echo -n $LIST | parallel -d ' ' -j $CONCURRENCY_LEVEL spatch --very-quiet -sp_file $SMPL --undefined UNITTESTS $PREFIX{} || if [ -z "$NOT_TERMINAL" ]; then exit 1; fi