From cdf20eebae59e0ceb2cf8fc2660609e6c38ccebf Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 24 Apr 2007 13:47:09 +0100 Subject: [PATCH] Add optional checks for coding style (mainly whitespace at the moment). These are on by default for git builds, off by default for releases. --- _dbus_bindings/Makefile.am | 3 +++ configure.ac | 17 ++++++++++++++++- dbus/Makefile.am | 3 +++ tools/Makefile.am | 5 +++++ tools/check-c-style.sh | 17 +++++++++++++++++ tools/check-coding-style.mk | 25 +++++++++++++++++++++++++ tools/check-py-style.sh | 18 ++++++++++++++++++ tools/check-whitespace.sh | 17 +++++++++++++++++ 8 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tools/Makefile.am create mode 100644 tools/check-c-style.sh create mode 100644 tools/check-coding-style.mk create mode 100644 tools/check-py-style.sh create mode 100644 tools/check-whitespace.sh diff --git a/_dbus_bindings/Makefile.am b/_dbus_bindings/Makefile.am index 35ef81d..c2e59c9 100644 --- a/_dbus_bindings/Makefile.am +++ b/_dbus_bindings/Makefile.am @@ -28,3 +28,6 @@ _dbus_bindings_la_SOURCES = \ string.c \ types-internal.h \ validation.c + +check_c_sources = $(_dbus_bindings_la_SOURCES) +include $(top_srcdir)/tools/check-coding-style.mk diff --git a/configure.ac b/configure.ac index 275371f..cb783e9 100644 --- a/configure.ac +++ b/configure.ac @@ -140,6 +140,20 @@ if test "x$enable_Werror" = xyes; then JH_ADD_CFLAG([-Werror]) fi +ifelse(dbus_python_released, 1, + [ # version x.y.z - disable coding style checks by default +AC_ARG_ENABLE(coding-style-checks, + AC_HELP_STRING([--enable-coding-style-checks], + [check coding style using grep]), + [ENABLE_CODING_STYLE_CHECKS=$enableval], [ENABLE_CODING_STYLE_CHECKS=no] ) + ], + [ # version x.y.z.200xyyzz - enable coding style checks by default +AC_ARG_ENABLE(coding-style-checks, + AC_HELP_STRING([--disable-coding-style-checks], + [don't check coding style using grep]), + [ENABLE_CODING_STYLE_CHECKS=$enableval], [ENABLE_CODING_STYLE_CHECKS=yes]) + ]) + AC_CONFIG_FILES( Makefile _dbus_bindings/Makefile @@ -152,5 +166,6 @@ AC_CONFIG_FILES( m4/Makefile test/Makefile test/tmp-session-bus.conf - test/TestSuitePythonService.service) + test/TestSuitePythonService.service + tools/Makefile) AC_OUTPUT diff --git a/dbus/Makefile.am b/dbus/Makefile.am index 484c2e6..9059659 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -15,6 +15,9 @@ nobase_pythondbus_PYTHON = dbus_bindings.py \ service.py \ types.py +check_py_sources = $(nobase_pythondbus_PYTHON) +include $(top_srcdir)/tools/check-coding-style.mk + CLEANFILES = .doc-needs-rebuild-stamp BUILT_SOURCES = .doc-needs-rebuild-stamp diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..122fa82 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = \ + check-coding-style.mk \ + check-c-style.sh \ + check-py-style.sh \ + check-whitespace.sh diff --git a/tools/check-c-style.sh b/tools/check-c-style.sh new file mode 100644 index 0000000..177355e --- /dev/null +++ b/tools/check-c-style.sh @@ -0,0 +1,17 @@ +#!/bin/sh +fail=0 + +/bin/sh "${top_srcdir}"/tools/check-whitespace.sh "$@" || fail=$? + +# at the moment we're not actually checking much C style here... to be added + +if test -n "$CHECK_FOR_LONG_LINES" +then + if egrep -n '.{80,}' "$@" + then + echo "^^^ The above files contain long lines" + fail=1 + fi +fi + +exit $fail diff --git a/tools/check-coding-style.mk b/tools/check-coding-style.mk new file mode 100644 index 0000000..5209223 --- /dev/null +++ b/tools/check-coding-style.mk @@ -0,0 +1,25 @@ +check-local:: + @fail=0; \ + if test -n "$(check_misc_sources)"; then \ + echo check-coding-style.mk: checking misc sources...; \ + top_srcdir=$(top_srcdir) \ + sh $(top_srcdir)/tools/check-whitespace.sh \ + $(check_misc_sources) || fail=1; \ + fi; \ + if test -n "$(check_py_sources)"; then \ + echo check-coding-style.mk: checking Python sources...; \ + top_srcdir=$(top_srcdir) \ + sh $(top_srcdir)/tools/check-py-style.sh \ + $(check_py_sources) || fail=1; \ + fi;\ + if test -n "$(check_c_sources)"; then \ + echo check-coding-style.mk: checking C sources...; \ + top_srcdir=$(top_srcdir) \ + sh $(top_srcdir)/tools/check-c-style.sh \ + $(check_c_sources) || fail=1; \ + fi;\ + if test yes = "@ENABLE_CODING_STYLE_CHECKS@"; then \ + exit "$$fail";\ + else \ + exit 0;\ + fi diff --git a/tools/check-py-style.sh b/tools/check-py-style.sh new file mode 100644 index 0000000..16a2c3a --- /dev/null +++ b/tools/check-py-style.sh @@ -0,0 +1,18 @@ +#!/bin/sh +fail=0 + +/bin/sh "${top_srcdir}"/tools/check-whitespace.sh "$@" || fail=$? + +# at the moment we're not actually checking much Python style here... +# to be added + +if test -n "$CHECK_FOR_LONG_LINES" +then + if egrep -n '.{80,}' "$@" + then + echo "^^^ The above files contain long lines" + fail=1 + fi +fi + +exit $fail diff --git a/tools/check-whitespace.sh b/tools/check-whitespace.sh new file mode 100644 index 0000000..5348331 --- /dev/null +++ b/tools/check-whitespace.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +fail=0 + +if grep -n ' $' "$@" +then + echo "^^^ The above files contain unwanted trailing spaces" + fail=1 +fi + +if grep -n ' ' "$@" +then + echo "^^^ The above files contain tabs" + fail=1 +fi + +exit $fail -- 2.11.4.GIT