mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
Improve coverage of cpluspluscheck.
Formerly, cpluspluscheck was only meant to examine headers that we thought of as exported --- but its notion of what we export was well behind the times. Let's just make it check *all* .h files, except for a well-defined blacklist, instead. While at it, improve its ability to use a C++ compiler other than g++, by scraping the CXX setting from Makefile.global and making it possible to override the warning options used (per suggestion from Andres Freund). Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru
This commit is contained in:
parent
b1cd7ce23f
commit
6f54b80edd
@ -1,12 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Check all exported PostgreSQL include files for C++ compatibility.
|
# Check (almost) all PostgreSQL include files for C++ compatibility.
|
||||||
#
|
#
|
||||||
# Argument 1 is the top-level source directory, argument 2 the
|
# Argument 1 is the top-level source directory, argument 2 the
|
||||||
# top-level build directory (they might be the same). If not set, they
|
# top-level build directory (they might be the same). If not set, they
|
||||||
# default to the current directory.
|
# default to the current directory.
|
||||||
#
|
#
|
||||||
# Needs to be run after all generated headers are created.
|
# Needs to be run after configuring and creating all generated headers.
|
||||||
#
|
#
|
||||||
# No output if everything is OK, else compiler errors.
|
# No output if everything is OK, else compiler errors.
|
||||||
|
|
||||||
@ -17,44 +17,132 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
builddir="$."
|
builddir="."
|
||||||
else
|
else
|
||||||
builddir="$2"
|
builddir="$2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
me=`basename $0`
|
me=`basename $0`
|
||||||
|
|
||||||
|
# Pull some info from configure's results.
|
||||||
|
MGLOB="$builddir/src/Makefile.global"
|
||||||
|
CXX=`sed -n 's/^CXX[ ]*=[ ]*//p' "$MGLOB"`
|
||||||
|
perl_includespec=`sed -n 's/^perl_includespec[ ]*=[ ]*//p' "$MGLOB"`
|
||||||
|
python_includespec=`sed -n 's/^python_includespec[ ]*=[ ]*//p' "$MGLOB"`
|
||||||
|
|
||||||
|
# These switches are g++ specific, you may override if necessary.
|
||||||
|
CXXFLAGS=${CXXFLAGS:- -fsyntax-only -Wall}
|
||||||
|
|
||||||
|
# Create temp directory.
|
||||||
tmp=`mktemp -d /tmp/$me.XXXXXX`
|
tmp=`mktemp -d /tmp/$me.XXXXXX`
|
||||||
|
|
||||||
trap 'rm -rf $tmp' 0 1 2 3 15
|
trap 'rm -rf $tmp' 0 1 2 3 15
|
||||||
|
|
||||||
# Omit src/include/port/, because it's platform specific, and c.h includes
|
# Scan all of src/ and contrib/ for header files.
|
||||||
# the relevant file anyway.
|
for f in `cd "$srcdir" && find src contrib -name '*.h' -print`
|
||||||
# rusagestub.h is also platform-specific, and will be included by
|
do
|
||||||
# utils/pg_rusage.h if necessary.
|
# Ignore files that are unportable or intentionally not standalone.
|
||||||
# access/rmgrlist.h is not meant to be included standalone.
|
|
||||||
# regex/regerrs.h is not meant to be included standalone.
|
# These files are platform-specific, and c.h will include the
|
||||||
# parser/gram.h will be included by parser/gramparse.h.
|
# one that's relevant for our current platform anyway.
|
||||||
# parser/kwlist.h is not meant to be included standalone.
|
test "$f" = src/include/port/aix.h && continue
|
||||||
|
test "$f" = src/include/port/cygwin.h && continue
|
||||||
|
test "$f" = src/include/port/darwin.h && continue
|
||||||
|
test "$f" = src/include/port/freebsd.h && continue
|
||||||
|
test "$f" = src/include/port/hpux.h && continue
|
||||||
|
test "$f" = src/include/port/linux.h && continue
|
||||||
|
test "$f" = src/include/port/netbsd.h && continue
|
||||||
|
test "$f" = src/include/port/openbsd.h && continue
|
||||||
|
test "$f" = src/include/port/solaris.h && continue
|
||||||
|
test "$f" = src/include/port/win32.h && continue
|
||||||
|
|
||||||
|
# Additional Windows-specific headers.
|
||||||
|
test "$f" = src/include/port/win32_port.h && continue
|
||||||
|
test "$f" = src/include/port/win32/sys/socket.h && continue
|
||||||
|
test "$f" = src/include/port/win32_msvc/dirent.h && continue
|
||||||
|
test "$f" = src/port/pthread-win32.h && continue
|
||||||
|
|
||||||
|
# Likewise, these files are platform-specific, and the one
|
||||||
|
# relevant to our platform will be included by atomics.h.
|
||||||
|
test "$f" = src/include/port/atomics/arch-arm.h && continue
|
||||||
|
test "$f" = src/include/port/atomics/fallback.h && continue
|
||||||
|
test "$f" = src/include/port/atomics/generic.h && continue
|
||||||
|
test "$f" = src/include/port/atomics/generic-acc.h && continue
|
||||||
|
test "$f" = src/include/port/atomics/generic-gcc.h && continue
|
||||||
|
test "$f" = src/include/port/atomics/generic-msvc.h && continue
|
||||||
|
test "$f" = src/include/port/atomics/generic-xlc.h && continue
|
||||||
|
|
||||||
|
# rusagestub.h is also platform-specific, and will be included
|
||||||
|
# by utils/pg_rusage.h if necessary.
|
||||||
|
test "$f" = src/include/rusagestub.h && continue
|
||||||
|
|
||||||
|
# sepgsql.h depends on headers that aren't there on most platforms.
|
||||||
|
test "$f" = contrib/sepgsql/sepgsql.h && continue
|
||||||
|
|
||||||
|
# These files are not meant to be included standalone, because
|
||||||
|
# they contain lists that might have multiple use-cases.
|
||||||
|
test "$f" = src/include/access/rmgrlist.h && continue
|
||||||
|
test "$f" = src/include/parser/kwlist.h && continue
|
||||||
|
test "$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h && continue
|
||||||
|
test "$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h && continue
|
||||||
|
test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue
|
||||||
|
test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue
|
||||||
|
test "$f" = src/include/regex/regerrs.h && continue
|
||||||
|
test "$f" = src/pl/plpgsql/src/plerrcodes.h && continue
|
||||||
|
test "$f" = src/pl/plpython/spiexceptions.h && continue
|
||||||
|
test "$f" = src/pl/tcl/pltclerrcodes.h && continue
|
||||||
|
|
||||||
|
# We can't make these Bison output files compilable standalone
|
||||||
|
# without using "%code require", which old Bison versions lack.
|
||||||
|
# parser/gram.h will be included by parser/gramparse.h anyway.
|
||||||
|
test "$f" = src/include/parser/gram.h && continue
|
||||||
|
test "$f" = src/backend/parser/gram.h && continue
|
||||||
|
test "$f" = src/pl/plpgsql/src/pl_gram.h && continue
|
||||||
|
test "$f" = src/interfaces/ecpg/preproc/preproc.h && continue
|
||||||
|
|
||||||
|
# ppport.h is not under our control, so we can't make it standalone.
|
||||||
|
test "$f" = src/pl/plperl/ppport.h && continue
|
||||||
|
|
||||||
|
# regression.h is not actually C, but ECPG code.
|
||||||
|
test "$f" = src/interfaces/ecpg/test/regression.h && continue
|
||||||
|
|
||||||
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
|
# pg_trace.h and utils/probes.h can include sys/sdt.h from SystemTap,
|
||||||
# which itself contains C++ code and so won't compile with a C++
|
# which itself contains C++ code and so won't compile with a C++
|
||||||
# compiler under extern "C" linkage.
|
# compiler under extern "C" linkage.
|
||||||
|
test "$f" = src/include/pg_trace.h && continue
|
||||||
|
test "$f" = src/include/utils/probes.h && continue
|
||||||
|
|
||||||
for f in `cd "$srcdir" && find src/include src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-events.h -name '*.h' -print | \
|
# pg_dump is not C++-clean because it uses "public" and "namespace"
|
||||||
grep -v -e ^src/include/port/ \
|
# as field names, which is unfortunate but we won't change it now.
|
||||||
-e ^src/include/rusagestub.h -e ^src/include/regex/regerrs.h \
|
test "$f" = src/bin/pg_dump/compress_io.h && continue
|
||||||
-e ^src/include/access/rmgrlist.h \
|
test "$f" = src/bin/pg_dump/parallel.h && continue
|
||||||
-e ^src/include/parser/gram.h -e ^src/include/parser/kwlist.h \
|
test "$f" = src/bin/pg_dump/pg_backup_archiver.h && continue
|
||||||
-e ^src/include/pg_trace.h -e ^src/include/utils/probes.h`
|
test "$f" = src/bin/pg_dump/pg_dump.h && continue
|
||||||
do
|
|
||||||
|
# OK, create .c file to include this .h file.
|
||||||
{
|
{
|
||||||
echo 'extern "C" {'
|
echo 'extern "C" {'
|
||||||
test $f != "src/include/postgres_fe.h" && echo '#include "postgres.h"'
|
test "$f" != src/include/postgres_fe.h && echo '#include "postgres.h"'
|
||||||
echo "#include \"$f\""
|
echo "#include \"$f\""
|
||||||
echo '};'
|
echo '};'
|
||||||
} >$tmp/test.cpp
|
} >$tmp/test.cpp
|
||||||
|
|
||||||
${CXX:-g++} -I $srcdir -I $srcdir/src/interfaces/libpq -I $srcdir/src/include \
|
# Some subdirectories need extra -I switches.
|
||||||
-I $builddir -I $builddir/src/interfaces/libpq -I $builddir/src/include \
|
case "$f" in
|
||||||
-fsyntax-only -Wall -c $tmp/test.cpp
|
src/pl/plperl/*)
|
||||||
|
EXTRAINCLUDES="$perl_includespec" ;;
|
||||||
|
src/pl/plpython/*)
|
||||||
|
EXTRAINCLUDES="$python_includespec" ;;
|
||||||
|
src/interfaces/ecpg/*)
|
||||||
|
EXTRAINCLUDES="-I $builddir/src/interfaces/ecpg/include -I $srcdir/src/interfaces/ecpg/include" ;;
|
||||||
|
*)
|
||||||
|
EXTRAINCLUDES="" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Run the test.
|
||||||
|
${CXX:-g++} -I $builddir -I $srcdir \
|
||||||
|
-I $builddir/src/include -I $srcdir/src/include \
|
||||||
|
-I $builddir/src/interfaces/libpq -I $srcdir/src/interfaces/libpq \
|
||||||
|
$EXTRAINCLUDES $CXXFLAGS -c $tmp/test.cpp
|
||||||
|
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user