Added:
authorRob Taylor <rob.taylor@codethink.co.uk>
Fri, 8 Feb 2008 18:09:05 +0000 (18:09 +0000)
committerRobert James Taylor <robtaylor@src.gnome.org>
Fri, 8 Feb 2008 18:09:05 +0000 (18:09 +0000)
2008-02-08  Rob Taylor  <rob.taylor@codethink.co.uk>

* Makefile.am:
* configure.ac:
* gcov.mak: Added:
* girepository/Makefile.am:
* m4/Makefile.am: Added:
* m4/as-compiler-flag.m4: Added:
* m4/gcov.m4: Added:
* tools/Makefile.am:
Add ability to generate a coverage report.
Adds configure option --enable-gcov and make rule 'check-coverage'.

svn path=/trunk/; revision=105

ChangeLog
Makefile.am
configure.ac
gcov.mak [new file with mode: 0644]
girepository/Makefile.am
m4/Makefile.am [new file with mode: 0644]
m4/as-compiler-flag.m4 [new file with mode: 0644]
m4/gcov.m4 [new file with mode: 0644]
tools/Makefile.am

index 6caf88386a42bed09536c62ad470bb5f10e2cd00..d430817219eb6dada9543684eef4b96ea875ca43 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-02-08  Rob Taylor  <rob.taylor@codethink.co.uk>
+
+       * Makefile.am:
+       * configure.ac:
+       * gcov.mak: Added:
+       * girepository/Makefile.am:
+       * m4/Makefile.am: Added:
+       * m4/as-compiler-flag.m4: Added:
+       * m4/gcov.m4: Added:
+       * tools/Makefile.am:
+       Add ability to generate a coverage report.
+       Adds configure option --enable-gcov and make rule 'check-coverage'.
+
 2008-02-08  Rob Taylor  <rob.taylor@codethink.co.uk>
 
        * Makefile.am:
index 8a336995b03e20ae1db33ad476bf66e57e5102be..978d2c09e0ac2091dbcb86a25b871569bc9d9100 100644 (file)
@@ -1,7 +1,45 @@
 ## Process this file with automake to produce Makefile.in
-
+DIST_SUBDIRS = m4
 SUBDIRS = gidl girepository tools tests
+ACLOCAL_AMFLAGS = -I m4
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gobject-introspection.pc
 EXTRA_DIST = $(pkgconfig_DATA)
+
+if GI_GCOV_ENABLED
+GCOV_DIRS = girepository tools
+
+clean-gcov:
+       find  -name "*.gcda" -o -name "*.gcov" -delete
+
+clean-gcno:
+       find  -name "*.gcno" -delete
+
+.PHONEY: gcov-all
+gcov-all:
+       @for dir in $(GCOV_DIRS); do \
+               cd $(abs_srcdir)/$$dir && \
+               for file in *.c; do \
+                       gcov -f -p -o `find $(abs_builddir)/$$dir -newer $$file -name "*-$${file/.c/.gcda}" -print0 | sed -e 's/\.gcda/\.o/'` $$file > /dev/null; \
+               done \
+       done
+       
+.PHONEY: coverage-report.txt
+coverage-report.txt: clean clean-gcov all check gcov-all
+       @rm  -f $(top_builddir)/coverage-report.txt
+       @echo -e "=== Coverage Report ===\n" >> $(top_builddir)/coverage-report.txt
+       @for dir in $(GCOV_DIRS); do \
+               echo "Module '$$dir':" >> $(top_builddir)/coverage-report.txt; \
+               $(MAKE) -C $$dir coverage-report; \
+       done
+
+check-coverage: coverage-report.txt
+       @cat $(top_builddir)/coverage-report.txt
+
+else
+
+check-coverage:
+       @echo "Need to reconfigure with --enable-gcov"
+
+endif
index 44fe0ab1069087c075d4c16271888053b664c29a..906b23992729d78241cb3416f64ed80e0ab09e40 100644 (file)
@@ -8,6 +8,8 @@ AM_MAINTAINER_MODE
 AC_CONFIG_SRCDIR([girepository/ginvoke.c])
 AC_CONFIG_HEADER([config.h])
 
