Syntax check generated headers using both C and C++ compilers

For C++ tests, check header compilation using C++ compiler too, as this
detects constructs valid in C but invalid in C++ and will also be useful
for checking C++-specific parts of the headers that will be generated in
the future.
This commit is contained in:
Vadim Zeitlin 2021-11-10 17:38:20 +01:00
commit 2ab549611b
2 changed files with 22 additions and 17 deletions

View file

@ -1363,8 +1363,6 @@ C_LDSHARED = @C_LDSHARED@
CXX_LDSHARED = @CXX_LDSHARED@
C_SO = @C_SO@
SYNTAX_CHECK := $(CC) -fsyntax-only -x c
c: $(SRCDIR_SRCS)
$(SWIG) -c $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) -I$(SRCDIR) $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(INCLUDES)
@ -1385,9 +1383,14 @@ $(eval c_compile: c_compile_$(RUNME_EXT))
# This target is used for the unit tests: if we don't have any test code to
# run, we at least can check that the generated header can be included without
# giving any syntax errors.
c_syntax_check:
$(SYNTAX_CHECK) -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
# giving any syntax errors, both when compiling it as C and C++ code.
c_syntax_check: c_syntax_check_c c_syntax_check_cxx
c_syntax_check_c:
$(CC) -fsyntax-only -x c -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
c_syntax_check_cxx:
$(CXX) -fsyntax-only -x c++ -I$(SRCDIR)$(INTERFACEDIR) $(C_HEADER)
# -----------------------------------------------------------------
# Run C example

View file

@ -117,12 +117,20 @@ endef
%.cpptest:
$(setup)
+(cd $* && $(swig_and_compile_cpp))
$(run_testcase)
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*); \
fi
%.ctest:
$(setup)
+(cd $* && $(swig_and_compile_c))
$(run_testcase)
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*,_c); \
fi
%.multicpptest:
$(setup)
@ -147,12 +155,15 @@ setup = \
fi;
# Checks the header syntax if there is no runnable testcase for it.
#
# The optional second argument can be "_c" to check syntax using C compiler only
# (by default both C and C++ compilers are used).
syntax_check_testcase = \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
SRCDIR='$(SRCDIR)' \
INTERFACEDIR='$(INTERFACEDIR)' \
C_HEADER=$1_wrap.h \
c_syntax_check
c_syntax_check$2
# Compiles C files then runs the testcase unconditionally.
do_run_testcase = \
@ -163,15 +174,6 @@ do_run_testcase = \
TARGET='$*' \
c_run
# Only compile and run testcase if we have a runme for it, otherwise only check
# the syntax of the generated files.
run_testcase = \
+if [ $(call has_runme,$*) ]; then \
$(do_run_testcase); \
else \
cd $* && $(call syntax_check_testcase,$*); \
fi
# Clean: remove testcase directories
%.clean:
@if [ -d $* ]; then \