[vala] Add support for coverage analysis using gcov and lcov



commit 331d4e8d2927eb912edd9b286568376149f60322
Author: Jürg Billeter <j bitron ch>
Date:   Sat Sep 26 21:58:39 2009 +0200

    Add support for coverage analysis using gcov and lcov

 .gitignore           |    5 +++++
 Makefile.am          |   20 ++++++++++++++++++++
 ccode/Makefile.am    |    4 +++-
 codegen/Makefile.am  |    4 +++-
 compiler/Makefile.am |    4 +++-
 configure.ac         |   16 ++++++++++++++++
 gee/Makefile.am      |    4 +++-
 vala/Makefile.am     |    4 +++-
 8 files changed, 56 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 42c1298..94ed5cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,8 @@ ylwrap
 compile
 stamp-h1
 *.pc
+
+*.gcda
+*.gcno
+coverage
+lcov.info
diff --git a/Makefile.am b/Makefile.am
index e603ea9..0dfaa20 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,10 +36,30 @@ DIST_SUBDIRS = \
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = vala-1.0.pc
 
+.PHONY: bootstrap
+bootstrap: all
+	find $(top_srcdir) -name "*.vala.stamp" | xargs rm -f
+	$(MAKE) $(AM_MAKEFLAGS) all VALAC=$(abs_top_builddir)/compiler/valac
+
 .PHONY: test
 test:
 	cd tests && $(MAKE) $(AM_MAKEFLAGS) check
 
+#if ENABLE_COVERAGE
+.PHONY: coverage coverage-report
+coverage:
+	find $(top_srcdir) -name "*.gcda" | xargs rm -f
+	$(MAKE) $(AM_MAKEFLAGS) bootstrap
+	$(MAKE) $(AM_MAKEFLAGS) test
+
+coverage-report: coverage
+	lcov --directory $(top_srcdir) --capture --output-file $(top_builddir)/lcov.info
+	lcov --directory $(top_srcdir) --output-file $(top_builddir)/lcov.info --remove $(top_builddir)/lcov.info "*.c" "*.h" "*.vapi"
+	rm -r $(top_builddir)/coverage
+	$(mkdir_p) $(top_builddir)/coverage
+	genhtml --title "@PACKAGE_STRING@" --output-directory $(top_builddir)/coverage $(top_builddir)/lcov.info
+#endif
+
 dist-hook: gen-ChangeLog
 
 gen_start_date = 2009-02-25
diff --git a/ccode/Makefile.am b/ccode/Makefile.am
index af79c1f..fdc07bb 100644
--- a/ccode/Makefile.am
+++ b/ccode/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 
 AM_CPPFLAGS = \
+	$(COVERAGE_CFLAGS) \
 	-I$(top_srcdir)/gee \
 	$(GLIB_CFLAGS) \
 	$(NULL)
@@ -76,10 +77,11 @@ ccodeinclude_HEADERS = \
 	$(NULL)
 
 ccode.vapi ccode.vala.stamp: $(libvalaccode_la_VALASOURCES)
