[vala] testrunner: Check if compiler flags are supported before using them



commit f08c9f7d1fa1df1d1fd6673785ca1764dc5c8046
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Nov 3 17:29:21 2018 +0100

    testrunner: Check if compiler flags are supported before using them
    
    Use AX_CHECK_COMPILE_FLAG to collect TEST_CFLAGS in configure.

 configure.ac                | 29 +++++++++++++++++++++++++++++
 tests/Makefile.am           | 11 +++++++----
 tests/testrunner.sh         | 25 ++++++-------------------
 valadoc/tests/Makefile.am   |  6 ++++--
 valadoc/tests/testrunner.sh | 18 ++++--------------
 5 files changed, 50 insertions(+), 39 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9d1c97417..6496a7fbf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,6 +106,35 @@ AC_SUBST(COVERAGE_VALAFLAGS)
 AC_SUBST(COVERAGE_CFLAGS)
 AC_SUBST(COVERAGE_LIBS)
 
+
+# Check supported compiler flags used in testrunner.sh
+TEST_EXTRA_CFLAGS="-Werror=init-self \
+-Werror=implicit \
+-Werror=pointer-arith \
+-Werror=redundant-decls \
+-Werror=return-type \
+-Werror=sequence-point \
+-Werror=uninitialized \
+-Werror=int-to-pointer-cast \
+-Werror=pointer-to-int-cast \
+-Wformat=2 \
+-Werror=format-security \
+-Werror=format-nonliteral \
+-Werror=int-conversion \
+-Werror=duplicated-branches \
+-Werror=duplicated-cond \
+-Werror=declaration-after-statement \
+-Werror=maybe-uninitialized \
+-Werror=enum-conversion"
+
+TEST_CFLAGS=
+for flag in $TEST_EXTRA_CFLAGS; do
+       AX_CHECK_COMPILE_FLAG([$flag],[TEST_CFLAGS="$TEST_CFLAGS $flag"])
+done
+
+AC_SUBST(TEST_CFLAGS)
+
+
 GLIB_REQUIRED=2.40.0
 LIBGVC_REQUIRED=2.16
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 34bedbdb7..fd0d24675 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,7 @@ BUILT_SOURCES = \
 noinst_PROGRAMS = \
        $(NULL)
 
-TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
$(srcdir)/testrunner.sh
+TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
TEST_CFLAGS='$(TEST_CFLAGS)' $(srcdir)/testrunner.sh
 
 TESTS = \
        basic-types/integers.vala \
@@ -637,11 +637,14 @@ LINUX_TESTS = \
        $(NULL)
 
 check-TESTS: $(TESTS) $(NON_NULL_TESTS)
-       @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
$(srcdir)/testrunner.sh $(TESTS)
+       @EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
TEST_CFLAGS='$(TEST_CFLAGS)' \
+               $(srcdir)/testrunner.sh $(TESTS)
 if HAVE_LINUX
-       @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
VALAFLAGS="--pkg linux" $(srcdir)/testrunner.sh $(LINUX_TESTS)
+       @EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
TEST_CFLAGS='$(TEST_CFLAGS)' \
+               VALAFLAGS="--pkg linux" $(srcdir)/testrunner.sh $(LINUX_TESTS)
 endif
-       @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
VALAFLAGS="--enable-experimental-non-null" $(srcdir)/testrunner.sh $(NON_NULL_TESTS)
+       @EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' 
TEST_CFLAGS='$(TEST_CFLAGS)' \
+               VALAFLAGS="--enable-experimental-non-null" $(srcdir)/testrunner.sh $(NON_NULL_TESTS)
 
 EXTRA_DIST = \
        testrunner.sh \
diff --git a/tests/testrunner.sh b/tests/testrunner.sh
index f40b5c11b..f90cba7bc 100755
--- a/tests/testrunner.sh
+++ b/tests/testrunner.sh
@@ -37,28 +37,15 @@ VALAFLAGS="$VALAFLAGS \
        -X -O0 \
        -X -pipe \
        -X -lm \
-       -X -DGETTEXT_PACKAGE=\\\"valac\\\" \
-       -X -Werror=return-type \
-       -X -Werror=init-self \
-       -X -Werror=implicit \
-       -X -Werror=sequence-point \
-       -X -Werror=return-type \
-       -X -Werror=uninitialized \
-       -X -Werror=pointer-arith \
-       -X -Werror=int-to-pointer-cast \
-       -X -Werror=pointer-to-int-cast \
-       -X -Wformat \
-       -X -Werror=format-security \
-       -X -Werror=format-nonliteral \
-       -X -Werror=redundant-decls \
-       -X -Werror=duplicated-branches \
-       -X -Werror=duplicated-cond \
-       -X -Werror=declaration-after-statement \
-       -X -Werror=maybe-uninitialized \
-       -X -Werror=int-conversion"
+       -X -DGETTEXT_PACKAGE=\\\"valac\\\""
 VAPIGEN=$topbuilddir/vapigen/vapigen$EXEEXT
 VAPIGENFLAGS="--vapidir $vapidir"
 
