2019-08-19 20:22:56 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Check (almost) all PostgreSQL include files for standalone build.
|
|
|
|
#
|
|
|
|
# Argument 1 is the top-level source directory, argument 2 the
|
|
|
|
# top-level build directory (they might be the same). If not set, they
|
|
|
|
# default to the current directory.
|
|
|
|
#
|
|
|
|
# Needs to be run after configuring and creating all generated headers.
|
|
|
|
# It's advisable to configure --with-perl --with-python, else you're
|
|
|
|
# likely to get errors from associated headers.
|
|
|
|
#
|
|
|
|
# No output if everything is OK, else compiler errors.
|
|
|
|
#
|
|
|
|
# src/tools/pginclude/headerscheck
|
2024-01-04 02:49:05 +01:00
|
|
|
# Copyright (c) 2009-2024, PostgreSQL Global Development Group
|
2019-08-19 20:22:56 +02:00
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
srcdir="."
|
|
|
|
else
|
|
|
|
srcdir="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
builddir="."
|
|
|
|
else
|
|
|
|
builddir="$2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
me=`basename $0`
|
|
|
|
|
|
|
|
# Pull some info from configure's results.
|
|
|
|
MGLOB="$builddir/src/Makefile.global"
|
|
|
|
CPPFLAGS=`sed -n 's/^CPPFLAGS[ ]*=[ ]*//p' "$MGLOB"`
|
|
|
|
CFLAGS=`sed -n 's/^CFLAGS[ ]*=[ ]*//p' "$MGLOB"`
|
|
|
|
CC=`sed -n 's/^CC[ ]*=[ ]*//p' "$MGLOB"`
|
|
|
|
PG_SYSROOT=`sed -n 's/^PG_SYSROOT[ ]*=[ ]*//p' "$MGLOB"`
|
|
|
|
perl_includespec=`sed -n 's/^perl_includespec[ ]*=[ ]*//p' "$MGLOB"`
|
|
|
|
python_includespec=`sed -n 's/^python_includespec[ ]*=[ ]*//p' "$MGLOB"`
|
|
|
|
|
|
|
|
# needed on Darwin
|
|
|
|
CPPFLAGS=`echo "$CPPFLAGS" | sed "s|\\\$(PG_SYSROOT)|$PG_SYSROOT|g"`
|
|
|
|
|
|
|
|
# (EXTRAFLAGS is not set here, but user can pass it in if need be.)
|
|
|
|
|
|
|
|
# Create temp directory.
|
|
|
|
tmp=`mktemp -d /tmp/$me.XXXXXX`
|
|
|
|
|
2022-09-20 18:50:16 +02:00
|
|
|
trap "ret=$?; rm -rf $tmp; exit $ret" 0 1 2 3 15
|
2019-08-19 20:22:56 +02:00
|
|
|
|
2022-08-16 00:53:29 +02:00
|
|
|
exit_status=0
|
|
|
|
|
2019-08-19 20:22:56 +02:00
|
|
|
# Scan all of src/ and contrib/ for header files.
|
|
|
|
for f in `cd "$srcdir" && find src contrib -name '*.h' -print`
|
|
|
|
do
|
|
|
|
# Ignore files that are unportable or intentionally not standalone.
|
|
|
|
|
|
|
|
# These files are platform-specific, and c.h will include the
|
|
|
|
# one that's relevant for our current platform anyway.
|
|
|
|
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/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
|
2022-08-14 01:15:23 +02:00
|
|
|
test "$f" = src/include/port/win32/netdb.h && continue
|
2019-08-19 20:22:56 +02:00
|
|
|
test "$f" = src/include/port/win32/sys/socket.h && continue
|
|
|
|
test "$f" = src/include/port/win32_msvc/dirent.h && continue
|
2020-03-02 20:35:22 +01:00
|
|
|
test "$f" = src/include/port/win32_msvc/utime.h && continue
|
2022-01-11 22:11:50 +01:00
|
|
|
test "$f" = src/include/port/win32ntdll.h && continue
|
2019-08-19 20:22:56 +02:00
|
|
|
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/arch-hppa.h && continue
|
|
|
|
test "$f" = src/include/port/atomics/arch-ppc.h && continue
|
|
|
|
test "$f" = src/include/port/atomics/arch-x86.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-sunpro.h && continue
|
|
|
|
|
|
|
|
# sepgsql.h depends on headers that aren't there on most platforms.
|
|
|
|
test "$f" = contrib/sepgsql/sepgsql.h && continue
|
|
|
|
|
2022-07-10 01:25:53 +02:00
|
|
|
# nodetags.h cannot be included standalone: it's just a code fragment.
|
|
|
|
test "$f" = src/include/nodes/nodetags.h && continue
|
|
|
|
test "$f" = src/backend/nodes/nodetags.h && continue
|
|
|
|
|
2019-08-19 20:22:56 +02:00
|
|
|
# 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
|
2020-03-21 23:28:44 +01:00
|
|
|
test "$f" = src/include/tcop/cmdtaglist.h && continue
|
2019-08-19 20:22:56 +02:00
|
|
|
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
|
|
|
|
|
2020-01-24 12:23:06 +01:00
|
|
|
# Also not meant to be included standalone.
|
2022-09-13 11:57:15 +02:00
|
|
|
test "$f" = src/include/common/unicode_nonspacing_table.h && continue
|
2021-09-23 21:30:25 +02:00
|
|
|
test "$f" = src/include/common/unicode_east_asian_fw_table.h && continue
|
2020-01-24 12:23:06 +01:00
|
|
|
|
2024-01-23 07:13:38 +01:00
|
|
|
test "$f" = src/backend/catalog/syscache_ids.h && continue
|
|
|
|
test "$f" = src/backend/catalog/syscache_info.h && continue
|
|
|
|
test "$f" = src/include/catalog/syscache_ids.h && continue
|
|
|
|
test "$f" = src/include/catalog/syscache_info.h && continue
|
|
|
|
|
2019-08-19 20:22:56 +02:00
|
|
|
# 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.
|
2022-09-04 06:33:31 +02:00
|
|
|
test "$f" = contrib/cube/cubeparse.h && continue
|
|
|
|
test "$f" = contrib/seg/segparse.h && continue
|
|
|
|
test "$f" = src/backend/bootstrap/bootparse.h && continue
|
2019-08-19 20:22:56 +02:00
|
|
|
test "$f" = src/backend/parser/gram.h && continue
|
2022-09-04 06:33:31 +02:00
|
|
|
test "$f" = src/backend/replication/repl_gram.h && continue
|
|
|
|
test "$f" = src/backend/replication/syncrep_gram.h && continue
|
|
|
|
test "$f" = src/backend/utils/adt/jsonpath_gram.h && continue
|
|
|
|
test "$f" = src/bin/pgbench/exprparse.h && continue
|
2019-08-19 20:22:56 +02:00
|
|
|
test "$f" = src/pl/plpgsql/src/pl_gram.h && continue
|
|
|
|
test "$f" = src/interfaces/ecpg/preproc/preproc.h && continue
|
2022-09-04 06:33:31 +02:00
|
|
|
test "$f" = src/test/isolation/specparse.h && continue
|
2019-08-19 20:22:56 +02:00
|
|
|
|
|
|
|
# This produces a "no previous prototype" warning.
|
|
|
|
test "$f" = src/include/storage/checksum_impl.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
|
|
|
|
# printf_hack.h produces "unused function" warnings.
|
|
|
|
test "$f" = src/interfaces/ecpg/test/printf_hack.h && continue
|
|
|
|
|
|
|
|
# OK, create .c file to include this .h file.
|
|
|
|
{
|
Tighten header pre-inclusions in headerscheck and cpluspluscheck.
We allow our header files to depend on the appropriate one of
postgres.h, postgres_fe.h, or c.h having already been included.
However, there are a few headers such as libpq-fe.h that are
meant to be used by client applications and therefore must
compile without any assumptions about previous inclusions.
These test scripts failed to consider that, which seems quite
hazardous since we might not immediately notice such a problem
otherwise. Hence, adjust these scripts to test relevant libpq
and ecpg headers with no prior inclusion.
While at it, we can also make an effort to actually use the
relevant one of postgres.h, postgres_fe.h, or c.h. I added
some rules that guess which one to use based on the first-level
src subdirectory, e.g. use postgres_fe.h under src/bin/.
These rules are hardly water-tight but they seem to work today,
and we can always refine them in the future.
These changes don't reveal any live problems today, which is good,
but they should make these scripts more able to catch future bugs.
Discussion: https://postgr.es/m/2488193.1677863247@sss.pgh.pa.us
2023-03-04 18:11:50 +01:00
|
|
|
# Ideally we'd pre-include only the appropriate one of
|
|
|
|
# postgres.h, postgres_fe.h, or c.h. We don't always have enough
|
|
|
|
# info to guess which, but in some subdirectories there's a
|
|
|
|
# reasonable choice to make, and otherwise we use postgres.h.
|
|
|
|
# Also, those three files should compile with no pre-include, as
|
|
|
|
# should src/interfaces headers meant to be exposed to clients.
|
|
|
|
case "$f" in
|
|
|
|
src/include/postgres.h) ;;
|
|
|
|
src/include/postgres_fe.h) ;;
|
|
|
|
src/include/c.h) ;;
|
|
|
|
src/interfaces/libpq/libpq-fe.h) ;;
|
|
|
|
src/interfaces/libpq/libpq-events.h) ;;
|
|
|
|
src/interfaces/ecpg/ecpglib/ecpglib_extern.h)
|
|
|
|
echo '#include "postgres_fe.h"' ;;
|
|
|
|
src/interfaces/ecpg/ecpglib/*) ;;
|
|
|
|
src/interfaces/*)
|
|
|
|
echo '#include "postgres_fe.h"' ;;
|
|
|
|
src/bin/*)
|
|
|
|
echo '#include "postgres_fe.h"' ;;
|
|
|
|
src/fe_utils/*)
|
|
|
|
echo '#include "postgres_fe.h"' ;;
|
|
|
|
src/port/*) ;;
|
|
|
|
src/common/*)
|
|
|
|
echo '#include "c.h"' ;;
|
|
|
|
*)
|
|
|
|
echo '#include "postgres.h"' ;;
|
|
|
|
esac
|
2019-08-19 20:22:56 +02:00
|
|
|
echo "#include \"$f\""
|
|
|
|
} >$tmp/test.c
|
|
|
|
|
|
|
|
# Some subdirectories need extra -I switches.
|
|
|
|
case "$f" in
|
|
|
|
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" ;;
|
2022-09-20 18:50:16 +02:00
|
|
|
src/backend/parser/*)
|
2022-09-14 09:33:35 +02:00
|
|
|
EXTRAINCLUDES="-I $builddir/src/backend/parser/" ;;
|
2022-09-20 18:50:16 +02:00
|
|
|
src/backend/utils/adt/*)
|
2022-09-06 07:46:41 +02:00
|
|
|
EXTRAINCLUDES="-I $builddir/src/backend/utils/adt/" ;;
|
2019-08-19 20:22:56 +02:00
|
|
|
*)
|
|
|
|
EXTRAINCLUDES="" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Run the test.
|
2022-08-16 00:53:29 +02:00
|
|
|
if ! ${CC:-gcc} $CPPFLAGS $CFLAGS -I $builddir -I $srcdir \
|
2019-08-19 20:22:56 +02:00
|
|
|
-I $builddir/src/include -I $srcdir/src/include \
|
|
|
|
-I $builddir/src/interfaces/libpq -I $srcdir/src/interfaces/libpq \
|
|
|
|
$EXTRAINCLUDES $EXTRAFLAGS -c $tmp/test.c -o $tmp/test.o
|
2022-08-16 00:53:29 +02:00
|
|
|
then
|
|
|
|
exit_status=1
|
|
|
|
fi
|
2019-08-19 20:22:56 +02:00
|
|
|
done
|
2022-08-16 00:53:29 +02:00
|
|
|
|
|
|
|
exit $exit_status
|