[json-glib] Use lcov instead of gcov for test coverage reports



commit 9fd65a138d6ec46b94eaf807f9c87ea5ada11cf0
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Sat Jun 30 14:04:31 2012 +0100

    Use lcov instead of gcov for test coverage reports
    
    With lcov we get nicer reporting tools, with HTML output.

 .gitignore                       |    2 +
 Makefile.am                      |   26 ++++++++-
 README.md                        |    1 +
 build/autotools/Makefile.am      |    1 -
 build/autotools/Makefile.am.gcov |   35 ------------
 configure.ac                     |  112 +++++++++++++++++++++++++++++++-------
 json-glib/Makefile.am            |    7 +--
 7 files changed, 120 insertions(+), 64 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 4ad056f..4b33016 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,8 @@ gtk-doc.make
 install-sh
 json-glib-1.0.pc
 json-glib.pc
+/json-lcov.info
+/json-lcov
 .deps
 .libs
 *.o
diff --git a/Makefile.am b/Makefile.am
index d0a944d..3b9edab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,5 +31,27 @@ dist-hook:
 	  echo A git checkout is required to generate a ChangeLog >&2; \
 	fi
 
-gcov:
-	( cd json-glib && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $?
+if ENABLE_GCOV
+# use recursive makes in order to ignore errors during check/perf
+lcov:
+	-$(MAKE) $(AM_MAKEFLAGS) check
+	$(MAKE) $(AM_MAKEFLAGS) genlcov
+
+# we have to massage the lcov.info file slightly to hide the effect of libtool
+# placing the objects files in the .libs/ directory separate from the *.c
+genlcov:
+	$(LTP) --directory $(top_builddir) --capture --output-file json-lcov.info --test-name JSON_TEST --no-checksum
+	$(SED) -e 's#.libs/##' < json-lcov.info > json-lcov.info.tmp
+	LANG=C $(LTP_GENHTML) --prefix $(top_builddir) --output-directory json-lcov --title "JSON-GLib Code Coverage" --show-details json-lcov.info.tmp
+	rm -f json-lcov.info.tmp
+
+lcov-clean:
+	-$(LTP) --directory $(top_builddir) -z
+	-$(RM) -rf json-lcov.info json-lcov
+else
+lcov genlcov lcov-clean:
+	@echo You need to configure JSON-GLib with support for gcov enabled.
+	@echo e.g., ./configure --enable-gcov
+endif
+
+.PHONY: lcov genlcov lcov-clean
diff --git a/README.md b/README.md
index b2ff9e3..cfbbd02 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ In order to build JSON-GLib you will need:
 Optionally, JSON-GLib depends on:
 
  * GObject-Introspection â 0.9.5
+ * LCov â 1.6
 
 INSTALLATION
 -------------
diff --git a/build/autotools/Makefile.am b/build/autotools/Makefile.am
index cc2d11c..ca20ec7 100644
--- a/build/autotools/Makefile.am
+++ b/build/autotools/Makefile.am
@@ -6,7 +6,6 @@ EXTRA_DIST = \
 	Makefile.am.enums	\
 	Makefile.am.marshal	\
 	Makefile.am.gtest	\
-	Makefile.am.gcov	\
 	Makefile.am.gitignore
 
 # needed to avoid including Makefile.am.gtest
diff --git a/configure.ac b/configure.ac
index ec9a79d..f2d197c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,8 @@ LT_INIT([disable-static])
 # Honor aclocal flags
 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
 
+dnl === Versioning ============================================================
+
 JSON_MAJOR_VERSION=json_major_version
 JSON_MINOR_VERSION=json_minor_version
 JSON_MICRO_VERSION=json_micro_version
@@ -64,6 +66,8 @@ JSON_LT_AGE=lt_age
 JSON_LT_VERSION="$JSON_LT_CURRENT:$JSON_LT_REVISION:$JSON_LT_AGE"
 JSON_LT_LDFLAGS="-version-info $JSON_LT_VERSION"
 
+dnl === Platform checks =======================================================
+
 AC_CANONICAL_HOST
 AC_MSG_CHECKING([if building for some Win32 platform])
 AS_CASE([$host],
@@ -80,16 +84,16 @@ AC_MSG_RESULT([$platform_win32])
 
 AC_SUBST(JSON_LT_LDFLAGS)
 
+dnl === Dependencies ==========================================================
+
 GLIB_PREFIX="`$PKG_CONFIG --variable=prefix glib-2.0`"
 AC_SUBST(GLIB_PREFIX)
 
 PKG_CHECK_MODULES(JSON, [gobject-2.0 >= glib_req_version gio-2.0])
-AC_SUBST(JSON_CFLAGS)
-AC_SUBST(JSON_LIBS)
 
 AM_CONDITIONAL(ENABLE_GLIB_TEST, [test "x$enable_glibtest" = "xyes"])
 
-dnl = Enable debug level ======================================================
+dnl === Enable debug level ====================================================
 
 m4_define([debug_default], [m4_if(m4_eval(json_minor_version % 2), [1], [yes], [minimum])])
 
@@ -122,7 +126,7 @@ AS_CASE([$enable_debug],
 
 AC_SUBST(JSON_DEBUG_CFLAGS)
 
-dnl = Enable strict compiler flags ============================================
+dnl === Enable strict compiler flags ==========================================
 
 # use strict compiler flags only on development releases
 m4_define([maintainer_flags_default], [m4_if(m4_eval(json_minor_version % 2), [1], [yes], [no])])
@@ -145,30 +149,91 @@ AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
 MAINTAINER_CFLAGS="${MAINTAINER_CFLAGS#*  }"
 AC_SUBST([MAINTAINER_CFLAGS])
 
-dnl = GCOV coverage checks ====================================================
-AC_MSG_CHECKING([whether to build with gcov testing])
+dnl === Test coverage =========================================================
+
 AC_ARG_ENABLE([gcov],
-              [AS_HELP_STRING([--enable-gcov],
-                              [Whether to enable coverage testing (requires gcc and gcov)])],
-              [],
-              [enable_gcov=no])
+              [AS_HELP_STRING([--enable-gcov], [Enable gcov])],
+              [use_gcov=$enableval],
+              [use_gcov=no])
 
-AS_IF([test "x$enable_gcov" = "xyes" && test "x$GCC" = "xyes"],
+AS_IF([test "x$use_gcov" = "xyes"],
       [
-        GCOV_CFLAGS="$CFLAGS -O0 -g -fprofile-arcs -ftest-coverage"
-        GCOV_LDFLAGS="$LDFLAGS -lgcov"
-      ]
-)
-
-AM_CONDITIONAL([GCOV_ENABLED], [test "x$enable_gcov" = "xyes"])
-AC_SUBST([GCOV_CFLAGS])
-AC_SUBST([GCOV_LDFLAGS])
-AC_MSG_RESULT([$enable_gcov])
+        dnl we need gcc:
+        AS_IF([test "$GCC" != "yes"], [AC_MSG_ERROR([GCC is required for --enable-gcov])])
+
+        dnl Check if ccache is being used
+        AC_CHECK_PROG(SHTOOL, shtool, shtool)
+        AS_CASE([`$SHTOOL path $CC`],
+                [*ccache*], [gcc_ccache=yes],
+                [gcc_ccache=no])
+
+        if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then
+          AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.])
+        fi
+
+        ltp_version_list="1.6 1.7 1.8 1.9"
+        AC_CHECK_PROG(LTP, lcov, lcov)
+        AC_CHECK_PROG(LTP_GENHTML, genhtml, genhtml)
+
+        if test "$LTP"; then
+          AC_CACHE_CHECK([for ltp version], json_cv_ltp_version,
+                         [
+                           json_cv_ltp_version=invalid
+                           ltp_version=`$LTP -v 2>/dev/null | $SED -e 's/^.* //'`
+                           for ltp_check_version in $ltp_version_list; do
+                             if test "$ltp_version" = "$ltp_check_version"; then
+                               json_cv_ltp_version="$ltp_check_version (ok)"
+                             fi
+                           done
+                         ])
+        else
+          ltp_msg="To enable code coverage reporting you must have one of the following LTP versions installed: $ltp_version_list"
+          AC_MSG_ERROR([$ltp_msg])
+        fi
+
+        case $json_cv_ltp_version in
+          ""|invalid[)]
+          ltp_msg="You must have one of the following versions of LTP: $ltp_version_list (found: $ltp_version)."
+          AC_MSG_ERROR([$ltp_msg])
+          LTP="exit 0;"
+          ;;
+        esac
+
+        if test -z "$LTP_GENHTML"; then
+          AC_MSG_ERROR([Could not find genhtml from the LTP package])
+        fi
+
+        AC_DEFINE(HAVE_GCOV, 1, [Whether you have gcov])
+
+        dnl Remove all optimization flags from CFLAGS
+        changequote({,})
+        CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'`
+        JSON_CFLAGS=`echo "$JSON_CFLAGS" | $SED -e 's/-O[0-9]*//g'`
+        changequote([,])
+
+        dnl Define the special gcc flags
+        JSON_GCOV_CFLAGS="-O0 -fprofile-arcs -ftest-coverage"
+        JSON_GCOV_LDADD="-lgcov"
+
+        AC_SUBST(JSON_GCOV_CFLAGS)
+        AC_SUBST(JSON_GCOV_LDADD)
+
+        JSON_CFLAGS="$JSON_CFLAGS $CLUTTER_GCOV_CFLAGS"
+        JSON_LIBS="$JSON_LIBS $CLUTTER_GCOV_LDADD"
+      ])
+
+AM_CONDITIONAL(ENABLE_GCOV, test "x$use_gcov" = "xyes")
+
+dnl === Documentation =========================================================
 
 GTK_DOC_CHECK([1.13], [--flavour no-tmpl])
 