+AC_CONFIG_MACRO_DIR([m4])
+
 # Checks for programs.
 AC_PROG_CC
 AM_PROG_CC_C_O
@@ -25,6 +27,8 @@ if test "$YACC" = :; then
 fi
 
 # Checks for libraries.
+GI_ENABLE_GCOV
+
 AC_CHECK_LIB([dl], [dlopen])
 
 PKG_CHECK_MODULES(GOBJECT, [gobject-2.0])
@@ -74,6 +78,7 @@ if test "$have_ffi_h" = "yes"; then
    GIREPO_LIBS="$GIREPO_LIBS $FFI_LIBS"
 fi
 
+GIREPO_CFLAGS="$GIREPO_CFLAGS $GCOV_CFLAGS"
 
 # Checks for header files.
 AC_HEADER_STDC
@@ -86,9 +91,11 @@ AC_C_CONST
 AC_FUNC_STRTOD
 AC_CHECK_FUNCS([memchr strchr strspn strstr strtol strtoull])
 
+
 AC_CONFIG_FILES([Makefile
-                gidl/Makefile
+                 gidl/Makefile
                  girepository/Makefile
+                 m4/Makefile
                  tools/Makefile
                  tests/Makefile
                  tests/invoke/Makefile
diff --git a/gcov.mak b/gcov.mak
new file mode 100644 (file)
index 0000000..7494678
--- /dev/null
+++ b/gcov.mak
@@ -0,0 +1,21 @@
+if GI_GCOV_ENABLED
+
+.PHONEY: coverage-report
+coverage-report:
+       @total_covered=0; total_lines=0; \
+       for file in $(GCOV_SOURCES); do \
+               if test -f $$file.gcov; then \
+                       covered=`grep -e '[0-9]\+:' $$file.gcov | wc -l` ; \
+                       uncovered=`grep '#####:' $$file.gcov | wc -l`; \
+                       lines=$$(($$covered + $$uncovered)); \
+                       total_covered=$$((total_covered + covered)); \
+                       total_lines=$$((total_lines + lines)); \
+                       echo -n "    $$file: $$covered / $$lines"; \
+                       echo " ($$((($$covered * 100) / $$lines))%)"; \
+               fi \
+       done >> $(top_builddir)/coverage-report.txt; \
+       echo -e "  Total coverage:"\
+            "$$((($$total_covered * 100) / $$total_lines))%\n" \
+            >> $(top_builddir)/coverage-report.txt
+
+endif
index 480e95f6a0b88ab9b3c32729576b7a8212e3a7bc..c79606efb73807e9d69e475d471388598d2d6cd7 100644 (file)
@@ -14,3 +14,6 @@ libgirepository_la_CFLAGS = $(GIREPO_CFLAGS)
 
 girepodir = $(includedir)/glib-2.0/gobject-introspection
 girepo_HEADERS = girepository.h
+
+GCOV_SOURCES = $(libgirepository_la_SOURCES)
+include $(top_srcdir)/gcov.mak
diff --git a/m4/Makefile.am b/m4/Makefile.am
new file mode 100644 (file)
index 0000000..c2095e8
--- /dev/null
@@ -0,0 +1 @@
+EXTRA_DIST=gcov.m4 as-compiler.m4
diff --git a/m4/as-compiler-flag.m4 b/m4/as-compiler-flag.m4
new file mode 100644 (file)
index 0000000..aba31b1
--- /dev/null
@@ -0,0 +1,33 @@
+dnl as-compiler-flag.m4 0.1.0
+
+dnl autostars m4 macro for detection of compiler flags
+
+dnl David Schleef <ds@schleef.org>
+
+dnl $Id: as-compiler-flag.m4,v 1.1 2004/06/01 09:33:45 thomasvs Exp $
+
+dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CFLAGS.
+dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
+dnl and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([AS_COMPILER_FLAG],
+[
+  AC_MSG_CHECKING([to see if compiler understands $1])
+
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS $1"
+
+  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+  CFLAGS="$save_CFLAGS"
+
+  if test "X$flag_ok" = Xyes ; then
+    $2
+    true
+  else
+    $3
+    true
+  fi
+  AC_MSG_RESULT([$flag_ok])
+])
+
diff --git a/m4/gcov.m4 b/m4/gcov.m4
new file mode 100644 (file)
index 0000000..c96edda
--- /dev/null
@@ -0,0 +1,47 @@
+AC_DEFUN([GI_ENABLE_GCOV],
+[
+  AC_ARG_ENABLE(gcov,
+    AC_HELP_STRING([--enable-gcov],
+      [compile with coverage profiling instrumentation (gcc only)]),
+    enable_gcov=$enableval,
+    enable_gcov=no)
+  if test x$enable_gcov = xyes ; then
+    if test "x$GCC" != "xyes"
+    then
+      AC_MSG_ERROR([gcov only works if gcc is used])
+    fi
+
+    AS_COMPILER_FLAG(["-fprofile-arcs"],
+      [GCOV_CFLAGS="$GCOV_CFLAGS -fprofile-arcs"],
+      true)
+    AS_COMPILER_FLAG(["-ftest-coverage"],
+      [GCOV_CFLAGS="$GCOV_CFLAGS -ftest-coverage"],
+      true)
+    dnl libtool 1.5.22 and lower strip -fprofile-arcs from the flags
+    dnl passed to the linker, which is a bug; -fprofile-arcs implicitly
+    dnl links in -lgcov, so we do it explicitly here for the same effect
+    GCOV_LIBS=-lgcov
+    AC_SUBST(GCOV_CFLAGS)
+    AC_SUBST(GCOV_LIBS)
+    GCOV=`echo $CC | sed s/gcc/gcov/g`
+    AC_SUBST(GCOV)
+
+    GI_GCOV_ENABLED=yes
+    AC_DEFINE_UNQUOTED(GI_GCOV_ENABLED, 1,
+      [Defined if gcov is enabled to force a rebuild due to config.h changing])
+    dnl if gcov is used, we do not want default -O2 CFLAGS
+    if test "x$GI_GCOV_ENABLED" = "xyes"
+    then
+      CFLAGS="-g -O0"
+      AC_SUBST(CFLAGS)
+      CXXFLAGS="-g -O0"
+      AC_SUBST(CXXFLAGS)
+      FFLAGS="-g -O0"
+      AC_SUBST(FFLAGS)
+      CCASFLAGS="-g -O0"
+      AC_SUBST(CCASFLAGS)
+      AC_MSG_NOTICE([gcov enabled, setting CFLAGS and friends to $CFLAGS])
+    fi
+  fi
+  AM_CONDITIONAL(GI_GCOV_ENABLED, test x$enable_gcov = xyes)
+])
index eb2d144faf6303ae21b33e1286ef8b2b88d27603..d28eaa2cb1e90f3ba4550c12de5030d35a62052c 100644 (file)
@@ -37,3 +37,11 @@ g_idl_scanner_SOURCES =                              \
        gidlwriter.h
 g_idl_scanner_CFLAGS = $(GIREPO_CFLAGS) $(SCANNER_CFLAGS) -I$(top_srcdir)/girepository
 g_idl_scanner_LDADD = $(GIREPO_LIBS) $(SCANNER_LIBS) $(top_builddir)/girepository/libgirepository.la libgirepository-parser.la
+
+GCOV_SOURCES =                                 \
+       $(libgirepository_la_SOURCES)           \
+       $(g_idl_compiler_SOURCES)               \
+       $(g_idl_generate_SOURCES)               \
+       $(g_idl_scanner_SOURCES)
+
+include $(top_srcdir)/gcov.mak