-	$(VALAC) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee -H valaccode.h --library ccode $^
+	$(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee -H valaccode.h --library ccode $^
 	touch $@
 
 libvalaccode_la_LIBADD = \
+	$(COVERAGE_LIBS) \
 	$(GLIB_LIBS) \
 	$(NULL)
 
diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index 8f9401f..902cf5d 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 
 AM_CPPFLAGS = \
+	$(COVERAGE_CFLAGS) \
 	-I$(top_srcdir)/gee \
 	-I$(top_srcdir)/ccode \
 	-I$(top_srcdir)/vala \
@@ -56,12 +57,13 @@ codegeninclude_HEADERS = \
 	$(NULL)
 
 codegen.vapi codegen.vala.stamp: $(libvala_la_VALASOURCES)
-	$(VALAC) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --vapidir ../ccode --pkg ccode --vapidir ../vala --pkg vala -H valacodegen.h --library codegen $^
+	$(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --vapidir ../ccode --pkg ccode --vapidir ../vala --pkg vala -H valacodegen.h --library codegen $^
 	touch $@
 
 libvala_la_LDFLAGS = -no-undefined
 
 libvala_la_LIBADD = \
+	$(COVERAGE_LIBS) \
 	$(GLIB_LIBS) \
 	../vala/libvalacore.la \
 	$(NULL)
diff --git a/compiler/Makefile.am b/compiler/Makefile.am
index 4cbe5ba..45e4fd7 100644
--- a/compiler/Makefile.am
+++ b/compiler/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 
 AM_CPPFLAGS = \
+	$(COVERAGE_CFLAGS) \
 	-I$(top_srcdir)/gee \
 	-I$(top_srcdir)/ccode \
 	-I$(top_srcdir)/vala \
@@ -26,10 +27,11 @@ valac_SOURCES = \
 	$(NULL)
 
 valac.vala.stamp: $(valac_VALASOURCES)
-	$(VALAC) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --vapidir ../ccode --pkg ccode --vapidir ../vala --pkg vala --vapidir ../codegen --pkg codegen --pkg config $^
+	$(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --vapidir ../ccode --pkg ccode --vapidir ../vala --pkg vala --vapidir ../codegen --pkg codegen --pkg config $^
 	touch $@
 
 valac_LDADD = \
+	$(COVERAGE_LIBS) \
 	$(GLIB_LIBS) \
 	../codegen/libvala.la \
 	$(NULL)
diff --git a/configure.ac b/configure.ac
index ec8b381..5b0b3cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,22 @@ AC_SUBST(CFLAGS)
 AC_SUBST(CPPFLAGS)
 AC_SUBST(LDFLAGS)
 
+AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [Enable coverage analysis]), enable_coverage=$enableval, enable_coverage=no)
+AM_CONDITIONAL(ENABLE_COVERAGE, test x$enable_coverage = xyes)
+
+if test "$enable_coverage" = "yes"; then
+	COVERAGE_VALAFLAGS="-g"
+	COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
+	COVERAGE_LIBS="-lgcov"
+else
+	COVERAGE_VALAFLAGS=
+	COVERAGE_CFLAGS=
+	COVERAGE_LIBS=
+fi
+AC_SUBST(COVERAGE_VALAFLAGS)
+AC_SUBST(COVERAGE_CFLAGS)
+AC_SUBST(COVERAGE_LIBS)
+
 AC_ARG_ENABLE(vapigen, AS_HELP_STRING([--enable-vapigen], [Enable VAPI generator]), enable_vapigen=$enableval, enable_vapigen=no)
 AM_CONDITIONAL(ENABLE_VAPIGEN, test x$enable_vapigen = xyes)
 
diff --git a/gee/Makefile.am b/gee/Makefile.am
index 85928fe..ece430c 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 
 AM_CPPFLAGS = \
+	$(COVERAGE_CFLAGS) \
 	$(GLIB_CFLAGS) \
 	$(NULL)
 
@@ -39,10 +40,11 @@ geeinclude_HEADERS = \
 	$(NULL)
 
 gee.vapi gee.vala.stamp: $(libgee_la_VALASOURCES)
-	$(VALAC) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 -H gee.h --library gee $^
+	$(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 -H gee.h --library gee $^
 	touch $@
 
 libgee_la_LIBADD = \
+	$(COVERAGE_LIBS) \
 	$(GLIB_LIBS) \
 	$(NULL)
 
diff --git a/vala/Makefile.am b/vala/Makefile.am
index e5bdde6..016d924 100644
--- a/vala/Makefile.am
+++ b/vala/Makefile.am
@@ -1,6 +1,7 @@
 NULL =
 
 AM_CPPFLAGS = \
+	$(COVERAGE_CFLAGS) \
 	-I$(top_srcdir)/gee \
 	-I$(top_srcdir)/ccode \
 	$(GLIB_CFLAGS) \
@@ -165,10 +166,11 @@ valainclude_HEADERS = \
 	$(NULL)
 
 vala.vapi vala.vala.stamp: $(libvalacore_la_VALASOURCES)
-	$(VALAC) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --vapidir ../ccode --pkg ccode --pkg config -H vala.h --library vala $^
+	$(VALAC) $(COVERAGE_VALAFLAGS) $(VALAFLAGS) -C --vapidir $(srcdir)/../vapi --pkg gobject-2.0 --vapidir ../gee --pkg gee --vapidir ../ccode --pkg ccode --pkg config -H vala.h --library vala $^
 	touch $@
 
 libvalacore_la_LIBADD = \
+	$(COVERAGE_LIBS) \
 	$(GLIB_LIBS) \
 	../gee/libgee.la \
 	../ccode/libvalaccode.la \



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