+dnl === Introspection =========================================================
+
 GOBJECT_INTROSPECTION_CHECK([0.9.5])
 
+dnl === Localization ==========================================================
+
 AM_GNU_GETTEXT_VERSION([0.18])
 AM_GNU_GETTEXT([external])
 
@@ -179,6 +244,11 @@ AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],
                    [The prefix for our gettext translation domains.])
 AS_ALL_LINGUAS
 
+dnl === Output ================================================================
+
+AC_SUBST(JSON_CFLAGS)
+AC_SUBST(JSON_LIBS)
+
 AC_CONFIG_FILES([
         Makefile
 
@@ -218,5 +288,5 @@ echo " â API reference: ${enable_gtk_doc}"
 echo ""
 echo " â Enable test suite: ${enable_glibtest}"
 echo " â Build introspection data: ${enable_introspection}"
-echo " â Enable coverage test: ${enable_gcov}"
+echo " â Enable test coverage: ${use_gcov}"
 echo ""
diff --git a/json-glib/Makefile.am b/json-glib/Makefile.am
index f2ee4ef..01969f5 100644
--- a/json-glib/Makefile.am
+++ b/json-glib/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = \
 	$(JSON_DEBUG_CFLAGS) 		\
 	$(NULL)
 
-AM_CFLAGS = $(JSON_CFLAGS) $(MAINTAINER_CFLAGS) $(GCOV_CFLAGS)
+AM_CFLAGS = $(JSON_CFLAGS) $(MAINTAINER_CFLAGS) $(JSON_GCOV_CFLAGS)
 
 BUILT_SOURCES =
 
@@ -78,7 +78,7 @@ lib_LTLIBRARIES = libjson-glib-1.0.la
 
 libjson_glib_1_0_la_LIBADD = $(JSON_LIBS)
 libjson_glib_1_0_la_SOURCES = $(source_c) $(source_h) $(source_h_private) $(BUILT_SOURCES)
-libjson_glib_1_0_la_LDFLAGS = $(JSON_LT_LDFLAGS) $(GCOV_LDFLAGS) -export-dynamic -export-symbols-regex "^json.*" -rpath $(libdir)
+libjson_glib_1_0_la_LDFLAGS = $(JSON_LT_LDFLAGS) $(JSON_GCOV_LDADD) -export-dynamic -export-symbols-regex "^json.*" -rpath $(libdir)
 
 jsonincludedir = $(includedir)/json-glib-1.0/json-glib
 jsoninclude_DATA = \
@@ -155,6 +155,3 @@ dist-hook: ../build/win32/vs9/json-glib.vcproj ../build/win32/vs10/json-glib.vcx
 DISTCLEANFILES += ../build/win32/vs9/json-glib.vcproj	\
 		  ../build/win32/vs10/json-glib.vcxproj	\
 		  ../build/win32/vs10/json-glib.vcxproj.filters
-
-gcov_sources = $(source_c)
-include $(top_srcdir)/build/autotools/Makefile.am.gcov



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]