[gjs/wip/ptomato/autotools: 16/18] build: Use AX_CODE_COVERAGE macro



commit 88075d3d47698853a35e6e16f722416c82c335d2
Author: Philip Chimento <philip chimento gmail com>
Date:   Tue Sep 27 23:17:36 2016 -0700

    build: Use AX_CODE_COVERAGE macro
    
    Instead of the homebrew stuff, use AX_CODE_COVERAGE from the Autoconf
    Archive. We do require a few extra options in order to include the
    coverage data for the JS files.
    
    See: https://wiki.gnome.org/Initiatives/GnomeGoals/ModernAutotools

 Makefile-test.am |   35 ++++++++---------------------------
 Makefile.am      |    5 +++--
 configure.ac     |   29 +++++++----------------------
 3 files changed, 18 insertions(+), 51 deletions(-)
---
diff --git a/Makefile-test.am b/Makefile-test.am
index 029b8b1..ade9cfe 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -126,35 +126,16 @@ TESTS_ENVIRONMENT =                                                       \
        G_FILENAME_ENCODING=latin1      # ensure filenames are not utf8 \
        DBUS_UUIDGEN="$(DBUS_UUIDGEN)"
 
-if ENABLE_COVERAGE
+if CODE_COVERAGE_ENABLED
 TESTS_ENVIRONMENT += \
        GJS_UNIT_COVERAGE_OUTPUT=lcov \
        GJS_UNIT_COVERAGE_PREFIX=resource:///org/gnome/gjs/
 endif
 
-########################################################################
-if ENABLE_COVERAGE
-lcov:
-       test -d lcov || mkdir lcov
-       $(LCOV) --compat-libtool --directory . --capture -o lcov/lcov_tmp.info
-       $(LCOV) --extract lcov/lcov_tmp.info "$(PWD)/*" -o lcov/lcov.info
-       rm -f lcov/lcov_tmp.info
-       $(GENHTML) --legend -o lcov lcov/lcov.info lcov/coverage.lcov
-
-lcov-clean:
-       find . -name '*.gcda' -delete
-       rm -rf lcov
-
-lcov-realclean: lcov-clean
-       find . -name '*.gcno' -delete
-
-clean-local: lcov-realclean
-
-.PHONY: lcov lcov-clean lcov-realclean
-else
-lcov:
-       @echo >&1 "*** ERROR: 'configure --enable-coverage' required"
-       @exit 1
-
-.PHONY: lcov
-endif
+CODE_COVERAGE_IGNORE_PATTERN = */include/*
+CODE_COVERAGE_GENHTML_OPTIONS =                        \
+       lcov/coverage.lcov                              \
+       --prefix $(abs_top_builddir)/lcov/org/gnome/gjs \
+       --prefix $(abs_top_builddir)                    \
+       $(NULL)
+@CODE_COVERAGE_RULES@
diff --git a/Makefile.am b/Makefile.am
index 4b1538f..2ff8019 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,8 +16,9 @@ check_PROGRAMS = $(TEST_PROGS)
 INTROSPECTION_GIRS =
 ## ACLOCAL_AMFLAGS can be removed for Automake 1.13
 ACLOCAL_AMFLAGS = -I m4
-AM_CXXFLAGS = $(WARN_CXXFLAGS)
-AM_CPPFLAGS = -DG_LOG_DOMAIN=\"Gjs\"
+AM_CXXFLAGS = $(WARN_CXXFLAGS) $(CODE_COVERAGE_CFLAGS)
+AM_CPPFLAGS = -DG_LOG_DOMAIN=\"Gjs\" $(CODE_COVERAGE_CPPFLAGS)
+AM_LDFLAGS = $(CODE_COVERAGE_LDFLAGS)
 
 gjsjsdir = @gjsjsdir@
 gjsoverridedir = $(gjsjsdir)/overrides
diff --git a/configure.ac b/configure.ac
index 9bd8673..263bcb2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,28 +37,12 @@ LT_INIT([disable-static])
 
 GNOME_CXX_WARNINGS([maximum])
 
-# coverage
-AC_ARG_ENABLE([coverage],
-              [AS_HELP_STRING([--enable-coverage],
-                              [enable code coverage])],
-              , [enable_coverage=no])
-if test x$enable_coverage = xyes; then
-    if test x$GCC != xyes; then
-        AC_MSG_ERROR([GCC is required for --enable-coverage])
-    fi
-
-    AC_PATH_TOOL([LCOV], [lcov])
-    AC_PATH_TOOL([GENHTML], [genhtml])
-
-    if test x$LCOV = x || test x$GENHTML = x; then
-        AC_MSG_ERROR([lcov and genhtml are required for --enable-coverage])
-    fi
-
-    CFLAGS="$CFLAGS -g -O0 --coverage"
-    CXXFLAGS="$CXXFLAGS -g -O0 --coverage"
-    LIBS="$LIBS -lgcov"
-fi
-AM_CONDITIONAL([ENABLE_COVERAGE], [test x$enable_coverage = xyes])
+AX_CODE_COVERAGE
+dnl Clang does not need to link with -lgcov
+AX_CHECK_LINK_FLAG([-lgcov],, [
+       CODE_COVERAGE_LIBS=
+       CODE_COVERAGE_LDFLAGS=
+])
 
 # Checks for libraries.
 m4_define(glib_required_version, 2.42.0)
@@ -240,4 +224,5 @@ AC_MSG_RESULT([
        dtrace:                 ${ENABLE_DTRACE}
        systemtap:              ${ENABLE_SYSTEMTAP}
        Run tests under:        ${TEST_MSG}
+       Code coverage:          ${enable_code_coverage}
 ])


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