summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <thibault.saunier@osg.samsung.com>2016-09-30 11:35:41 -0300
committerThibault Saunier <thibault.saunier@osg.samsung.com>2016-09-30 13:31:16 -0300
commitb84d4490f7f64a2ce581906f0cc630e578e90c2b (patch)
tree05988cce2f32b92dd292da40a3f8d9e48b1b727c
parent5dd3f9df205edc1a4bf817ec99ad38e7192082e2 (diff)
meson: Setup pre commit hook and fix getpluginsdir for standalone case
-rwxr-xr-xhooks/multi-pre-commit.hook (renamed from validate/multi-pre-commit.hook)2
-rwxr-xr-xhooks/pre-commit-python.hook (renamed from validate/pre-commit-python.hook)0
-rwxr-xr-xhooks/pre-commit.hook83
-rw-r--r--meson.build3
-rw-r--r--validate/tests/getpluginsdir13
5 files changed, 94 insertions, 7 deletions
diff --git a/validate/multi-pre-commit.hook b/hooks/multi-pre-commit.hook
index 4a1e8e0..98ae380 100755
--- a/validate/multi-pre-commit.hook
+++ b/hooks/multi-pre-commit.hook
@@ -15,7 +15,7 @@
# commit. They are executed in the order in which they are listed.
###########################################################
-HOOKS="validate/common/hooks/pre-commit.hook validate/pre-commit-python.hook"
+HOOKS="hooks/pre-commit.hook hooks/pre-commit-python.hook"
# exit on error
set -e
diff --git a/validate/pre-commit-python.hook b/hooks/pre-commit-python.hook
index 1c0efb6..1c0efb6 100755
--- a/validate/pre-commit-python.hook
+++ b/hooks/pre-commit-python.hook
diff --git a/hooks/pre-commit.hook b/hooks/pre-commit.hook
new file mode 100755
index 0000000..3c1062b
--- /dev/null
+++ b/hooks/pre-commit.hook
@@ -0,0 +1,83 @@
+#!/bin/sh
+#
+# Check that the code follows a consistant code style
+#
+
+# Check for existence of indent, and error out if not present.
+# On some *bsd systems the binary seems to be called gnunindent,
+# so check for that first.
+
+version=`gnuindent --version 2>/dev/null`
+if test "x$version" = "x"; then
+ version=`gindent --version 2>/dev/null`
+ if test "x$version" = "x"; then
+ version=`indent --version 2>/dev/null`
+ if test "x$version" = "x"; then
+ echo "GStreamer git pre-commit hook:"
+ echo "Did not find GNU indent, please install it before continuing."
+ exit 1
+ else
+ INDENT=indent
+ fi
+ else
+ INDENT=gindent
+ fi
+else
+ INDENT=gnuindent
+fi
+
+case `$INDENT --version` in
+ GNU*)
+ ;;
+ default)
+ echo "GStreamer git pre-commit hook:"
+ echo "Did not find GNU indent, please install it before continuing."
+ echo "(Found $INDENT, but it doesn't seem to be GNU indent)"
+ exit 1
+ ;;
+esac
+
+INDENT_PARAMETERS="--braces-on-if-line \
+ --case-brace-indentation0 \
+ --case-indentation2 \
+ --braces-after-struct-decl-line \
+ --line-length80 \
+ --no-tabs \
+ --cuddle-else \
+ --dont-line-up-parentheses \
+ --continuation-indentation4 \
+ --honour-newlines \
+ --tab-size8 \
+ --indent-level2 \
+ --leave-preprocessor-space"
+
+echo "--Checking style--"
+for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
+ # nf is the temporary checkout. This makes sure we check against the
+ # revision in the index (and not the checked out version).
+ nf=`git checkout-index --temp ${file} | cut -f 1`
+ newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
+ $INDENT ${INDENT_PARAMETERS} \
+ $nf -o $newfile 2>> /dev/null
+ # FIXME: Call indent twice as it tends to do line-breaks
+ # different for every second call.
+ $INDENT ${INDENT_PARAMETERS} \
+ $newfile 2>> /dev/null
+ diff -u -p "${nf}" "${newfile}"
+ r=$?
+ rm "${newfile}"
+ rm "${nf}"
+ if [ $r != 0 ] ; then
+echo "================================================================================================="
+echo " Code style error in: $file "
+echo " "
+echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
+echo " If the whole file is to be committed, this should work (run from the top-level directory): "
+echo " "
+echo " gst-indent $file; git add $file; git commit"
+echo " "
+echo "================================================================================================="
+ exit 1
+ fi
+done
+echo "--Checking style pass--"
diff --git a/meson.build b/meson.build
index e49d44c..6497c26 100644
--- a/meson.build
+++ b/meson.build
@@ -54,3 +54,6 @@ gnome = import('gnome')
gtkdoc = find_program('gtkdoc-scan', required : false)
subdir('validate')
+
+python3 = find_program('python3')
+run_command(python3, '-c', 'import shutil; shutil.copy("hooks/multi-pre-commit.hook", ".git/hooks/pre-commit")')
diff --git a/validate/tests/getpluginsdir b/validate/tests/getpluginsdir
index 98054b4..aa41ca8 100644
--- a/validate/tests/getpluginsdir
+++ b/validate/tests/getpluginsdir
@@ -16,11 +16,12 @@ for i in range(0, len(args), 2):
res += ':' + path
else:
try:
- res += ':' + subprocess.check_output(['pkg-config',
- '--variable=pluginsdir',
- pkg_name]).decode()
- except subprocess.CalledProcessError:
- exit(1)
+ res += ':' + subprocess.check_output([
+ 'pkg-config', '--variable=pluginsdir',
+ pkg_name]).decode().replace("\n", "")
+ except subprocess.CalledProcessError as e:
+ # Probably means there is no .pc file for the module
+ # and it should hopefully no be too bad.
+ pass
print(res.strip(":"))
-