+# Incorporate the TEST_CFLAGS.
+for cflag in ${TEST_CFLAGS}; do
+    VALAFLAGS="${VALAFLAGS} -X ${cflag}"
+done
+
 # Incorporate the user's CFLAGS. Matters if the user decided to insert
 # -m32 in CFLAGS, for example.
 for cflag in ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
diff --git a/valadoc/tests/Makefile.am b/valadoc/tests/Makefile.am
index 1c111295f..f7cdf73f8 100644
--- a/valadoc/tests/Makefile.am
+++ b/valadoc/tests/Makefile.am
@@ -2,7 +2,8 @@ include $(top_srcdir)/Makefile.common
 
 NULL =
 
-TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) PACKAGE_SUFFIX=$(PACKAGE_SUFFIX) TOPBUILDDIR=$(abs_top_builddir) 
TOPSRCDIR=$(abs_top_srcdir) $(srcdir)/testrunner.sh
+TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) PACKAGE_SUFFIX=$(PACKAGE_SUFFIX) TOPBUILDDIR=$(abs_top_builddir) 
TOPSRCDIR=$(abs_top_srcdir) \
+       CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' TEST_CFLAGS='$(TEST_CFLAGS)' 
$(srcdir)/testrunner.sh
 
 TESTS = \
        libvaladoc/errorreporter.vala \
@@ -16,7 +17,8 @@ TESTS = \
        $(NULL)
 
 check-TESTS: $(TESTS)
-       @EXEEXT=$(EXEEXT) PACKAGE_SUFFIX=$(PACKAGE_SUFFIX) TOPBUILDDIR=$(abs_top_builddir) 
TOPSRCDIR=$(abs_top_srcdir) $(srcdir)/testrunner.sh $(TESTS)
+       @EXEEXT=$(EXEEXT) PACKAGE_SUFFIX=$(PACKAGE_SUFFIX) TOPBUILDDIR=$(abs_top_builddir) 
TOPSRCDIR=$(abs_top_srcdir) \
+               CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' TEST_CFLAGS='$(TEST_CFLAGS)' 
$(srcdir)/testrunner.sh $(TESTS)
        G_DEBUG=fatal_warnings $(builddir)/driver
 
 AM_CFLAGS = \
diff --git a/valadoc/tests/testrunner.sh b/valadoc/tests/testrunner.sh
index 34eb5ca2c..60609f757 100755
--- a/valadoc/tests/testrunner.sh
+++ b/valadoc/tests/testrunner.sh
@@ -42,20 +42,6 @@ VALAFLAGS="$VALAFLAGS \
        -X -O0 \
        -X -pipe \
        -X -lm \
-       -X -Werror=return-type \
-       -X -Werror=init-self \
-       -X -Werror=implicit \
-       -X -Werror=sequence-point \
-       -X -Werror=return-type \
-       -X -Werror=uninitialized \
-       -X -Werror=pointer-arith \
-       -X -Werror=int-to-pointer-cast \
-       -X -Werror=pointer-to-int-cast \
-       -X -Wformat \
-       -X -Werror=format-security \
-       -X -Werror=format-nonliteral \
-       -X -Werror=redundant-decls \
-       -X -Werror=int-conversion \
        -X -L$topbuilddir/vala/.libs -X -lvala$PACKAGE_SUFFIX \
        -X -L$topbuilddir/libvaladoc/.libs -X -lvaladoc$PACKAGE_SUFFIX \
        -X -I$topsrcdir/gee \
@@ -63,6 +49,10 @@ VALAFLAGS="$VALAFLAGS \
        -X -I$topsrcdir/libvaladoc \
        $topsrcdir/valadoc/tests/libvaladoc/parser/generic-scanner.vala"
 
+# Incorporate the TEST_CFLAGS.
+for cflag in ${TEST_CFLAGS}; do
+    VALAFLAGS="${VALAFLAGS} -X ${cflag}"
+done
 
 # Incorporate the user's CFLAGS. Matters if the user decided to insert
 # -m32 in CFLAGS, for example.


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